mesa: remove unused var in _mesa_PushDebugGroup()
[mesa.git] / src / mesa / main / errors.c
index 4e7853b9066209ca3ecf3c53bf16fb340b8c8492..366b119aba348a6a2b225ebaf794172dc0474c50 100644 (file)
@@ -28,6 +28,8 @@
  */
 
 
+#include <stdarg.h>
+#include <stdio.h>
 #include "errors.h"
 #include "enums.h"
 #include "imports.h"
@@ -37,6 +39,7 @@
 #include "mtypes.h"
 #include "version.h"
 #include "util/hash_table.h"
+#include "util/simple_list.h"
 
 static mtx_t DynamicIDMutex = _MTX_INITIALIZER_NP;
 static GLuint NextDynamicID = 1;
@@ -134,9 +137,9 @@ static const GLenum debug_severity_enums[] = {
 static enum mesa_debug_source
 gl_enum_to_debug_source(GLenum e)
 {
-   int i;
+   unsigned i;
 
-   for (i = 0; i < Elements(debug_source_enums); i++) {
+   for (i = 0; i < ARRAY_SIZE(debug_source_enums); i++) {
       if (debug_source_enums[i] == e)
          break;
    }
@@ -146,9 +149,9 @@ gl_enum_to_debug_source(GLenum e)
 static enum mesa_debug_type
 gl_enum_to_debug_type(GLenum e)
 {
-   int i;
+   unsigned i;
 
-   for (i = 0; i < Elements(debug_type_enums); i++) {
+   for (i = 0; i < ARRAY_SIZE(debug_type_enums); i++) {
       if (debug_type_enums[i] == e)
          break;
    }
@@ -158,9 +161,9 @@ gl_enum_to_debug_type(GLenum e)
 static enum mesa_debug_severity
 gl_enum_to_debug_severity(GLenum e)
 {
-   int i;
+   unsigned i;
 
-   for (i = 0; i < Elements(debug_severity_enums); i++) {
+   for (i = 0; i < ARRAY_SIZE(debug_severity_enums); i++) {
       if (debug_severity_enums[i] == e)
          break;
    }
@@ -633,7 +636,7 @@ debug_fetch_message(const struct gl_debug_state *debug)
  * Delete the oldest debug messages out of the log.
  */
 static void
-debug_delete_messages(struct gl_debug_state *debug, unsigned count)
+debug_delete_messages(struct gl_debug_state *debug, int count)
 {
    struct gl_debug_log *log = &debug->Log;
 
@@ -975,9 +978,13 @@ _mesa_DebugMessageInsert(GLenum source, GLenum type, GLuint id,
                          GLenum severity, GLint length,
                          const GLchar *buf)
 {
-   const char *callerstr = "glDebugMessageInsert";
-
    GET_CURRENT_CONTEXT(ctx);
+   const char *callerstr;
+
+   if (_mesa_is_desktop_gl(ctx))
+      callerstr = "glDebugMessageInsert";
+   else
+      callerstr = "glDebugMessageInsertKHR";
 
    if (!validate_params(ctx, INSERT, callerstr, source, type, severity))
       return; /* GL_INVALID_ENUM */
@@ -1001,15 +1008,21 @@ _mesa_GetDebugMessageLog(GLuint count, GLsizei logSize, GLenum *sources,
 {
    GET_CURRENT_CONTEXT(ctx);
    struct gl_debug_state *debug;
+   const char *callerstr;
    GLuint ret;
 
+   if (_mesa_is_desktop_gl(ctx))
+      callerstr = "glGetDebugMessageLog";
+   else
+      callerstr = "glGetDebugMessageLogKHR";
+
    if (!messageLog)
       logSize = 0;
 
    if (logSize < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE,
-                  "glGetDebugMessageLog(logSize=%d : logSize must not be"
-                  " negative)", logSize);
+                  "%s(logSize=%d : logSize must not be negative)",
+                  callerstr, logSize);
       return 0;
    }
 
@@ -1063,9 +1076,14 @@ _mesa_DebugMessageControl(GLenum gl_source, GLenum gl_type,
    enum mesa_debug_source source = gl_enum_to_debug_source(gl_source);
    enum mesa_debug_type type = gl_enum_to_debug_type(gl_type);
    enum mesa_debug_severity severity = gl_enum_to_debug_severity(gl_severity);
-   const char *callerstr = "glDebugMessageControl";
+   const char *callerstr;
    struct gl_debug_state *debug;
 
+   if (_mesa_is_desktop_gl(ctx))
+      callerstr = "glDebugMessageControl";
+   else
+      callerstr = "glDebugMessageControlKHR";
+
    if (count < 0) {
       _mesa_error(ctx, GL_INVALID_VALUE,
                   "%s(count=%d : count must not be negative)", callerstr,
@@ -1121,10 +1139,15 @@ _mesa_PushDebugGroup(GLenum source, GLuint id, GLsizei length,
                      const GLchar *message)
 {
    GET_CURRENT_CONTEXT(ctx);
-   const char *callerstr = "glPushDebugGroup";
+   const char *callerstr;
    struct gl_debug_state *debug;
    struct gl_debug_message *emptySlot;
 
+   if (_mesa_is_desktop_gl(ctx))
+      callerstr = "glPushDebugGroup";
+   else
+      callerstr = "glPushDebugGroupKHR";
+
    switch(source) {
    case GL_DEBUG_SOURCE_APPLICATION:
    case GL_DEBUG_SOURCE_THIRD_PARTY:
@@ -1173,10 +1196,15 @@ void GLAPIENTRY
 _mesa_PopDebugGroup(void)
 {
    GET_CURRENT_CONTEXT(ctx);
-   const char *callerstr = "glPopDebugGroup";
+   const char *callerstr;
    struct gl_debug_state *debug;
    struct gl_debug_message *gdmessage, msg;
 
+   if (_mesa_is_desktop_gl(ctx))
+      callerstr = "glPopDebugGroup";
+   else
+      callerstr = "glPopDebugGroupKHR";
+
    debug = _mesa_lock_debug_state(ctx);
    if (!debug)
       return;
@@ -1230,12 +1258,14 @@ _mesa_free_errors_data(struct gl_context *ctx)
 /** \name Diagnostics */
 /*@{*/
 
+static FILE *LogFile = NULL;
+
+
 static void
 output_if_debug(const char *prefixString, const char *outputString,
                 GLboolean newline)
 {
    static int debug = -1;
-   static FILE *fout = NULL;
 
    /* Init the local 'debug' var once.
     * Note: the _mesa_init_debug() function should have been called
@@ -1247,9 +1277,9 @@ output_if_debug(const char *prefixString, const char *outputString,
        */
       const char *logFile = getenv("MESA_LOG_FILE");
       if (logFile)
-         fout = fopen(logFile, "w");
-      if (!fout)
-         fout = stderr;
+         LogFile = fopen(logFile, "w");
+      if (!LogFile)
+         LogFile = stderr;
 #ifdef DEBUG
       /* in debug builds, print messages unless MESA_DEBUG="silent" */
       if (MESA_DEBUG_FLAGS & DEBUG_SILENT)
@@ -1264,10 +1294,13 @@ output_if_debug(const char *prefixString, const char *outputString,
 
    /* Now only print the string if we're required to do so. */
    if (debug) {
-      fprintf(fout, "%s: %s", prefixString, outputString);
+      if (prefixString)
+         fprintf(LogFile, "%s: %s", prefixString, outputString);
+      else
+         fprintf(LogFile, "%s", outputString);
       if (newline)
-         fprintf(fout, "\n");
-      fflush(fout);
+         fprintf(LogFile, "\n");
+      fflush(LogFile);
 
 #if defined(_WIN32)
       /* stderr from windows applications without console is not usually 
@@ -1282,6 +1315,18 @@ output_if_debug(const char *prefixString, const char *outputString,
 }
 
 
+/**
+ * Return the file handle to use for debug/logging.  Defaults to stderr
+ * unless MESA_LOG_FILE is defined.
+ */
+FILE *
+_mesa_get_log_file(void)
+{
+   assert(LogFile);
+   return LogFile;
+}
+
+
 /**
  * When a new type of error is recorded, print a message describing
  * previous errors which were accumulated.
@@ -1294,7 +1339,7 @@ flush_delayed_errors( struct gl_context *ctx )
    if (ctx->ErrorDebugCount) {
       _mesa_snprintf(s, MAX_DEBUG_MESSAGE_LENGTH, "%d similar %s errors", 
                      ctx->ErrorDebugCount,
-                     _mesa_lookup_enum_by_nr(ctx->ErrorValue));
+                     _mesa_enum_to_string(ctx->ErrorValue));
 
       output_if_debug("Mesa", s, GL_TRUE);
 
@@ -1392,6 +1437,26 @@ should_output(struct gl_context *ctx, GLenum error, const char *fmtString)
 }
 
 
+void
+_mesa_gl_vdebug(struct gl_context *ctx,
+                GLuint *id,
+                enum mesa_debug_source source,
+                enum mesa_debug_type type,
+                enum mesa_debug_severity severity,
+                const char *fmtString,
+                va_list args)
+{
+   char s[MAX_DEBUG_MESSAGE_LENGTH];
+   int len;
+
+   debug_get_id(id);
+
+   len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
+
+   log_msg(ctx, source, type, *id, severity, len, s);
+}
+
+
 void
 _mesa_gl_debug(struct gl_context *ctx,
                GLuint *id,
@@ -1400,17 +1465,10 @@ _mesa_gl_debug(struct gl_context *ctx,
                enum mesa_debug_severity severity,
                const char *fmtString, ...)
 {
-   char s[MAX_DEBUG_MESSAGE_LENGTH];
-   int len;
    va_list args;
-
-   debug_get_id(id);
-
    va_start(args, fmtString);
-   len = _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
+   _mesa_gl_vdebug(ctx, id, source, type, severity, fmtString, args);
    va_end(args);
-
-   log_msg(ctx, source, type, *id, severity, len, s);
 }
 
 
@@ -1465,15 +1523,15 @@ _mesa_error( struct gl_context *ctx, GLenum error, const char *fmtString, ... )
          /* Too long error message. Whoever calls _mesa_error should use
           * shorter strings.
           */
-         ASSERT(0);
+         assert(0);
          return;
       }
 
       len = _mesa_snprintf(s2, MAX_DEBUG_MESSAGE_LENGTH, "%s in %s",
-                           _mesa_lookup_enum_by_nr(error), s);
+                           _mesa_enum_to_string(error), s);
       if (len >= MAX_DEBUG_MESSAGE_LENGTH) {
          /* Same as above. */
-         ASSERT(0);
+         assert(0);
          return;
       }
 
@@ -1523,6 +1581,18 @@ _mesa_debug( const struct gl_context *ctx, const char *fmtString, ... )
 }
 
 
+void
+_mesa_log(const char *fmtString, ...)
+{
+   char s[MAX_DEBUG_MESSAGE_LENGTH];
+   va_list args;
+   va_start(args, fmtString);
+   _mesa_vsnprintf(s, MAX_DEBUG_MESSAGE_LENGTH, fmtString, args);
+   va_end(args);
+   output_if_debug("", s, GL_FALSE);
+}
+
+
 /**
  * Report debug information from the shader compiler via GL_ARB_debug_output.
  *