From 97789b18c0bfacac7fd6daab3b83e2e47371f1fe Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Sun, 12 Feb 2017 17:58:28 -0400 Subject: [PATCH] Only use opengl debug groups if the LOVE_GRAPHICS_DEBUG environment variable is set to 1. --HG-- branch : minor --- src/modules/graphics/Graphics.cpp | 15 ++++++++++++++ src/modules/graphics/Graphics.h | 2 ++ src/modules/graphics/opengl/Graphics.cpp | 12 +---------- src/modules/graphics/opengl/OpenGL.cpp | 26 ++++++++++++++++++++++++ src/modules/graphics/opengl/OpenGL.h | 21 ++----------------- src/modules/window/sdl/Window.cpp | 3 +-- 6 files changed, 47 insertions(+), 32 deletions(-) diff --git a/src/modules/graphics/Graphics.cpp b/src/modules/graphics/Graphics.cpp index 62503ae91..a076ec7d7 100644 --- a/src/modules/graphics/Graphics.cpp +++ b/src/modules/graphics/Graphics.cpp @@ -28,6 +28,7 @@ // C++ #include +#include namespace love { @@ -35,6 +36,8 @@ namespace graphics { static bool gammaCorrect = false; +static bool debugMode = false; +static bool debugModeQueried = false; void setGammaCorrect(bool gammacorrect) { @@ -80,6 +83,18 @@ Colorf unGammaCorrectColor(const Colorf &c) return r; } +bool isDebugEnabled() +{ + if (!debugModeQueried) + { + const char *debugenv = getenv("LOVE_GRAPHICS_DEBUG"); + debugMode = debugenv != nullptr && debugenv[0] != '0'; + debugModeQueried = true; + } + + return debugMode; +} + love::Type Graphics::type("graphics", &Module::type); Shader::ShaderSource Graphics::defaultShaderCode[Shader::LANGUAGE_MAX_ENUM][2]; diff --git a/src/modules/graphics/Graphics.h b/src/modules/graphics/Graphics.h index 149f4643a..516fb54b3 100644 --- a/src/modules/graphics/Graphics.h +++ b/src/modules/graphics/Graphics.h @@ -88,6 +88,8 @@ void unGammaCorrectColor(Colorf &c); Colorf gammaCorrectColor(const Colorf &c); Colorf unGammaCorrectColor(const Colorf &c); +bool isDebugEnabled(); + class Graphics : public Module { public: diff --git a/src/modules/graphics/opengl/Graphics.cpp b/src/modules/graphics/opengl/Graphics.cpp index ecc63e744..418cc5185 100644 --- a/src/modules/graphics/opengl/Graphics.cpp +++ b/src/modules/graphics/opengl/Graphics.cpp @@ -272,17 +272,7 @@ bool Graphics::setMode(int width, int height, int pixelwidth, int pixelheight, b else setGammaCorrect(false); - bool enabledebug = false; - - if (GLAD_VERSION_3_0) - { - // Enable OpenGL's debug output if a debug context has been created. - GLint flags = 0; - glGetIntegerv(GL_CONTEXT_FLAGS, &flags); - enabledebug = (flags & GL_CONTEXT_FLAG_DEBUG_BIT) != 0; - } - - setDebug(enabledebug); + setDebug(isDebugEnabled()); if (streamBufferState.vb[0] == nullptr) { diff --git a/src/modules/graphics/opengl/OpenGL.cpp b/src/modules/graphics/opengl/OpenGL.cpp index 3bd47406d..89278c2aa 100644 --- a/src/modules/graphics/opengl/OpenGL.cpp +++ b/src/modules/graphics/opengl/OpenGL.cpp @@ -64,6 +64,32 @@ static void *LOVEGetProcAddress(const char *name) return SDL_GL_GetProcAddress(name); } +OpenGL::TempDebugGroup::TempDebugGroup(const char *name) +{ + if (isDebugEnabled()) + { + if (GLAD_VERSION_4_3 || (GLAD_KHR_debug && !GLAD_ES_VERSION_2_0)) + glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, 0, (const GLchar *) name); + else if (GLAD_ES_VERSION_2_0 && GLAD_KHR_debug) + glPushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION, 0, 0, (const GLchar *) name); + else if (GLAD_EXT_debug_marker) + glPushGroupMarkerEXT(0, (const GLchar *) name); + } +} + +OpenGL::TempDebugGroup::~TempDebugGroup() +{ + if (isDebugEnabled()) + { + if (GLAD_VERSION_4_3 || (GLAD_KHR_debug && !GLAD_ES_VERSION_2_0)) + glPopDebugGroup(); + else if (GLAD_ES_VERSION_2_0 && GLAD_KHR_debug) + glPopDebugGroupKHR(); + else if (GLAD_EXT_debug_marker) + glPopGroupMarkerEXT(); + } +} + OpenGL::OpenGL() : stats() , contextInitialized(false) diff --git a/src/modules/graphics/opengl/OpenGL.h b/src/modules/graphics/opengl/OpenGL.h index af5c52554..b22c366b1 100644 --- a/src/modules/graphics/opengl/OpenGL.h +++ b/src/modules/graphics/opengl/OpenGL.h @@ -101,25 +101,8 @@ public: { public: - TempDebugGroup(const char *name) - { - if (GLAD_VERSION_4_3 || (GLAD_KHR_debug && !GLAD_ES_VERSION_2_0)) - glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, 0, (const GLchar *) name); - else if (GLAD_ES_VERSION_2_0 && GLAD_KHR_debug) - glPushDebugGroupKHR(GL_DEBUG_SOURCE_APPLICATION, 0, 0, (const GLchar *) name); - else if (GLAD_EXT_debug_marker) - glPushGroupMarkerEXT(0, (const GLchar *) name); - } - - ~TempDebugGroup() - { - if (GLAD_VERSION_4_3 || (GLAD_KHR_debug && !GLAD_ES_VERSION_2_0)) - glPopDebugGroup(); - else if (GLAD_ES_VERSION_2_0 && GLAD_KHR_debug) - glPopDebugGroupKHR(); - else if (GLAD_EXT_debug_marker) - glPopGroupMarkerEXT(); - } + TempDebugGroup(const char *name); + ~TempDebugGroup(); }; struct Stats diff --git a/src/modules/window/sdl/Window.cpp b/src/modules/window/sdl/Window.cpp index 31f2c0539..e759fbb0b 100644 --- a/src/modules/window/sdl/Window.cpp +++ b/src/modules/window/sdl/Window.cpp @@ -235,8 +235,7 @@ std::vector Window::getContextAttribsList() const } // Do we want a debug context? - const char *debughint = SDL_GetHint("LOVE_GRAPHICS_DEBUG"); - bool debug = (debughint != nullptr && debughint[0] != '0'); + bool debug = love::graphics::isDebugEnabled(); const char *preferGL2hint = SDL_GetHint("LOVE_GRAPHICS_USE_GL2"); bool preferGL2 = (preferGL2hint != nullptr && preferGL2hint[0] != '0');