X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=glws_wgl.cpp;h=59f47866331288521bc0de700f178ed3947e4238;hb=4fdd5632465440b4f584a74bd4c171aa225a16e5;hp=b1e274b5f9314f27e2394f1ea362b70f0a4d3cb9;hpb=7497c130f98f33f41437678835f4b2eb2abce750;p=apitrace diff --git a/glws_wgl.cpp b/glws_wgl.cpp index b1e274b..59f4786 100644 --- a/glws_wgl.cpp +++ b/glws_wgl.cpp @@ -23,7 +23,7 @@ * **************************************************************************/ -#include "glimports.hpp" +#include "glproc.hpp" #include "glws.hpp" @@ -81,7 +81,7 @@ public: } dwExStyle = 0; - dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_OVERLAPPEDWINDOW; + dwStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW; int x = 0, y = 0; @@ -107,10 +107,11 @@ 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; @@ -135,17 +136,40 @@ public: void resize(int w, int h) { - Drawable::resize(w, 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; 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); + } } }; @@ -154,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() { @@ -168,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, int width, int height) - { - return new WglDrawable(visual, width, height); +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 */