问题
This is based on the debug callback example from https://www.khronos.org/opengl/wiki/Debug_Output and somewhat on https://learnopengl.com/In-Practice/Debugging.
Setting up the callback:
void GLAPIENTRY
MessageCallback( GLenum source,
GLenum type,
GLuint id,
GLenum severity,
GLsizei length,
const GLchar* message,
const void* userParam )
{
fprintf( stderr, "GL CALLBACK: %s type = 0x%x, severity = 0x%x, message = %s\n",
( type == GL_DEBUG_TYPE_ERROR ? "** GL ERROR **" : "" ),
type, severity, message );
}
And then, after window creation ect., registering it:
glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
glEnable ( GL_DEBUG_OUTPUT );
if(glDebugMessageCallback){
std::cout << "Register OpenGL debug callback " << std::endl;
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
GLuint unusedIds = 0;
//glDebugMessageCallback( MessageCallback, 0 ); also tried setting up the callback here
glDebugMessageControl(GL_DONT_CARE,
GL_DONT_CARE,
GL_DONT_CARE,
0,
&unusedIds,
GL_TRUE);
glDebugMessageCallback( MessageCallback, 0 );
}
else
std::cout << "glDebugMessageCallback not available" << std::endl;
After that I produce an error message by calling
glClear(GL_DEPTH);
which works as expected. It's source is GL_DEBUG_SOURCE_API.
However, if i set
glDebugMessageControl(GL_DEBUG_SOURCE_APPLICATION,
GL_DONT_CARE,
GL_DONT_CARE,
0,
&unusedIds,
GL_TRUE);
the callback is still emitted, even though, as I understand, it should not be because of the GL_DEBUG_SOURCE_APPLICATION filter.
This also occurs for other combinations of filters, so that I assume that the call to glDebugMessageControl has no effect in my implementation.
Has anyone an idea what I'm missing here? Thank you!
回答1:
By glDebugMessageControl you can explicitly specify messages, whose state (enabled/disabled) you want to change. But there is no possibility to change the state of all the other messages, which are not specified in the filter, which is passed to glDebugMessageControl.
If you want to disable reporting of specific debug messages, then the last parameter of glDebugMessageControl (enabled) has to be GL_FALSE.
Furthermore, glClear(GL_DEPTH) would cause a GL_INVALID_VALUE error and the source type is GL_DEBUG_SOURCE_API, instead of GL_DEBUG_SOURCE_APPLICATION:
glDebugMessageControl(
GL_DEBUG_SOURCE_API,
GL_DONT_CARE,
GL_DONT_CARE,
0, NULL,
GL_FALSE); // disable all messages with source `GL_DEBUG_SOURCE_APPLICATION`
If you want to disable all error messages, except the API error messages, then you have to disable all messages first and the enable explicitly the API error messages:
glDebugMessageControl(
GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_FALSE);
glDebugMessageControl(
GL_DEBUG_SOURCE_API, GL_DEBUG_TYPE_ERROR, GL_DONT_CARE, 0, NULL, GL_TRUE);
See also Debug Output - Message Components
来源:https://stackoverflow.com/questions/51962968/how-to-use-gldebugmessagecontrol