Keywords:debug、opengl、调试、message

4.3之前的版本,如果要打印debug信息,通常是调用glGetError()函数,从4.3开始,提供了注册回调函数来获取debug message。

示例:

1.Create a callback function to receive the debug messages. The function must conform to a specific prototype described in the OpenGL documentation. For this example, we’ll use the following one:

void debugCallback(GLenum source, GLenum type, GLuint id,GLenum severity, GLsizei length,const GLchar * message, void * param)
{
    // Convert GLenum parameters to strings
    printf("%s:%s[%s](%d): %s\n", sourceStr, typeStr, severityStr, id, message);
}

2.Register our callback with OpenGL using glDebugMessageCallback:

glDebugMessageCallback( debugCallback, NULL );

3.Enable all messages, all sources, all levels, and all IDs:

glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);

开启或禁用debug消息:

opengl默认是开启了debug的,显示开启方式:

glEnable(GL_DEBUG_OUTPUT);
debugCallback函数的参数类型说明:
Source Generated By
GL_DEBUG_SOURCE_API Calls to the OpenGL API
GL_DEBUG_SOURCE_WINDOW_SYSTEM Calls to a window system API
GL_DEBUG_SOURCE_THIRD_PARTY An application associated with OpenGL
GL_DEBUG_SOURCE_APPLICATION This application itself
GL_DEBUG_SOURCE_OTHER Some other source
The type parameter can have any of the following values:
Type Description
GL_DEBUG_TYPE_ERROR An error from the OpenGL API.
GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR Behavior that has been deprecated
GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR Undefined behaviour
GL_DEBUG_TYPE_PORTABILITIY Some functionality is not portable.
GL_DEBUG_TYPE_PERFORMANCE Possible performance issues
GL_DEBUG_TYPE_MARKER An annotation
GL_DEBUG_TYPE_PUSH_GROUP Messages related to debug group push.
GL_DEBUG_TYPE_POP_GROUP Messages related to debug group pop.
GL_DEBUG_TYPE_OTHER Other messages
The severity parameter can have the following values:
Severity Meaning
GL_DEBUG_SEVERITY_HIGH Errors or dangerous behaviour
GL_DEBUG_SEVERITY_MEDIUM Major performance warnings, other warnings or use of deprecated functionality.
GL_DEBUG_SEVERITY_LOW Redundant state changes, unimportant undefined behaviour.
GL_DEBUG_SEVERITY_NOTIFICATION A notification, not an error or performance issue.

Debug filter分组

opengl提供了两个函数glPushDebugGroup 和glPopDebugGroup。当在某个位置执行glPushDebugGroup,opengl内部就会将当前的debug filter保存到一个堆栈里面,然后再执行glDebugMessageControl时,不会覆盖之前位置设置的debug filter,直到执行glPopDebugGroup之后。

这两个函数的意义是:如果想让某块代码的debug级别是error,另一个代码的debug级别是warn,那么就可以使用glPushDebugGroup 和glPopDebugGroup来让多个debug级别共存。


杨柳岸,晓风残月。---柳永《雨霖铃》