X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=glws_wgl.cpp;h=59f47866331288521bc0de700f178ed3947e4238;hb=a5b476eb4eed9b06e22f4a80b16251aea243207d;hp=7e5807146375646500b723ce8f4ac819a2057519;hpb=ce6bcdd4395c9efec37a26f6c1caf8944d75f6d0;p=apitrace diff --git a/glws_wgl.cpp b/glws_wgl.cpp index 7e58071..59f4786 100644 --- a/glws_wgl.cpp +++ b/glws_wgl.cpp @@ -23,13 +23,34 @@ * **************************************************************************/ -#include "glimports.hpp" +#include "glproc.hpp" #include "glws.hpp" namespace glws { +static LRESULT CALLBACK +WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + MINMAXINFO *pMMI; + switch (uMsg) { + case WM_GETMINMAXINFO: + // Allow to create a window bigger than the desktop + pMMI = (MINMAXINFO *)lParam; + pMMI->ptMaxSize.x = 60000; + pMMI->ptMaxSize.y = 60000; + pMMI->ptMaxTrackSize.x = 60000; + pMMI->ptMaxTrackSize.y = 60000; + break; + default: + break; + } + + return DefWindowProc(hWnd, uMsg, wParam, lParam); +} + + class WglDrawable : public Drawable { public: @@ -40,8 +61,8 @@ public: PIXELFORMATDESCRIPTOR pfd; int iPixelFormat; - WglDrawable(const Visual *vis) : - Drawable(vis) + WglDrawable(const Visual *vis, int width, int height) : + Drawable(vis, width, height) { static bool first = TRUE; RECT rect; @@ -52,7 +73,7 @@ public: wc.hbrBackground = (HBRUSH) (COLOR_BTNFACE + 1); wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hIcon = LoadIcon(NULL, IDI_APPLICATION); - wc.lpfnWndProc = DefWindowProc; + wc.lpfnWndProc = WndProc; wc.lpszClassName = "glretrace"; wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW; RegisterClass(&wc); @@ -60,9 +81,9 @@ public: } dwExStyle = 0; - dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_OVERLAPPEDWINDOW; + dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW; - int x = 0, y = 0, width = 256, height = 256; + int x = 0, y = 0; rect.left = x; rect.top = y; @@ -75,8 +96,8 @@ public: "glretrace", /* wc.lpszClassName */ NULL, dwStyle, - CW_USEDEFAULT, /* x */ - CW_USEDEFAULT, /* y */ + 0, /* x */ + 0, /* y */ rect.right - rect.left, /* width */ rect.bottom - rect.top, /* height */ NULL, @@ -86,10 +107,13 @@ public: hDC = GetDC(hWnd); memset(&pfd, 0, sizeof pfd); - pfd.cColorBits = 3; + pfd.cColorBits = 4; pfd.cRedBits = 1; pfd.cGreenBits = 1; pfd.cBlueBits = 1; + pfd.cAlphaBits = 1; + pfd.cDepthBits = 1; + pfd.cStencilBits = 1; pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL; pfd.iLayerType = PFD_MAIN_PLANE; pfd.iPixelType = PFD_TYPE_RGBA; @@ -111,18 +135,41 @@ public: } void - resize(unsigned w, unsigned h) { - Drawable::resize(w, h); + resize(int w, int h) { + if (w == width && h == height) { + return; + } + RECT rClient, rWindow; GetClientRect(hWnd, &rClient); GetWindowRect(hWnd, &rWindow); w += (rWindow.right - rWindow.left) - rClient.right; h += (rWindow.bottom - rWindow.top) - rClient.bottom; - MoveWindow(hWnd, rWindow.left, rWindow.top, w, h, TRUE); + SetWindowPos(hWnd, NULL, rWindow.left, rWindow.top, w, h, SWP_NOMOVE); + + Drawable::resize(w, h); + } + + void show(void) { + if (visible) { + return; + } + + ShowWindow(hWnd, SW_SHOW); + + Drawable::show(); } void swapBuffers(void) { SwapBuffers(hDC); + + // Drain message queue to prevent window from being considered + // non-responsive + MSG msg; + while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } } }; @@ -131,10 +178,12 @@ class WglContext : public Context { public: HGLRC hglrc; - - WglContext(const Visual *vis) : - Context(vis), - hglrc(0) + WglContext *shareContext; + + WglContext(const Visual *vis, Profile prof, WglContext *share) : + Context(vis, prof), + hglrc(0), + shareContext(share) {} ~WglContext() { @@ -145,61 +194,76 @@ public: }; -class WglWindowSystem : public WindowSystem -{ -public: - Visual * - createVisual(bool doubleBuffer) { - Visual *visual = new Visual(); +void +init(void) { + /* + * OpenGL library must be loaded by the time we call GDI. + */ + __libGlHandle = LoadLibraryA("OPENGL32"); +} - visual->doubleBuffer = doubleBuffer; +void +cleanup(void) { +} - return visual; - } - - Drawable * - createDrawable(const Visual *visual) - { - return new WglDrawable(visual); +Visual * +createVisual(bool doubleBuffer, Profile profile) { + if (profile != PROFILE_COMPAT) { + return NULL; } - Context * - createContext(const Visual *visual) - { - return new WglContext(visual); + Visual *visual = new Visual(); + + visual->doubleBuffer = doubleBuffer; + + return visual; +} + +Drawable * +createDrawable(const Visual *visual, int width, int height) +{ + return new WglDrawable(visual, width, height); +} + +Context * +createContext(const Visual *visual, Context *shareContext, Profile profile) +{ + if (profile != PROFILE_COMPAT) { + return NULL; } - bool - makeCurrent(Drawable *drawable, Context *context) - { - if (!drawable || !context) { - return wglMakeCurrent(NULL, NULL); - } else { - WglDrawable *wglDrawable = dynamic_cast(drawable); - WglContext *wglContext = dynamic_cast(context); + return new WglContext(visual, profile, static_cast(shareContext)); +} +bool +makeCurrent(Drawable *drawable, Context *context) +{ + if (!drawable || !context) { + return wglMakeCurrent(NULL, NULL); + } else { + WglDrawable *wglDrawable = static_cast(drawable); + WglContext *wglContext = static_cast(context); + + if (!wglContext->hglrc) { + wglContext->hglrc = wglCreateContext(wglDrawable->hDC); if (!wglContext->hglrc) { - wglContext->hglrc = wglCreateContext(wglDrawable->hDC); - if (!wglContext->hglrc) { - return false; - } + return false; + } + if (wglContext->shareContext) { + wglShareLists(wglContext->shareContext->hglrc, + wglContext->hglrc); } - - return wglMakeCurrent(wglDrawable->hDC, wglContext->hglrc); } - } - bool - processEvents(void) { - // TODO - return true; + return wglMakeCurrent(wglDrawable->hDC, wglContext->hglrc); } -}; - +} -WindowSystem *createNativeWindowSystem(void) { - return new WglWindowSystem(); +bool +processEvents(void) { + // TODO + return true; } -} /* namespace glretrace */ +} /* namespace glws */