summaryrefslogtreecommitdiffstats
path: root/src/gallium/state_trackers/wgl
diff options
context:
space:
mode:
authorJose Fonseca <[email protected]>2015-04-14 14:25:21 +0100
committerJose Fonseca <[email protected]>2015-04-15 09:58:38 +0100
commit1aa50339d816c5d5ad3107673c315569ce9b21d3 (patch)
treebf37c492180c43cdfa11fce617569e8efc07a864 /src/gallium/state_trackers/wgl
parent6635fb6cae702b195e9912747b5a11c41970ab9e (diff)
st/wgl: Couple of fixes to opengl32.dll's wglCreateContext/wglDeleteContext dispatch.
- Use GetModuleHandle instead of LoadLibrary to avoid incrementing the opengl32.dll reference count (otherwise the opengl32.dll will linger in memory forever.) - Ensure we use our fake wglCreateContext/wglDeleteContext when using Mesa as a drop-in replacement for opengl32.dll Untested. Just noticed by accident. Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium/state_trackers/wgl')
-rw-r--r--src/gallium/state_trackers/wgl/stw_ext_context.c18
-rw-r--r--src/gallium/state_trackers/wgl/stw_ext_context.h36
-rw-r--r--src/gallium/state_trackers/wgl/stw_wgl.c21
3 files changed, 66 insertions, 9 deletions
diff --git a/src/gallium/state_trackers/wgl/stw_ext_context.c b/src/gallium/state_trackers/wgl/stw_ext_context.c
index 8a96cac4385..6af20627398 100644
--- a/src/gallium/state_trackers/wgl/stw_ext_context.c
+++ b/src/gallium/state_trackers/wgl/stw_ext_context.c
@@ -33,6 +33,11 @@
#include "stw_icd.h"
#include "stw_context.h"
#include "stw_device.h"
+#include "stw_ext_context.h"
+
+
+wglCreateContext_t wglCreateContext_func = 0;
+wglDeleteContext_t wglDeleteContext_func = 0;
/**
@@ -50,12 +55,7 @@
HGLRC WINAPI
wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const int *attribList)
{
- typedef HGLRC (WINAPI *wglCreateContext_t)(HDC hdc);
- typedef BOOL (WINAPI *wglDeleteContext_t)(HGLRC hglrc);
HGLRC context;
- static HMODULE opengl_lib = 0;
- static wglCreateContext_t wglCreateContext_func = 0;
- static wglDeleteContext_t wglDeleteContext_func = 0;
int majorVersion = 1, minorVersion = 0, layerPlane = 0;
int contextFlags = 0x0;
@@ -135,11 +135,11 @@ wglCreateContextAttribsARB(HDC hDC, HGLRC hShareContext, const int *attribList)
}
/* Get pointer to OPENGL32.DLL's wglCreate/DeleteContext() functions */
- if (opengl_lib == 0) {
- /* Open the OPENGL32.DLL library */
- opengl_lib = LoadLibraryA("OPENGL32.DLL");
+ if (!wglCreateContext_func || !wglDeleteContext_func) {
+ /* Get the OPENGL32.DLL library */
+ HMODULE opengl_lib = GetModuleHandleA("opengl32.dll");
if (!opengl_lib) {
- _debug_printf("wgl: LoadLibrary(OPENGL32.DLL) failed\n");
+ _debug_printf("wgl: GetModuleHandleA(\"opengl32.dll\") failed\n");
return 0;
}
diff --git a/src/gallium/state_trackers/wgl/stw_ext_context.h b/src/gallium/state_trackers/wgl/stw_ext_context.h
new file mode 100644
index 00000000000..9cb12b498bd
--- /dev/null
+++ b/src/gallium/state_trackers/wgl/stw_ext_context.h
@@ -0,0 +1,36 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2011 Morgan Armand <[email protected]>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#pragma once
+
+#include <windows.h>
+#include <GL/gl.h>
+
+
+typedef HGLRC (WINAPI *wglCreateContext_t)(HDC hdc);
+typedef BOOL (WINAPI *wglDeleteContext_t)(HGLRC hglrc);
+
+extern wglCreateContext_t wglCreateContext_func;
+extern wglDeleteContext_t wglDeleteContext_func;
+
diff --git a/src/gallium/state_trackers/wgl/stw_wgl.c b/src/gallium/state_trackers/wgl/stw_wgl.c
index 0650fbbd02d..5146e6a5b79 100644
--- a/src/gallium/state_trackers/wgl/stw_wgl.c
+++ b/src/gallium/state_trackers/wgl/stw_wgl.c
@@ -45,8 +45,12 @@
#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;
+}