仅在MSVC上无法匹配GLDEBUGPROC的功能(使用相同的glew版本2.1.0,在具有gcc/clang的linux上就可以了) [英] Function unable to match GLDEBUGPROC, only on MSVC (uses same glew version 2.1.0, on linux with gcc/clang it's fine)
问题描述
我定义了以下与glDebugCallback
一起使用的功能,该功能在Linux上的GCC和Clang上可以正常使用.但是,在Windows上,以下代码不想注册为OpenGL的调试回调:
I have the following function I've defined that i use with glDebugCallback
, which works perfectly fine with GCC and Clang on Linux. However on Windows, the following code does not want to register as a debug callback for OpenGL:
inline void messageCallback(GLenum source, GLenum type, GLuint id,
GLenum severity, GLsizei length, const GLchar* message,
const void* userParam) {
// ...
}
然后我用
glDebugMessageCallback(messageCallback, nullptr);
在查找错误标题后,它显示:
After looking up what the glew headers have, it shows:
typedef void (GLAPIENTRY *GLDEBUGPROC)(GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const GLchar* message,
const void* userParam);
但是我收到一条错误消息
but I'm getting an error message that says
错误(有效)E0167类型的参数"void(*)(GLenum源,GLenum类型,GLutint id,GLenum严重性,GLsizei长度,const GLchar *消息,const void * userParam)"与类型的参数不兼容GLDEBUGPROC"
Error (active) E0167 argument of type "void (*)(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)" is incompatible with parameter of type "GLDEBUGPROC"
我一直试图弄清楚为什么只有MSVC才能失败...但是我很困惑,因为它看起来像逐字匹配.它在GCC/Clang上编译的事实也有点令人困惑,我不确定我缺少什么或为什么会发生这种情况.
I've been trying to figure out why it fails only with MSVC... but I'm quite stuck since it looks like it matches verbatim. The fact it compiles on GCC/Clang is also a bit confusing as well, I'm not sure what I'm missing or why this is happening.
请注意,inline
关键字不会影响结果,我在没有关键字的情况下尝试了该操作,并且存在相同的问题.我只是将其保留在此处,因为我想复制并粘贴确切的内容.我还通过diff检查器对此进行了检查,以查看我是否以任何方式错误地设置了参数,但是它们是相同的.
Note that the inline
keyword does not affect the result, I tried it without the keyword and the same problem is there. I just kept it there because I wanted to copy and paste the exact thing. I also put this through a diff checker to see if I did the parameters wrong in any way, but they are identical.
这是在Visual Studio 2017中,使用C ++ 17,glew 2.1.0,现代的Opengl等.我的OpenGL版本也是4.6.
This is within Visual Studio 2017, using C++17, glew 2.1.0, modern Opengl, etc. My OpenGL version is 4.6 as well.
推荐答案
您可能需要包含GLAPIENTRY
限定符:
You probably need to include the GLAPIENTRY
qualifier:
void GLAPIENTRY messageCallback(...)
这指定了一个调用约定,该约定告诉编译器修改传递函数参数的方式.在某些平台上,它没有什么区别,但我想它可能在Windows上也可以.
This specifies a calling convention that tells the compiler to modify the way the function's arguments are passed. On some platforms it makes no difference, but I would guess it probably does on Windows.
这篇关于仅在MSVC上无法匹配GLDEBUGPROC的功能(使用相同的glew版本2.1.0,在具有gcc/clang的linux上就可以了)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!