X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=retrace%2Fglws_wgl.cpp;h=de6c7d6b546161fe4c1968cb1f3305632cb1dee9;hb=c8695f74ce1ee6a93dee4b3f7da5a70a64706c82;hp=887a528db38dc21cbb833efb6236036b24c8bbee;hpb=632a78d5c90941c896fa3c7156131f27c5a58b24;p=apitrace diff --git a/retrace/glws_wgl.cpp b/retrace/glws_wgl.cpp index 887a528..de6c7d6 100644 --- a/retrace/glws_wgl.cpp +++ b/retrace/glws_wgl.cpp @@ -64,6 +64,13 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { MINMAXINFO *pMMI; switch (uMsg) { + case WM_KEYDOWN: + switch (wParam) { + case VK_ESCAPE: + PostMessage(hWnd, WM_CLOSE, 0, 0); + break; + } + break; case WM_GETMINMAXINFO: // Allow to create a window bigger than the desktop pMMI = (MINMAXINFO *)lParam; @@ -72,6 +79,9 @@ WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) pMMI->ptMaxTrackSize.x = 60000; pMMI->ptMaxTrackSize.y = 60000; break; + case WM_CLOSE: + exit(0); + break; default: break; } @@ -90,8 +100,8 @@ public: PIXELFORMATDESCRIPTOR pfd; int iPixelFormat; - WglDrawable(const Visual *vis, int width, int height) : - Drawable(vis, width, height) + WglDrawable(const Visual *vis, int width, int height, bool pbuffer) : + Drawable(vis, width, height, pbuffer) { static bool first = TRUE; RECT rect; @@ -233,6 +243,34 @@ public: wglDeleteContext(hglrc); } } + + bool + create(WglDrawable *wglDrawable) { + if (!hglrc) { + hglrc = wglCreateContext(wglDrawable->hDC); + if (!hglrc) { + std::cerr << "error: wglCreateContext failed\n"; + exit(1); + return false; + } + if (shareContext) { + if (shareContext->create(wglDrawable)) { + BOOL bRet; + bRet = wglShareLists(shareContext->hglrc, + hglrc); + if (!bRet) { + std::cerr + << "warning: wglShareLists failed: " + << std::hex << GetLastError() << std::dec + << "\n"; + } + } + } + } + + return true; + } + }; @@ -265,7 +303,8 @@ cleanup(void) { Visual * createVisual(bool doubleBuffer, Profile profile) { - if (profile != PROFILE_COMPAT) { + if (profile != PROFILE_COMPAT && + profile != PROFILE_CORE) { return NULL; } @@ -277,18 +316,23 @@ createVisual(bool doubleBuffer, Profile profile) { } Drawable * -createDrawable(const Visual *visual, int width, int height) +createDrawable(const Visual *visual, int width, int height, bool pbuffer) { - return new WglDrawable(visual, width, height); + return new WglDrawable(visual, width, height, pbuffer); } Context * -createContext(const Visual *visual, Context *shareContext, Profile profile) +createContext(const Visual *visual, Context *shareContext, Profile profile, bool debug) { - if (profile != PROFILE_COMPAT) { + if (profile != PROFILE_COMPAT && + profile != PROFILE_CORE) { return NULL; } + if (profile == PROFILE_CORE) { + std::cerr << "warning: ignoring OpenGL core profile request\n"; + } + return new WglContext(visual, profile, static_cast(shareContext)); } @@ -301,22 +345,7 @@ makeCurrent(Drawable *drawable, Context *context) WglDrawable *wglDrawable = static_cast(drawable); WglContext *wglContext = static_cast(context); - if (!wglContext->hglrc) { - wglContext->hglrc = wglCreateContext(wglDrawable->hDC); - if (!wglContext->hglrc) { - std::cerr << "error: wglCreateContext failed\n"; - exit(1); - return false; - } - if (wglContext->shareContext) { - BOOL bRet; - bRet = wglShareLists(wglContext->shareContext->hglrc, - wglContext->hglrc); - if (!bRet) { - std::cerr << "warning: wglShareLists failed\n"; - } - } - } + wglContext->create(wglDrawable); return wglMakeCurrent(wglDrawable->hDC, wglContext->hglrc); } @@ -324,7 +353,17 @@ makeCurrent(Drawable *drawable, Context *context) bool processEvents(void) { - // TODO + MSG uMsg; + while (PeekMessage(&uMsg, NULL, 0, 0, PM_REMOVE)) { + if (uMsg.message == WM_QUIT) { + return false; + } + + if (!TranslateAccelerator(uMsg.hwnd, NULL, &uMsg)) { + TranslateMessage(&uMsg); + DispatchMessage(&uMsg); + } + } return true; }