From 18ff65fb0e0090926674a875322a8bfb2bd1f6b0 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Wed, 17 Aug 2016 23:52:20 +0200 Subject: [PATCH] Filter logging to only display each message once --- src/gl/system/gl_debug.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/gl/system/gl_debug.cpp b/src/gl/system/gl_debug.cpp index 365356752..932ae221d 100644 --- a/src/gl/system/gl_debug.cpp +++ b/src/gl/system/gl_debug.cpp @@ -42,6 +42,7 @@ #include "gl/system/gl_system.h" #include "gl/system/gl_interface.h" #include "gl/system/gl_debug.h" +#include #ifndef _MSC_VER #include @@ -209,19 +210,33 @@ void FGLDebug::PrintMessage(GLenum source, GLenum type, GLuint id, GLenum severi if (type == GL_DEBUG_TYPE_PUSH_GROUP || type == GL_DEBUG_TYPE_POP_GROUP) return; + const int maxMessages = 50; + static int messagesPrinted = 0; + if (messagesPrinted > maxMessages) + return; + + FString msg(message, length); + + static std::set seenMessages; + bool alreadySeen = !seenMessages.insert(msg.GetChars()).second; + if (alreadySeen) + return; + messagesPrinted++; - if (messagesPrinted == 50) + if (messagesPrinted == maxMessages) { Printf("Max OpenGL debug messages reached. Suppressing further output.\n"); } - else if (messagesPrinted < 50) + else if (messagesPrinted < maxMessages) { - FString msg(message, length); FString sourceStr = SourceToString(source); FString typeStr = TypeToString(type); FString severityStr = SeverityToString(severity); - Printf("%s [%s] %s: %s\n", severityStr.GetChars(), sourceStr.GetChars(), typeStr.GetChars(), msg.GetChars()); + if (type != GL_DEBUG_TYPE_OTHER) + Printf("[%s] %s, %s: %s\n", sourceStr.GetChars(), severityStr.GetChars(), typeStr.GetChars(), msg.GetChars()); + else + Printf("[%s] %s: %s\n", sourceStr.GetChars(), severityStr.GetChars(), msg.GetChars()); } }