简体   繁体   中英

Platform specific macros in OpenGL headers

I was parsing gl.h and I noticed a quite unusual (at least to me) way of declaring openGL functions. Here is an example:

GLAPI void APIENTRY glEvalCoord1d( GLdouble u );
GLAPI void APIENTRY glEvalCoord1f( GLfloat u );
GLAPI void APIENTRY glEvalCoord1dv( const GLdouble *u );

Obviously, those are regular functions with return type void, but my questions is about the effect of GLAPI and APIENTRY macros. Those two are platform specific, declared in the beginning of the header:

/* GLAPI, part 1 (use WINGDIAPI, if defined) */
#if defined(__WIN32__) && defined(WINGDIAPI)
#  define GLAPI WINGDIAPI
#endif

/* GLAPI, part 2 */
#if !defined(GLAPI)
#  if defined(_MSC_VER)                        /* Microsoft Visual C++ */
#    define GLAPI __declspec(dllimport)
#  elif defined(__LCC__) && defined(__WIN32__) /* LCC-Win32 */
#    define GLAPI __stdcall
#  else                                        /* Others (e.g. MinGW, Cygwin, non-win32) */
#    define GLAPI extern
#  endif
#endif

/* APIENTRY */
#if !defined(APIENTRY)
#  if defined(__WIN32__)
#    define APIENTRY __stdcall
#  else
#    define APIENTRY
#  endif
#endif

I want to make a code parser that goes through headers and lists their content, so my question is how to deal with those macros and what to make out of them.

I am fairly new to C++ so those irregular function declarations are not familiar to me. I found out that __declspec(dllimport) and __stdcall are basically MS stuff to deal with win32 api and DLLs, I know what "extern" means, but for APIENTRY the win32 version is __stdcall which I get, but the "else" doesn't seem to define APIENTRY to anything, does that mean it simply substitutes APIENTRY with nothing?

What is the difference between the two:

void glEvalCoord1d( GLdouble u );
__stdcall void __stdcall glEvalCoord1d( GLdouble u );

您可以将预处理器用于此任务,如下所示:

gcc --nostdinc -E -DGLAPI="" -DAPIENTRY="" yourHeader.h > cleanedFile.h

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM