glew icon indicating copy to clipboard operation
glew copied to clipboard

Support non global scope for function pointers

Open ensisoft opened this issue 9 years ago • 0 comments

What this issue means is that instead of having all the function pointers always in the global scope the function pointers were declared in a separate header file that one could easily include inside some other scope. For an example what I mean please see the two examples below.

// include all the required denitions that the entry pointer declarations need.

include <glew/glew.h>

// Example 1: // put the pointers inside namespace acme. namespace acme { #include <glew/glew_api.h> }

// Example 2: class MyOpenGLDevice { public: ... // put the function pointers in the scope of MyOpenGLDevice #include <glew/glew_api.h>

private: };

The second example is very explicit and also helps for cases when you might want to have multiple contexts. You can't readily do that with one set of global function pointers. (Just a reminder, for example in WGL the pointers are specific to PixelFormats, so you can't share function pointers betweeen contexts if they have different configs)

The ugly part is that I think you'd need to put the whole resolution inside a macro in order to make it reusable. Something like:

MyOpenGLDevice::MyOpenGLDevice() { // create context etc. // ...

// resolve our fuction pointers GLEW_INIT_HERE(); }

Supporting existing C based API with global function pointers would be straightforward.

ensisoft avatar Oct 03 '16 14:10 ensisoft