From f75b6d8c5d41dc1532ddd8e674672fc5afadd7c6 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Thu, 18 Aug 2016 02:10:54 +0200 Subject: [PATCH] Improve debug level filtering --- src/gl/system/gl_debug.cpp | 26 +++++++++++++++++++++++++- src/gl/system/gl_debug.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/gl/system/gl_debug.cpp b/src/gl/system/gl_debug.cpp index 932ae221df..d4a0b2fcf2 100644 --- a/src/gl/system/gl_debug.cpp +++ b/src/gl/system/gl_debug.cpp @@ -156,6 +156,26 @@ void FGLDebug::UpdateLoggingLevel() } } +//----------------------------------------------------------------------------- +// +// The log may already contain entries for a debug level we are no longer +// interested in.. +// +//----------------------------------------------------------------------------- + +bool FGLDebug::IsFilteredByDebugLevel(GLenum severity) +{ + int severityLevel = 0; + switch (severity) + { + case GL_DEBUG_SEVERITY_LOW: severityLevel = 1; break; + case GL_DEBUG_SEVERITY_MEDIUM: severityLevel = 2; break; + case GL_DEBUG_SEVERITY_HIGH: severityLevel = 3; break; + case GL_DEBUG_SEVERITY_NOTIFICATION: severityLevel = 4; break; + } + return severityLevel >= (int)gl_debug_level; +} + //----------------------------------------------------------------------------- // // Prints all logged messages to the console @@ -193,7 +213,8 @@ void FGLDebug::OutputMessageLog() GLsizei offset = 0; for (GLuint i = 0; i < numMessages; i++) { - PrintMessage(sources[i], types[i], ids[i], severities[i], lengths[i], &messageLog[offset]); + if (!IsFilteredByDebugLevel(severities[i])) + PrintMessage(sources[i], types[i], ids[i], severities[i], lengths[i], &messageLog[offset]); offset += lengths[i]; } } @@ -248,6 +269,9 @@ void FGLDebug::PrintMessage(GLenum source, GLenum type, GLuint id, GLenum severi void FGLDebug::DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam) { + if (IsFilteredByDebugLevel(severity)) + return; + PrintMessage(source, type, id, severity, length, message); if (severity != GL_DEBUG_SEVERITY_NOTIFICATION) diff --git a/src/gl/system/gl_debug.h b/src/gl/system/gl_debug.h index 2401ba5cc4..1688297be9 100644 --- a/src/gl/system/gl_debug.h +++ b/src/gl/system/gl_debug.h @@ -22,6 +22,7 @@ private: void UpdateLoggingLevel(); void OutputMessageLog(); + static bool IsFilteredByDebugLevel(GLenum severity); static void PrintMessage(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message); static void APIENTRY DebugCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam);