In my app I’m using 4 rendering contexts (standard WinAPI OpenGl windows) - 1 for each thread. So far I’ve been successfully using GLee to transparently handle GL extensions. The app seems to work correctly.
However, when I started debugging with gDEBugger I got several errors like that:
Detected error: The debugged process asked for an extension function pointer (glGenBuffersARB) from one render context, but called this function pointer in another render context (context #4)
Perhaps I would even consider leaving it as is but unfortunately gDEBugger quits my app abnormally shortly afterwards.
I googled and it seems that GLEW developers are aware of this issue. They provide an option to enable extensions on multiple rendering contexts:
Starting with release 1.2.0, thread-safe support for multiple rendering contexts, possibly with different capabilities, is available. Since this is not required by most users, it is not added to the binary releases to maintain compatibility between different versions. To include multi-context support, you have to do the following:
- Compile and use GLEW with the GLEW_MX preprocessor token defined.
- For each rendering context, create a GLEWContext object that will be available as long as the rendering context exists.
- Define a macro or function called glewGetContext() that returns a pointer to the GLEWContext object associated with the rendering context from which OpenGL/WGL/GLX calls are issued. This dispatch mechanism is primitive, but generic.
- Make sure that you call glewInit() after creating the GLEWContext object in each rendering context. Note, that the GLEWContext pointer returned by glewGetContext() has to reside in global or thread-local memory.
The problem is that I get numerous issues while the steps above and GLEW support is nonexistent. I can’t define glewGetContext() because it’s already defined in GLEW sources. When declaring glewGetContext() the compiler cannot find WGL extensions, when declaring wglewGetContext() the compiler cannot find generic extensions, when declaring both functions I get redefinition error. Perhaps I haven’t tried everything but what’s the purpose of a library if to learn how to use it I would have to dig deep into its implementation sources?
So maybe someone has an easier solution than GLEW? Or perhaps a full working example of GLEW_MX?