0
votes

In the OpenGl-loader I've used (GLLoaderGenerator, GLEW) the header looks something like:

extern void (CODEGEN_FUNCPTR *_ptrc_glBindVertexBuffer)(GLuint, GLuint, GLintptr, GLsizei);
#define glBindVertexBuffer _ptrc_glBindVertexBuffer

... ok, GLEW hides this behind a couple of macros, but it results in pretty much the same.. So my question is - Is there a particular reason to define a function pointer with some name (_ptrc_XXX) and the #define the name I do want to use? Why not simply using:

extern void (CODEGEN_FUNCPTR *glBindVertexBuffer)(GLuint, GLuint, GLintptr, GLsizei);
1
Since the #define is just a rename, it would work in this case. - Bartek Banachewicz

1 Answers

1
votes

This is done to avoid namespace collisions. The names specified by OpenGL and the OpenGL extensions are reserved for the use by OpenGL implementations. Later versions of the various operating systems OpenGL standard ABI^1 may suddenly expose symbols in that namespace, which would break programs being linked with libraries, that also define these symbols.

An extension loader library is not an OpenGL implementation, but a 3rd party library. As such it is good practice not tread into the namespace reserved to OpenGL, i.e. symbols beginning with gl…. Instead such extension loaders load the symbols into their own namespace, like _ptrc_glew… and use some preprocessor macro trickery to transparently "rename" symbol references in code that uses that library.


1: ABI = specifications on what a certain API has to provide and how the interface is done on the lower level.