在OpenGL中,你可以浪费很多时间(特别是):
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // OK
glPolygonMode(GL_FRONT_AND_BACK, GL_LINES); // WRONG but compiles
glPolygonMode(GL_LINE, GL_FRONT_AND_BACK); // WRONG but compiles
查找此类错误可能需要一些时间。
我想要的是什么:
我尝试了什么:
MY_
我得到了什么:
#ifdef _DEBUG
#define TRFUNC(func) MY_##func
#define TRPARAM(type, name) MY_##type::MY_##name
enum MY_FACE{MY_GL_FRONT_AND_BACK};
enum MY_MODE{MY_GL_POINT, MY_GL_LINE, MY_GL_FILL};
static GLenum tr(MY_FACE face)
{
if (face == MY_FACE::MY_GL_FRONT_AND_BACK)
return GL_FRONT_AND_BACK;
}
static GLenum tr(MY_MODE mode)
{
if (mode == MY_MODE::MY_GL_FILL)
return GL_FILL;
if (mode == MY_MODE::MY_GL_LINE)
return GL_LINE;
if (mode == MY_MODE::MY_GL_POINT)
return GL_POINT;
}
// Prefix name because functions names are #defined so will be replaced by preprocessor
static void MY_glPolygonMode(MY_FACE face, MY_MODE mode)
{
glPolygonMode(tr(face), tr(mode));
}
#else
#define TRFUNC(func) func
#define TRPARAM(type, name) name
#endif
电话就像:
TRFUNC(glPolygonMode)(TRPARAM(FACE, GL_FRONT_AND_BACK), TRPARAM(MODE, GL_LINE)); // OK
TRFUNC(glPolygonMode)(TRPARAM(FACE, GL_FRONT_AND_BACK), TRPARAM(MODE, GL_LINES)); // error C2838: 'MY_GL_LINES' : illegal qualified name
TRFUNC(glPolygonMode)(TRPARAM(MODE, GL_LINE), TRPARAM(FACE, GL_FRONT_AND_BACK)); // error C2664: 'void MY_glPolygonMode(MY_FACE,MY_MODE)' : cannot convert argument 1 from 'MY_MODE' to 'MY_FACE'
这只是“原型解决方案”,用于测试它是否有效以及可能的情况。
我想要的是什么:
我不想要的东西: