Support custom callback to resolve OpenGL entry points

There's a need to be able to define a custom callback to resolve
the OpenGL entry points. For example when integrating with 3rd party
toolkits such as Qt. Glew doesn't know the underlying implementation
and the entry point resolution really needs to happen through the
context object created by Qt.

Implementation for issue #106
This commit is contained in:
Sami Väisänen 2016-10-01 21:15:33 +03:00
parent cdc3aeacde
commit 4d6e0387b3
2 changed files with 22 additions and 1 deletions

View File

@ -122,7 +122,11 @@ void* NSGLGetProcAddress (const GLubyte *name)
/*
* Define glewGetProcAddress.
*/
#if defined(GLEW_REGAL)
#if defined(GLEW_CUSTOM_GET_PROC_ADDRESS)
glewResolveProcType glewResolveProc;
glewResolveDataType glewResolveData;
# define glewGetProcAddress(name) glewResolveProc((const char*)name, glewResolveData)
#elif defined(GLEW_REGAL)
# define glewGetProcAddress(name) regalGetProcAddress((const GLchar *)name)
#elif defined(GLEW_OSMESA)
# define glewGetProcAddress(name) OSMesaGetProcAddress((const char *)name)

View File

@ -187,6 +187,23 @@ typedef _W64 int ptrdiff_t;
#define GLEW_VAR_EXPORT GLEWAPI
#define GLEW_FUN_EXPORT GLEWAPI
/*
* If you're integrating glew with something like Qt you really want to use
* the context created by Qt to resolve the function pointers.
* In this case define GLEW_CUSTOM_GET_PROC_ADDRESS and set the pointer below
* to your callback function.
*/
#ifdef GLEW_CUSTOM_GET_PROC_ADDRESS
typedef void* glewResolveDataType;
typedef void* (*glewResolveProcType)(const char*, glewResolveDataType user);
/* This is your callback */
extern glewResolveProcType glewResolveProc;
/* This is your (optional) callback data */
extern glewResolveDataType glewResolveData;
#endif
#ifdef __cplusplus
extern "C" {
#endif