[Mesa-dev] [PATCH 11/11] mesa: add basic GL error logging

nobled nobled at dreamwidth.org
Mon May 2 16:01:21 PDT 2011


---
 src/mesa/main/errors.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index ed0e7b7..d910092 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -543,6 +543,17 @@ _mesa_init_errors(struct gl_context *ctx)
 /*@{*/

 static void
+_mesa_log_api_error(struct gl_context *ctx, ApiError id,
+                    GLint len, const char *buf)
+{
+   GLenum source = GL_DEBUG_SOURCE_API_ARB;
+   GLenum type = GL_DEBUG_TYPE_ERROR_ARB;
+   GLenum severity = GL_DEBUG_SEVERITY_HIGH_ARB;
+
+   _mesa_log_msg(ctx, source, type, id, severity, len, buf);
+}
+
+static void
 output_if_debug(const char *prefixString, const char *outputString,
                 GLboolean newline)
 {
@@ -731,16 +742,23 @@ _mesa_error( struct gl_context *ctx, GLenum
error, const char *fmtString, ... )
       }
       else {
          char s[MAXSTRING], s2[MAXSTRING];
+         int len;
          va_list args;

          flush_delayed_errors( ctx );

          va_start(args, fmtString);
-         _mesa_vsnprintf(s, MAXSTRING, fmtString, args);
+         len = _mesa_vsnprintf(s, MAXSTRING, fmtString, args);
          va_end(args);

-         _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s);
-         output_if_debug("Mesa: User error", s2, GL_TRUE);
+         if (len < MAXSTRING)
+            len = _mesa_snprintf(s2, MAXSTRING, "%s in %s",
+                                 error_string(error), s);
+
+         if (len < MAXSTRING) {
+            _mesa_log_api_error(ctx, API_ERROR_UNKNOWN, len, s2);
+            output_if_debug("Mesa: User error", s2, GL_TRUE);
+         }

          ctx->ErrorDebugFmtString = fmtString;
          ctx->ErrorDebugCount = 0;
-- 
1.7.0.4
-------------- next part --------------
From cfc91258e92038350418c43798a5bd9d9512d1d3 Mon Sep 17 00:00:00 2001
From: nobled <nobled at dreamwidth.org>
Date: Mon, 2 May 2011 21:29:19 +0000
Subject: [PATCH] mesa: add basic GL error logging

---
 src/mesa/main/errors.c |   24 +++++++++++++++++++++---
 1 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index ed0e7b7..d910092 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -543,6 +543,17 @@ _mesa_init_errors(struct gl_context *ctx)
 /*@{*/
 
 static void
+_mesa_log_api_error(struct gl_context *ctx, ApiError id,
+                    GLint len, const char *buf)
+{
+   GLenum source = GL_DEBUG_SOURCE_API_ARB;
+   GLenum type = GL_DEBUG_TYPE_ERROR_ARB;
+   GLenum severity = GL_DEBUG_SEVERITY_HIGH_ARB;
+
+   _mesa_log_msg(ctx, source, type, id, severity, len, buf);
+}
+
+static void
 output_if_debug(const char *prefixString, const char *outputString,
                 GLboolean newline)
 {
@@ -731,16 +742,23 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
       }
       else {
          char s[MAXSTRING], s2[MAXSTRING];
+         int len;
          va_list args;
 
          flush_delayed_errors( ctx );
          
          va_start(args, fmtString);
-         _mesa_vsnprintf(s, MAXSTRING, fmtString, args);
+         len = _mesa_vsnprintf(s, MAXSTRING, fmtString, args);
          va_end(args);
 
-         _mesa_snprintf(s2, MAXSTRING, "%s in %s", error_string(error), s);
-         output_if_debug("Mesa: User error", s2, GL_TRUE);
+         if (len < MAXSTRING)
+            len = _mesa_snprintf(s2, MAXSTRING, "%s in %s",
+                                 error_string(error), s);
+
+         if (len < MAXSTRING) {
+            _mesa_log_api_error(ctx, API_ERROR_UNKNOWN, len, s2);
+            output_if_debug("Mesa: User error", s2, GL_TRUE);
+         }
          
          ctx->ErrorDebugFmtString = fmtString;
          ctx->ErrorDebugCount = 0;
-- 
1.7.0.4


More information about the mesa-dev mailing list