OpenGL标头中特定于平台的宏 [英] Platform specific macros in OpenGL headers

查看:83
本文介绍了OpenGL标头中特定于平台的宏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在解析gl.h时,我注意到了一种非常不寻常的(至少对我而言)声明openGL函数的方式.这是一个示例:

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 );

很显然,那些是返回类型为void的常规函数​​,但是我的问题是关于GLAPI和APIENTRY宏的作用.这两个是特定于平台的,在标头的开头声明:

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.

我对C ++还是很陌生,所以那些不规则的函数声明对我来说并不熟悉.我发现__declspec(dllimport)和__stdcall基本上是用于处理win32 api和DLL的MS东西,我知道"extern"是什么意思,但是对于APIENTRY,win32版本是我得到的__stdcall,但是"else"却没有似乎将APIENTRY定义为任何东西,这是否意味着它只是用什么都代替了APIENTRY?

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?

两者之间有什么区别?

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

推荐答案

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

You can use the preprocessor for this task, with something like this:

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

这篇关于OpenGL标头中特定于平台的宏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆