From 5d416a0f699c68bb15f16c2474d3ba8b615c4d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Fri, 13 Nov 2015 13:11:47 +0100 Subject: [PATCH] Introduce additional safety checks for init debug output in SceneOpenGL There are slight differences between GL_ARB_debug_output and GL_KHR_debug affecting how it works on GLES. With GL_KHR_debug the context should be created with a debug flag. With the ARB extension there is no such requirement. Empirical data (Mali) shows that it doesn't work if the context is not created with the flag, although the spec seems to allows it. So: * if we have GL_ARB_debug_output we assume it works * if we only have GL_KHR_debug we check whether the context is created with debug support (which we don't do yet, but maybe should?) * on GLES we can only query with version 3.2 (which we don't request yet) * with anything older we just assume it's not enabled (which is correct given that we don't enable the debug flag) REVIEW: 126053 --- scene_opengl.cpp | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/scene_opengl.cpp b/scene_opengl.cpp index dbe33539ed..c90c260e2d 100644 --- a/scene_opengl.cpp +++ b/scene_opengl.cpp @@ -476,9 +476,27 @@ static void scheduleVboReInit() void SceneOpenGL::initDebugOutput() { const bool have_KHR_debug = hasGLExtension(QByteArrayLiteral("GL_KHR_debug")); - if (!have_KHR_debug && !hasGLExtension(QByteArrayLiteral("GL_ARB_debug_output"))) + const bool have_ARB_debug = hasGLExtension(QByteArrayLiteral("GL_ARB_debug_output")); + if (!have_KHR_debug && !have_ARB_debug) return; + if (!have_ARB_debug) { + // if we don't have ARB debug, but only KHR debug we need to verify whether the context is a debug context + // it should work without as well, but empirical tests show: no it doesn't + if (GLPlatform::instance()->isGLES()) { + if (!hasGLVersion(3, 2)) { + // empirical data shows extension doesn't work + return; + } + } + // can only be queried with either OpenGL or OpenGL ES of at least 3.1 + GLint value = 0; + glGetIntegerv(GL_CONTEXT_FLAGS, &value); + if (!(value & GL_CONTEXT_FLAG_DEBUG_BIT)) { + return; + } + } + gs_debuggedScene = this; // Set the callback function @@ -515,11 +533,6 @@ void SceneOpenGL::initDebugOutput() } }; - // Expoxy fails to resolve glDebugMessageCallback on GLES - if (!glDebugMessageCallback) { - return; - } - glDebugMessageCallback(callback, nullptr); // This state exists only in GL_KHR_debug