From 38deb97478ace8a3fa19fe55f0a987a2ad6599d0 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 29 Jul 2011 18:06:36 +0100 Subject: [PATCH] cogl-winsys-wgl: Add a fallback for failed wglGetProcAddress The documentation for wglGetProcAddress implies that it should only be used for extension functions. The rest of Cogl assumes that it can dynamically resolve all GL symbols so it would crash if this happens. This patch makes it fallback to trying to resolve the symbol using GModule to open the opengl32 library if wglGetProcAddress fails. https://bugzilla.gnome.org/show_bug.cgi?id=655510 Reviewed-by: Robert Bragg --- cogl/winsys/cogl-winsys-wgl.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/cogl/winsys/cogl-winsys-wgl.c b/cogl/winsys/cogl-winsys-wgl.c index def4d9239..f3bc8ba6a 100644 --- a/cogl/winsys/cogl-winsys-wgl.c +++ b/cogl/winsys/cogl-winsys-wgl.c @@ -45,6 +45,8 @@ typedef struct _CoglRendererWgl { + GModule *gl_module; + /* Function pointers for GLX specific extensions */ #define COGL_WINSYS_FEATURE_BEGIN(a, b, c, d, e, f) @@ -125,12 +127,32 @@ static CoglFuncPtr _cogl_winsys_renderer_get_proc_address (CoglRenderer *renderer, const char *name) { - return (CoglFuncPtr) wglGetProcAddress ((LPCSTR) name); + CoglRendererWgl *wgl_renderer = renderer->winsys; + void *proc = wglGetProcAddress ((LPCSTR) name); + + /* The documentation for wglGetProcAddress implies that it only + returns pointers to extension functions so if it fails we'll try + resolving the symbol directly from the the GL library */ + if (proc == NULL) + { + if (wgl_renderer->gl_module == NULL) + wgl_renderer->gl_module = g_module_open ("opengl32", 0); + + if (wgl_renderer->gl_module) + g_module_symbol (wgl_renderer->gl_module, name, &proc); + } + + return proc; } static void _cogl_winsys_renderer_disconnect (CoglRenderer *renderer) { + CoglRendererWgl *wgl_renderer = renderer->winsys; + + if (wgl_renderer->gl_module) + g_module_close (wgl_renderer->gl_module); + g_slice_free (CoglRendererWgl, renderer->winsys); }