OpenGL: Log GL_KHR_debug messages we receive
This allows the driver to communicate errors, warnings and improvement suggestions about our usage of the API.
This commit is contained in:
parent
2e8a7a7a08
commit
53df67376d
|
@ -369,6 +369,58 @@ void RendererOpenGL::SetWindow(EmuWindow* window) {
|
|||
render_window = window;
|
||||
}
|
||||
|
||||
static const char* GetSource(GLenum source) {
|
||||
#define RET(s) case GL_DEBUG_SOURCE_##s: return #s
|
||||
switch (source) {
|
||||
RET(API);
|
||||
RET(WINDOW_SYSTEM);
|
||||
RET(SHADER_COMPILER);
|
||||
RET(THIRD_PARTY);
|
||||
RET(APPLICATION);
|
||||
RET(OTHER);
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
#undef RET
|
||||
}
|
||||
|
||||
static const char* GetType(GLenum type) {
|
||||
#define RET(t) case GL_DEBUG_TYPE_##t: return #t
|
||||
switch (type) {
|
||||
RET(ERROR);
|
||||
RET(DEPRECATED_BEHAVIOR);
|
||||
RET(UNDEFINED_BEHAVIOR);
|
||||
RET(PORTABILITY);
|
||||
RET(PERFORMANCE);
|
||||
RET(OTHER);
|
||||
RET(MARKER);
|
||||
default:
|
||||
UNREACHABLE();
|
||||
}
|
||||
#undef RET
|
||||
}
|
||||
|
||||
static void DebugHandler(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
|
||||
const GLchar* message, const void* user_param) {
|
||||
Log::Level level;
|
||||
switch (severity) {
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
level = Log::Level::Error;
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
level = Log::Level::Warning;
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
||||
level = Log::Level::Info;
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
level = Log::Level::Debug;
|
||||
break;
|
||||
}
|
||||
LOG_GENERIC(Log::Class::Render_OpenGL, level, "%s %s %d: %s",
|
||||
GetSource(source), GetType(type), id, message);
|
||||
}
|
||||
|
||||
/// Initialize the renderer
|
||||
void RendererOpenGL::Init() {
|
||||
render_window->MakeCurrent();
|
||||
|
@ -379,6 +431,11 @@ void RendererOpenGL::Init() {
|
|||
exit(-1);
|
||||
}
|
||||
|
||||
if (GLAD_GL_KHR_debug) {
|
||||
glEnable(GL_DEBUG_OUTPUT);
|
||||
glDebugMessageCallback(DebugHandler, nullptr);
|
||||
}
|
||||
|
||||
LOG_INFO(Render_OpenGL, "GL_VERSION: %s", glGetString(GL_VERSION));
|
||||
LOG_INFO(Render_OpenGL, "GL_VENDOR: %s", glGetString(GL_VENDOR));
|
||||
LOG_INFO(Render_OpenGL, "GL_RENDERER: %s", glGetString(GL_RENDERER));
|
||||
|
|
Reference in New Issue