]> git.notmuchmail.org Git - apitrace/blobdiff - glws_wgl.cpp
Implement getTime for OS X
[apitrace] / glws_wgl.cpp
index adc99578e3b7aa9cd885c2de41458301856dec52..5fddb7932a5ef49cb3c4c7fab080d4270fe00deb 100644 (file)
@@ -23,7 +23,9 @@
  *
  **************************************************************************/
 
-#include "glimports.hpp"
+#include <iostream>
+
+#include "glproc.hpp"
 #include "glws.hpp"
 
 
@@ -136,25 +138,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) {
-            ShowWindow(hWnd, SW_SHOW);
-
-            Drawable::show();
+        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);
+        }
     }
 };
 
@@ -165,8 +182,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)
     {}
@@ -181,6 +198,21 @@ public:
 
 void
 init(void) {
+    /*
+     * OpenGL library must be loaded by the time we call GDI.
+     */
+
+    const char * libgl_filename = getenv("TRACE_LIBGL");
+
+    if (!libgl_filename) {
+        libgl_filename = "OPENGL32";
+    }
+
+    __libGlHandle = LoadLibraryA(libgl_filename);
+    if (!__libGlHandle) {
+        std::cerr << "error: unable to open " << libgl_filename << "\n";
+        exit(1);
+    }
 }
 
 void
@@ -188,7 +220,11 @@ cleanup(void) {
 }
 
 Visual *
-createVisual(bool doubleBuffer) {
+createVisual(bool doubleBuffer, Profile profile) {
+    if (profile != PROFILE_COMPAT) {
+        return NULL;
+    }
+
     Visual *visual = new Visual();
 
     visual->doubleBuffer = doubleBuffer;
@@ -203,9 +239,13 @@ createDrawable(const Visual *visual, int width, int height)
 }
 
 Context *
-createContext(const Visual *visual, Context *shareContext)
+createContext(const Visual *visual, Context *shareContext, Profile profile)
 {
-    return new WglContext(visual, dynamic_cast<WglContext *>(shareContext));
+    if (profile != PROFILE_COMPAT) {
+        return NULL;
+    }
+
+    return new WglContext(visual, profile, static_cast<WglContext *>(shareContext));
 }
 
 bool
@@ -214,8 +254,8 @@ makeCurrent(Drawable *drawable, Context *context)
     if (!drawable || !context) {
         return wglMakeCurrent(NULL, NULL);
     } else {
-        WglDrawable *wglDrawable = dynamic_cast<WglDrawable *>(drawable);
-        WglContext *wglContext = dynamic_cast<WglContext *>(context);
+        WglDrawable *wglDrawable = static_cast<WglDrawable *>(drawable);
+        WglContext *wglContext = static_cast<WglContext *>(context);
 
         if (!wglContext->hglrc) {
             wglContext->hglrc = wglCreateContext(wglDrawable->hDC);