Add an optional context when debug messages are logged

* Many debug messages are completely useless without context, so to track
  down bugs in crashdumps with logs, etc, it would be very useful to add
  a little snippet to show what function call the message was fired from
  and what the parameters were.
* I'll just add these as/when necessary for tracking bugs.
This commit is contained in:
baldurk
2014-12-26 12:54:48 +00:00
parent fd9d49f13e
commit 2788069f4a
2 changed files with 25 additions and 0 deletions
+2
View File
@@ -1849,6 +1849,8 @@ void WrappedOpenGL::DebugSnoop(GLenum source, GLenum type, GLuint id, GLenum sev
{
if(type != eGL_DEBUG_TYPE_PERFORMANCE && type != eGL_DEBUG_TYPE_OTHER)
{
if(m_DebugMsgContext != "")
RDCLOG("Debug Message context: \"%s\"", m_DebugMsgContext.c_str());
RDCLOG("Got a Debug message from %s, type %s, ID %d, severity %s:\n'%s'",
ToStr::Get(source).c_str(), ToStr::Get(type).c_str(), id, ToStr::Get(severity).c_str(), message);
}
+23
View File
@@ -101,6 +101,7 @@ class WrappedOpenGL
GLDEBUGPROC m_RealDebugFunc;
const void *m_RealDebugFuncParam;
string m_DebugMsgContext;
void DebugSnoop(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message);
static void APIENTRY DebugSnoopStatic(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar *message, const void *userParam)
@@ -347,6 +348,8 @@ class WrappedOpenGL
GLReplay *GetReplay() { return &m_Replay; }
void *GetCtx();
void *SwitchToContext(void *ctx);
void SetDebugMsgContext(const char *context) { m_DebugMsgContext = context; }
// replay interface
void Initialise(GLInitParams &params);
@@ -1185,3 +1188,23 @@ class WrappedOpenGL
IMPLEMENT_FUNCTION_SERIALISED(void, glVertexArrayVertexAttribLOffsetEXT(GLuint vaobj, GLuint buffer, GLuint index, GLint size, GLenum type, GLsizei stride, GLintptr offset));
IMPLEMENT_FUNCTION_SERIALISED(void, glVertexArrayVertexAttribDivisorEXT(GLuint vaobj, GLuint index, GLuint divisor));
};
class ScopedDebugContext
{
public:
ScopedDebugContext(WrappedOpenGL *gl, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
char buf[1024]; buf[1023] = 0;
StringFormat::vsnprintf(buf, 1023, fmt, args);
va_end(args);
m_GL = gl;
m_GL->SetDebugMsgContext(buf);
}
~ScopedDebugContext() { m_GL->SetDebugMsgContext(""); }
private:
WrappedOpenGL *m_GL;
};