From 53df67376de96904f0174fc9d4a35940b87652b7 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sat, 10 Oct 2015 00:32:40 +0100 Subject: 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. --- src/video_core/renderer_opengl/renderer_opengl.cpp | 57 ++++++++++++++++++++++ 1 file changed, 57 insertions(+) (limited to 'src/video_core') diff --git a/src/video_core/renderer_opengl/renderer_opengl.cpp b/src/video_core/renderer_opengl/renderer_opengl.cpp index f1313b54f..4202d828c 100644 --- a/src/video_core/renderer_opengl/renderer_opengl.cpp +++ b/src/video_core/renderer_opengl/renderer_opengl.cpp @@ -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)); -- cgit v1.2.3