Menu

#227 Using *APIENTRY in user code

1.11.0
closed
None
1
2014-08-26
2013-12-05
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

  • Nigel Stewart

    Nigel Stewart - 2013-12-06

    Agreed. This is a good proposal.

     
  • Nigel Stewart

    Nigel Stewart - 2013-12-09
    • assigned_to: Nigel Stewart
    • Group: v1.0_(example) --> 1.10.1
     
  • Nigel Stewart

    Nigel Stewart - 2014-02-20

    Fixed in GLEW git master branch.

     
  • Nigel Stewart

    Nigel Stewart - 2014-02-20
    • status: open --> pending
     
  • Nigel Stewart

    Nigel Stewart - 2014-08-12
    • Group: 1.10.1 --> 1.11.0
     
  • Nigel Stewart

    Nigel Stewart - 2014-08-12
    • Status: pending --> closed