diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 93b3718057..f42dfe3f78 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -516,7 +516,8 @@ void OMW::Engine::createWindow(Settings::Manager& settings) checkSDLError(SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8)); checkSDLError(SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0)); checkSDLError(SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24)); - checkSDLError(SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG)); + if (Debug::shouldDebugOpenGL()) + checkSDLError(SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG)); if (antialiasing > 0) { @@ -577,7 +578,8 @@ void OMW::Engine::createWindow(Settings::Manager& settings) camera->setGraphicsContext(graphicsWindow); camera->setViewport(0, 0, traits->width, traits->height); - mViewer->setRealizeOperation(new Debug::EnableGLDebugOperation()); + if (Debug::shouldDebugOpenGL()) + mViewer->setRealizeOperation(new Debug::EnableGLDebugOperation()); mViewer->realize(); diff --git a/components/debug/gldebug.cpp b/components/debug/gldebug.cpp index 76e7a4bb9b..20448ccbb3 100644 --- a/components/debug/gldebug.cpp +++ b/components/debug/gldebug.cpp @@ -31,6 +31,8 @@ either expressed or implied, of the FreeBSD Project. #include "gldebug.hpp" +#include + #include // OpenGL constants not provided by OSG: @@ -144,3 +146,15 @@ void Debug::EnableGLDebugOperation::operator()(osg::GraphicsContext* graphicsCon unsigned int contextID = graphicsContext->getState()->getContextID(); enableGLDebugExtension(contextID); } + +bool Debug::shouldDebugOpenGL() +{ + const char* env = std::getenv("OPENMW_DEBUG_OPENGL"); + if (!env) + return false; + std::string str(env); + if (str.length() == 0) + return true; + + return str.find("OFF") == std::string::npos && str.find("0") == std::string::npos && str.find("NO") == std::string::npos; +} diff --git a/components/debug/gldebug.hpp b/components/debug/gldebug.hpp index 77d6c82a85..823d4f36fa 100644 --- a/components/debug/gldebug.hpp +++ b/components/debug/gldebug.hpp @@ -15,5 +15,7 @@ namespace Debug private: OpenThreads::Mutex mMutex; }; + + bool shouldDebugOpenGL(); } #endif