On 05/02/2011 05:00 PM, nobled wrote:
Controlling the output of client-provided messages
isn't done yet.
---
  src/mesa/main/errors.c |  110 ++++++++++++++++++++++++++++++++++++++++++++++++
  1 files changed, 110 insertions(+), 0 deletions(-)


Please put comments on all the new functions defined here (and in your other patches) to explain what they do.


diff --git a/src/mesa/main/errors.c b/src/mesa/main/errors.c
index 9d74a05..e304184 100644
--- a/src/mesa/main/errors.c
+++ b/src/mesa/main/errors.c
@@ -41,6 +41,31 @@

  static char out_of_memory[] = "Debugging error: out of memory";

+#define enum_is(e, kind1, kind2) \
+   ((e) == GL_DEBUG_##kind1##_##kind2##_ARB || (e) == GL_DONT_CARE)
+#define severity_is(sev, kind) enum_is(sev, SEVERITY, kind)
+#define source_is(s, kind) enum_is(s, SOURCE, kind)
+#define type_is(t, kind) enum_is(t, TYPE, kind)
+
+static GLboolean
+should_log(struct gl_context *ctx, GLenum source, GLenum type,
+           GLuint id, GLenum severity)
+{
+   if (type_is(type, ERROR)) {
+      if (source_is(source, API))
+         return ctx->Debug.ApiErrors[id];
+      if (source_is(source, WINDOW_SYSTEM))
+         return ctx->Debug.WinsysErrors[id];
+      if (source_is(source, SHADER_COMPILER))
+         return ctx->Debug.ShaderErrors[id];
+      if (source_is(source, OTHER))
+         return ctx->Debug.OtherErrors[id];
+   }
+
+   /* TODO: tracking client messages' state. */
+   return (severity != GL_DEBUG_SEVERITY_LOW_ARB);
+}
+
  /* 'buf' is not necessarily a null-terminated string. When logging, copy
   * 'len' characters from it, store them in a new, null-terminated string,
   * and remember the number of bytes used by that string, *including*
@@ -55,6 +80,9 @@ _mesa_log_msg(struct gl_context *ctx, GLenum source,
GLenum type,

     assert(len>= 0&&  len<  _MESA_MAX_DEBUG_MESSAGE_LENGTH);

+   if (!should_log(ctx, source, type, id, severity))
+      return;
+
     if (ctx->Debug.Callback) {
        ctx->Debug.Callback(source, type, id, severity,
                            len, buf, ctx->Debug.CallbackData);
@@ -281,6 +309,82 @@ _mesa_GetDebugMessageLogARB(GLuint count, GLsizei
logSize, GLenum* sources,
     return ret;
  }

+static void
+control_messages(GLboolean *array, GLuint size,
+                 GLsizei count, const GLuint *ids, GLboolean enabled)
+{
+   int i;
+
+   if (!count) {
+      for (i = 0; (GLuint)i<  size; i++) {
+         array[i] = enabled;
+      }
+      return;
+   }

If you put the declaration of 'i' inside that loop you can use the right type to avoid casting.


+
+   for (i = 0; i<  count; i++) {
+      if (ids[i]>= size) {
+         /* XXX: The spec doesn't say what to do with a non-existent ID. */
+         continue;
+      }
+      array[ids[i]] = enabled;
+   }
+}
+
+static void
+control_app_messages(struct gl_context *ctx, GLenum source, GLenum type,
+                     GLenum severity, GLsizei count, const GLuint *ids,
+                     GLboolean enabled)
+{
+   assert(0&&  "glDebugMessageControlARB():"
+          " Controlling application IDs not implemented");
+}
+
+static void GLAPIENTRY
+_mesa_DebugMessageControlARB(GLenum source, GLenum type, GLenum severity,
+                             GLsizei count, const GLuint *ids,
+                             GLboolean enabled)
+{
+   GET_CURRENT_CONTEXT(ctx);
+
+   if (count<  0) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glDebugMessageControlARB"
+                 "(count=%d : count must not be negative)", count);
+      return;
+   }
+
+   if (!validate_params(ctx, CONTROL, source, type, severity))
+      return; /* GL_INVALID_ENUM */
+
+   if (count&&  (severity != GL_DONT_CARE || type == GL_DONT_CARE
+                 || source == GL_DONT_CARE)) {
+      _mesa_error(ctx, GL_INVALID_OPERATION, "glDebugMessageControlARB"
+                 "(When passing an array of ids, severity must be"
+         " GL_DONT_CARE, and source and type must not be GL_DONT_CARE.");
+      return;
+   }
+
+   if (source_is(source, APPLICATION) || source_is(source, THIRD_PARTY))
+      control_app_messages(ctx, source, type, severity, count, ids, enabled);
+
+   if (severity_is(severity, HIGH)) {
+      if (type_is(type, ERROR)) {
+         if (source_is(source, API))
+            control_messages(ctx->Debug.ApiErrors, API_ERROR_COUNT,
+                             count, ids, enabled);
+         if (source_is(source, WINDOW_SYSTEM))
+            control_messages(ctx->Debug.WinsysErrors, WINSYS_ERROR_COUNT,
+                             count, ids, enabled);
+         if (source_is(source, SHADER_COMPILER))
+            control_messages(ctx->Debug.ShaderErrors, SHADER_ERROR_COUNT,
+                             count, ids, enabled);
+         if (source_is(source, OTHER))
+            control_messages(ctx->Debug.OtherErrors, OTHER_ERROR_COUNT,
+                             count, ids, enabled);
+      }
+   }
+}
+
  static void GLAPIENTRY
  _mesa_DebugMessageCallbackARB(GLDEBUGPROCARB callback, GLvoid* userParam)
  {
@@ -309,6 +413,12 @@ _mesa_init_errors(struct gl_context *ctx)
     ctx->Debug.NumMessages = 0;
     ctx->Debug.NextMsg = 0;
     ctx->Debug.NextMsgLength = 0;
+
+   /* Enable all the messages with severity HIGH or MEDIUM by default. */
+   memset(ctx->Debug.ApiErrors, GL_TRUE, sizeof ctx->Debug.ApiErrors);
+   memset(ctx->Debug.WinsysErrors, GL_TRUE, sizeof ctx->Debug.WinsysErrors);
+   memset(ctx->Debug.ShaderErrors, GL_TRUE, sizeof ctx->Debug.ShaderErrors);
+   memset(ctx->Debug.OtherErrors, GL_TRUE, sizeof ctx->Debug.OtherErrors);
  }

  /**********************************************************************/



_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to