#227 Using *APIENTRY in user code

1.11.0
closed
Nigel Stewart
None
1
3 days ago
2013-12-05
Daniel Scharrer
No

It is sometimes necessary to use one of the *APIENTRY defines when defining functions in user code, for example with the callback for ARB_debug_output.

The Khronos headers make sure APIENTRY is defined after <GL/gl.h> or <GL/glext.h> by including <windows.h> if aplicable.

GLEW avoids including <windows.h> by manually defining APIENTRY (if not defined) and then cleaning it up at the end of the header.

This has the unfortunate effect that if <Gl/glew.h> is included without also including <windows.h>,

  • APIENTRY is undefined
  • GLAPIENTRY is defined but empty, even if __stdcall is needed
  • GLEWAPIENTRY is defined to APIENTRY, which is undefined

This means that user code that wishes to provide a GL callback needs to know about OS-specific OpenGL implementation details in order to either conditionally include <windows.h> or manually define their own APIENTRY variant.

This could easily be avoided by:

  1. If APIENTRY is already defined, #define GLEWAPIENTRY APIENTRY
  2. Otherwise manually set up GLEWAPIENTRY like APIENTRY is defined now
  3. If APIENTRY is not defined, #define APIENTRY GLEWAPIENTRY
  4. At then end, if APIENTRY was not originally defined, #undef APIENTRY, but leave GLEWAPIENTRY

(Replace GLEWAPIENTRY with GLAPIENTRY or another name if you want to allow seperate ABIs for gl and glew functions)

This would ensure that
a) GLEWAPIENTRY is always defined after <GL/glew.h>
b) GLEWAPIENTRY always matches the calling convention used in the prototypes and typedefs provided by <GL/glew.h>

Discussion


Anonymous


Cancel   Add attachments