X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=glws_wgl.cpp;h=63ce5fea1444748ef2f6c3956d1a732cb3fdef6d;hb=dfa23ba3320555bb32ee964e20f83d498132bcb7;hp=9e8f1e036432a81298b135004c835e790a1e773f;hpb=d3a6f1508e3ab0f8ce16f29f55b6d4019372ef98;p=apitrace diff --git a/glws_wgl.cpp b/glws_wgl.cpp index 9e8f1e0..63ce5fe 100644 --- a/glws_wgl.cpp +++ b/glws_wgl.cpp @@ -23,7 +23,7 @@ * **************************************************************************/ -#include "glimports.hpp" +#include "glproc.hpp" #include "glws.hpp" @@ -136,21 +136,28 @@ 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) { - ShowWindow(hWnd, SW_SHOW); - - Drawable::show(); + if (visible) { + return; } + + ShowWindow(hWnd, SW_SHOW); + + Drawable::show(); } void swapBuffers(void) { @@ -165,8 +172,8 @@ public: HGLRC hglrc; WglContext *shareContext; - WglContext(const Visual *vis, WglContext *share) : - Context(vis), + WglContext(const Visual *vis, Profile prof, WglContext *share) : + Context(vis, prof), hglrc(0), shareContext(share) {} @@ -179,65 +186,72 @@ 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) { + Visual *visual = new Visual(); - Context * - createContext(const Visual *visual, Context *shareContext) - { - return new WglContext(visual, dynamic_cast(shareContext)); + 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; - } - if (wglContext->shareContext) { - wglShareLists(wglContext->shareContext->hglrc, - wglContext->hglrc); - } + 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 */