gpt4 book ai didi

c++ - 用函数替换宏

转载 作者:太空宇宙 更新时间:2023-11-04 15:30:31 26 4
gpt4 key购买 nike

我有一段宏用来检查与 opengl 相关的错误

#if (GL_ERROR_CHECK == On)
#define GL_CHECK(x) \
x; \
{ \
GLenum glError = glGetError(); \
if(glError != GL_NO_ERROR) \
{ \
std::cout << "GL Error: " << glError << " at " << __FILE__ << ", " << __LINE__ << std::endl; \
} \
}
#else
#define GL_CHECK(x) x;
#endif

并这样使用它

GL_CHECK(glGenFramebuffers(1, (GLuint*)&m_u32FboID));
GL_CHECK(glBindFramebuffer(GL_FRAMEBUFFER, m_u32FboID));

我想知道是否有任何方法可以用适当的 c++ 函数替换此宏?

最佳答案

如果您使用的是 OpenGL 4.3 及更高版本,则可以改用调试回调,这样您就不必将每个 GL 函数都包装在宏中:Check it out here

启用一切:

glDebugMessageCallback(some_callback_function, nullptr);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, nullptr, true);

例如,这个函数:

void gl_debug_callback(GLenum source, GLenum type, GLuint id, GLenum severity,
GLsizei length, const GLchar* message, const void* userParam)
{
std::cerr << "GL Debug Message: " << message << '\n';
}

请注意,这有时会输出非错误的消息,因此您可以考虑打开严重性,或者对使用 ...MessageControl 函数启用的内容进行更严格的限制。

关于c++ - 用函数替换宏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54685076/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com