[cogl/msvc-support] cogl-winsys-wgl: Add a fallback for failed wglGetProcAddress



commit a8618c21e069f7b81f4b09e1c17aa05fe7268e96
Author: Neil Roberts <neil linux intel com>
Date:   Fri Jul 29 18:06:36 2011 +0100

    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
    
    Signed-off-by: Chun-wei Fan <fanchunwei src gnome org>

 cogl/winsys/cogl-winsys-wgl.c |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)
---
diff --git a/cogl/winsys/cogl-winsys-wgl.c b/cogl/winsys/cogl-winsys-wgl.c
index def4d92..f3bc8ba 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);
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]