From 9e149c6d70f49d4f617b7a67d5ee853dd5046a5b Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Fri, 24 Nov 2017 16:30:25 +0000 Subject: [PATCH] vrend: Add optional KHR_debug printing code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently only prints errors, not enabled by default. Reviewed-by: Marc-André Lureau Signed-off-by: Jakob Bornecrantz --- src/vrend_renderer.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 17f4b82..088b815 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -61,6 +61,9 @@ /* debugging aid to dump shaders */ int vrend_dump_shaders; +/* debugging via KHR_debug extension */ +int vrend_use_debug_cb = 0; + struct vrend_if_cbs *vrend_clicbs; struct vrend_fence { @@ -3813,6 +3816,17 @@ static void vrend_renderer_use_threaded_sync(void) } #endif +static void vrend_debug_cb(GLenum source, GLenum type, GLuint id, + GLenum severity, GLsizei length, + const GLchar* message, const void* userParam) +{ + if (type != GL_DEBUG_TYPE_ERROR) { + return; + } + + fprintf(stderr, "ERROR: %s\n", message); +} + int vrend_renderer_init(struct vrend_if_cbs *cbs, uint32_t flags) { int gl_ver; @@ -3833,6 +3847,13 @@ int vrend_renderer_init(struct vrend_if_cbs *cbs, uint32_t flags) vrend_clicbs->make_current(0, gl_context); gl_ver = epoxy_gl_version(); + /* enable error output as early as possible */ + if (vrend_use_debug_cb && epoxy_has_gl_extension("GL_KHR_debug")) { + glDebugMessageCallback(vrend_debug_cb, NULL); + glEnable(GL_DEBUG_OUTPUT); + glDisable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + } + vrend_state.gl_major_ver = gl_ver / 10; vrend_state.gl_minor_ver = gl_ver % 10; if (gl_ver > 30 && !epoxy_has_gl_extension("GL_ARB_compatibility")) {