st/wgl: Couple of fixes to opengl32.dll's wglCreateContext/wglDeleteContext dispatch.
[mesa.git] / src / gallium / state_trackers / wgl / stw_wgl.c
index 0650fbbd02d5ceb0deb9e10ff8d0010c45c445fe..5146e6a5b79579f36066dea6c52a7cf75a6ed44e 100644 (file)
 #include "stw_context.h"
 #include "stw_pixelformat.h"
 #include "stw_wgl.h"
+#include "stw_ext_context.h"
 
 
+static void
+overrideOpenGL32EntryPoints(void);
+
 WINGDIAPI BOOL APIENTRY
 wglCopyContext(
    HGLRC hglrcSrc,
@@ -62,6 +66,7 @@ WINGDIAPI HGLRC APIENTRY
 wglCreateContext(
    HDC hdc )
 {
+   overrideOpenGL32EntryPoints();
    return (HGLRC) DrvCreateContext(hdc);
 }
 
@@ -70,6 +75,7 @@ wglCreateLayerContext(
    HDC hdc,
    int iLayerPlane )
 {
+   overrideOpenGL32EntryPoints();
    return (HGLRC) DrvCreateLayerContext( hdc, iLayerPlane );
 }
 
@@ -334,3 +340,18 @@ wglRealizeLayerPalette(
 
    return FALSE;
 }
+
+
+/* When this library is used as a opengl32.dll drop-in replacement, ensure we
+ * use the wglCreate/Destroy entrypoints above, and not the true opengl32.dll,
+ * which could happen if this library's name is not opengl32.dll exactly.
+ *
+ * For example, Qt 5.4 bundles this as opengl32sw.dll:
+ * https://blog.qt.io/blog/2014/11/27/qt-weekly-21-dynamic-opengl-implementation-loading-in-qt-5-4/
+ */
+static void
+overrideOpenGL32EntryPoints(void)
+{
+   wglCreateContext_func = &wglCreateContext;
+   wglDeleteContext_func = &wglDeleteContext;
+}