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 <robert@linux.intel.com>
This commit is contained in:
Neil Roberts 2011-07-29 18:06:36 +01:00
parent 93e69387cc
commit 38deb97478

View File

@ -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);
}