diff options
author | Andrei Karas <akaras@inbox.ru> | 2012-10-23 03:51:06 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2012-10-23 13:13:02 +0300 |
commit | 4ab2c210277be6cf16f86e2fcf4fa5a6c090b45e (patch) | |
tree | 3ccee6444e6c044e895d3bb70942f1547addb230 /src | |
parent | 89106a96cd86042415d19f307a4ade5f1fae8b5d (diff) | |
download | ManaVerse-4ab2c210277be6cf16f86e2fcf4fa5a6c090b45e.tar.gz ManaVerse-4ab2c210277be6cf16f86e2fcf4fa5a6c090b45e.tar.bz2 ManaVerse-4ab2c210277be6cf16f86e2fcf4fa5a6c090b45e.tar.xz ManaVerse-4ab2c210277be6cf16f86e2fcf4fa5a6c090b45e.zip |
Add support for OpenGL debug extensions.
Diffstat (limited to 'src')
-rw-r--r-- | src/defaults.cpp | 1 | ||||
-rw-r--r-- | src/graphicsmanager.cpp | 103 | ||||
-rw-r--r-- | src/graphicsmanager.h | 4 | ||||
-rw-r--r-- | src/gui/setup_other.cpp | 3 | ||||
-rw-r--r-- | src/mgl.h | 22 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 2 |
6 files changed, 134 insertions, 1 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp index d29a818a7..77c7f04af 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -268,6 +268,7 @@ DefaultsData* getConfigDefaults() AddDEF("useTextureSampler", false); AddDEF("ministatussaved", 0); AddDEF("allowscreensaver", false); + AddDEF("debugOpenGL", 0); return configData; } diff --git a/src/graphicsmanager.cpp b/src/graphicsmanager.cpp index d746cb199..ba96041be 100644 --- a/src/graphicsmanager.cpp +++ b/src/graphicsmanager.cpp @@ -84,6 +84,7 @@ GraphicsManager::GraphicsManager() : #ifdef USE_OPENGL mUseTextureSampler(true), mTextureSampler(0), + mSupportDebug(0), #endif mUseAtlases(false) { @@ -639,16 +640,19 @@ void GraphicsManager::initOpenGLFunctions() logger->log("found GL_KHR_debug"); assignFunction(glDebugMessageControl, "glDebugMessageControl"); assignFunction(glDebugMessageCallback, "glDebugMessageCallback"); + mSupportDebug = 2; } else if (supportExtension("GL_ARB_debug_output")) { logger->log("found GL_ARB_debug_output"); assignFunction(glDebugMessageControl, "glDebugMessageControlARB"); assignFunction(glDebugMessageCallback, "glDebugMessageCallbackARB"); + mSupportDebug = 1; } else { logger->log("debug extensions not found"); + mSupportDebug = 0; } #ifdef WIN32 @@ -682,6 +686,7 @@ void GraphicsManager::initOpenGL() updateExtensions(); initOpenGLFunctions(); updatePlanformExtensions(); + updateDebugLog(); createTextureSampler(); updateLimits(); } @@ -745,4 +750,102 @@ void GraphicsManager::detectVideoSettings() delete test; } } + +static void debugCallback(GLenum source, GLenum type, GLuint id, + GLenum severity, GLsizei length, + const GLchar *text, GLvoid *userParam) +{ + std::string message("OPENGL:"); + switch (source) + { + case GL_DEBUG_SOURCE_API: + message += " API"; + break; + case GL_DEBUG_SOURCE_WINDOW_SYSTEM: + message += " WM"; + break; + case GL_DEBUG_SOURCE_SHADER_COMPILER: + message += " SHADERS"; + break; + case GL_DEBUG_SOURCE_THIRD_PARTY: + message += " THIRD_PARTY"; + break; + case GL_DEBUG_SOURCE_APPLICATION: + message += " APP"; + break; + case GL_DEBUG_SOURCE_OTHER: + message += " OTHER"; + break; + default: + message += " ?" + toString(source); + break; + } + switch (type) + { + case GL_DEBUG_TYPE_ERROR: + message += " ERROR"; + break; + case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR: + message += " DEPRECATED"; + break; + case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR: + message += " UNDEFINED"; + break; + case GL_DEBUG_TYPE_PORTABILITY: + message += " PORTABILITY"; + break; + case GL_DEBUG_TYPE_PERFORMANCE: + message += " PERFOMANCE"; + break; + case GL_DEBUG_TYPE_OTHER: + message += " OTHER"; + break; + case GL_DEBUG_TYPE_MARKER: + message += " MARKER"; + break; + default: + message += " ?" + toString(type); + break; + } + message += " " + toString(id); + switch (severity) + { + case GL_DEBUG_SEVERITY_NOTIFICATION: + message += " N"; + break; + case GL_DEBUG_SEVERITY_HIGH: + message += " H"; + break; + case GL_DEBUG_SEVERITY_MEDIUM: + message += " M"; + break; + case GL_DEBUG_SEVERITY_LOW: + message += " L"; + break; + default: + message += " ?" + toString(type); + break; + } + char *buf = new char[length + 1]; + memcpy (buf, text, length); + buf[length] = 0; + message += " "; + message += buf; + delete [] buf; + logger->log(message); +} + +void GraphicsManager::updateDebugLog() +{ + if (mSupportDebug && config.getIntValue("debugOpenGL")) + { + logger->log("Enable OpenGL debug log"); + glEnable(GL_DEBUG_OUTPUT); + glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); + + mglDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, + 0, nullptr, GL_TRUE); + mglDebugMessageCallback(&debugCallback, this); + } +} #endif diff --git a/src/graphicsmanager.h b/src/graphicsmanager.h index 53de59c46..9523fb3d0 100644 --- a/src/graphicsmanager.h +++ b/src/graphicsmanager.h @@ -111,6 +111,8 @@ class GraphicsManager final { return mUseTextureSampler; } unsigned int getLastError(); + + void updateDebugLog(); #endif private: @@ -140,6 +142,8 @@ class GraphicsManager final bool mUseTextureSampler; GLuint mTextureSampler; + + int mSupportDebug; #endif bool mUseAtlases; diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index ff0e584fc..0fec8a99d 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -223,6 +223,9 @@ Setup_Other::Setup_Other(const Widget2 *const widget) : new SetupItemCheckBox(_("Enable debug log"), "", "debugLog", this, "debugLogEvent"); + new SetupItemCheckBox(_("Enable OpenGL log"), "", + "debugOpenGL", this, "debugOpenGLEvent"); + new SetupItemCheckBox(_("Low traffic mode"), "", "lowTraffic", this, "lowTrafficEvent"); @@ -50,6 +50,28 @@ #define GL_MAX_ELEMENTS_INDICES 0x80E9 #endif +#ifndef GL_DEBUG_OUTPUT +#define GL_DEBUG_OUTPUT_SYNCHRONOUS 0x8242 +#define GL_DEBUG_OUTPUT 0x92E0 +#define GL_DEBUG_SOURCE_API 0x8246 +#define GL_DEBUG_SOURCE_WINDOW_SYSTEM 0x8247 +#define GL_DEBUG_SOURCE_SHADER_COMPILER 0x8248 +#define GL_DEBUG_SOURCE_THIRD_PARTY 0x8249 +#define GL_DEBUG_SOURCE_APPLICATION 0x824A +#define GL_DEBUG_SOURCE_OTHER 0x824B +#define GL_DEBUG_TYPE_ERROR 0x824C +#define GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR 0x824D +#define GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR 0x824E +#define GL_DEBUG_TYPE_PORTABILITY 0x824F +#define GL_DEBUG_TYPE_PERFORMANCE 0x8250 +#define GL_DEBUG_TYPE_OTHER 0x8251 +#define GL_DEBUG_TYPE_MARKER 0x8268 +#define GL_DEBUG_SEVERITY_NOTIFICATION 0x826B +#define GL_DEBUG_SEVERITY_HIGH 0x9146 +#define GL_DEBUG_SEVERITY_MEDIUM 0x9147 +#define GL_DEBUG_SEVERITY_LOW 0x9148 +#endif + #define defNameE(name) extern name##_t m##name typedef void (APIENTRY *glGenRenderbuffers_t)(GLsizei, GLuint *); diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 3c5e35738..5bd4db3e4 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -239,7 +239,7 @@ void ResourceManager::logResource(const Resource *const res) const int count = image->getRefCount(); if (count) src += " " + toString(count); - if (image && image->getGLImage()) + if (image) { logger->log("resource(%s, %u) %s", res->mIdPath.c_str(), image->getGLImage(), src.c_str()); |