From 512160a1c8ecfd55b44b5071026d3f261feeca4d Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Thu, 20 May 2021 22:52:56 +1000 Subject: [PATCH] gl/context/wgl: implement a better get_proc_address() Look in opengl32.dll first, then wglGetProcAddress(), and only then possibly from any linked in libraries. Part-of: --- gst-libs/gst/gl/wgl/gstglcontext_wgl.c | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/gst-libs/gst/gl/wgl/gstglcontext_wgl.c b/gst-libs/gst/gl/wgl/gstglcontext_wgl.c index d75dc32..b24f46c 100644 --- a/gst-libs/gst/gl/wgl/gstglcontext_wgl.c +++ b/gst-libs/gst/gl/wgl/gstglcontext_wgl.c @@ -24,6 +24,7 @@ #endif #include +#include #include #include @@ -468,14 +469,43 @@ gst_gl_context_wgl_check_feature (GstGLContext * context, const gchar * feature) return gst_gl_check_extension (feature, context_wgl->priv->wgl_exts); } +static GOnce module_opengl_dll_gonce = G_ONCE_INIT; +static GModule *module_opengl_dll; + +static gpointer +load_opengl_dll_module (gpointer user_data) +{ +#ifdef GST_GL_LIBGL_MODULE_NAME + module_opengl_dll = + g_module_open (GST_GL_LIBGL_MODULE_NAME, G_MODULE_BIND_LAZY); +#else + if (g_strcmp0 (G_MODULE_SUFFIX, "dll") == 0) + module_opengl_dll = g_module_open ("opengl32.dll", G_MODULE_BIND_LAZY); + + /* This automatically handles the suffix and even .la files */ + if (!module_opengl_dll) + module_opengl_dll = g_module_open ("opengl32", G_MODULE_BIND_LAZY); +#endif + + return NULL; +} + gpointer gst_gl_context_wgl_get_proc_address (GstGLAPI gl_api, const gchar * name) { gpointer result; - if (!(result = gst_gl_context_default_get_proc_address (gl_api, name))) { - result = wglGetProcAddress ((LPCSTR) name); + if (gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3)) { + g_once (&module_opengl_dll_gonce, load_opengl_dll_module, NULL); + if (module_opengl_dll) + g_module_symbol (module_opengl_dll, name, &result); + + if (!result) { + result = wglGetProcAddress ((LPCSTR) name); + } } + if (!result) + result = gst_gl_context_default_get_proc_address (gl_api, name); return result; } -- 2.7.4