#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;
/**
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;
}
/* 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;
}
--- /dev/null
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright (C) 2011 Morgan Armand <morgan.devel@gmail.com>
+ *
+ * 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;
+
#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,
wglCreateContext(
HDC hdc )
{
+ overrideOpenGL32EntryPoints();
return (HGLRC) DrvCreateContext(hdc);
}
HDC hdc,
int iLayerPlane )
{
+ overrideOpenGL32EntryPoints();
return (HGLRC) DrvCreateLayerContext( hdc, iLayerPlane );
}
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;
+}