From 3115a6168836ff65ce58c31458d7672400458d74 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 18 May 2009 19:38:03 +0100 Subject: [PATCH] [cogl] Rework the GL-error-to-string conversion The code for the conversion of the GL error enumeration code into a string is not following the code style and conventions we follow in Clutter and COGL. The GE() macro is also using fprintf(stderr) directly instead of using g_warning() -- which is redirectable to an alternative logging system using the g_log* API. --- clutter/cogl/common/cogl-internal.h | 20 +++++------ clutter/cogl/common/cogl.c | 52 +++++++++++++++-------------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/clutter/cogl/common/cogl-internal.h b/clutter/cogl/common/cogl-internal.h index 595242168..6e7867e81 100644 --- a/clutter/cogl/common/cogl-internal.h +++ b/clutter/cogl/common/cogl-internal.h @@ -55,17 +55,17 @@ typedef struct _CoglBoxedValue #include -const char *_cogl_error_string(GLenum errorCode); +const gchar *cogl_gl_error_to_string (GLenum error_code); -#define GE(x...) G_STMT_START { \ - GLenum err; \ - (x); \ - while ((err = glGetError()) != GL_NO_ERROR) { \ - fprintf(stderr, "glError: %s caught at %s:%u\n", \ - (char *)_cogl_error_string(err), \ - __FILE__, __LINE__); \ - } \ -} G_STMT_END +#define GE(x...) G_STMT_START { \ + GLenum __err; \ + (x); \ + while ((err = glGetError ()) != GL_NO_ERROR) \ + { \ + g_warning ("%s: GL error (%d): %s\n", \ + G_STRLOC, \ + cogl_gl_error_to_string (err));\ + } } G_STMT_END #else /* COGL_DEBUG */ diff --git a/clutter/cogl/common/cogl.c b/clutter/cogl/common/cogl.c index e6341a8ac..f002231d7 100644 --- a/clutter/cogl/common/cogl.c +++ b/clutter/cogl/common/cogl.c @@ -46,39 +46,41 @@ typedef CoglFuncPtr (*GLXGetProcAddressProc) (const guint8 *procName); #include "cogl-gles2-wrapper.h" #endif +#ifdef COGL_DEBUG /* GL error to string conversion */ -#if COGL_DEBUG -struct token_string -{ - GLuint Token; - const char *String; -}; +static const struct { + GLuint error_code; + const gchar *error_string; +} gl_errors[] = { + { GL_NO_ERROR, "No error" }, + { GL_INVALID_ENUM, "Invalid enumeration value" }, + { GL_INVALID_VALUE, "Invalid value" }, + { GL_INVALID_OPERATION, "Invalid operation" }, + { GL_STACK_OVERFLOW, "Stack overflow" }, + { GL_STACK_UNDERFLOW, "Stack underflow" }, + { GL_OUT_OF_MEMORY, "Out of memory" }, -static const struct token_string Errors[] = { - { GL_NO_ERROR, "no error" }, - { GL_INVALID_ENUM, "invalid enumerant" }, - { GL_INVALID_VALUE, "invalid value" }, - { GL_INVALID_OPERATION, "invalid operation" }, - { GL_STACK_OVERFLOW, "stack overflow" }, - { GL_STACK_UNDERFLOW, "stack underflow" }, - { GL_OUT_OF_MEMORY, "out of memory" }, #ifdef GL_INVALID_FRAMEBUFFER_OPERATION_EXT - { GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "invalid framebuffer operation" }, + { GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "Invalid framebuffer operation" } #endif - { ~0, NULL } }; -const char* -_cogl_error_string(GLenum errorCode) +static const guint n_gl_errors = G_N_ELEMENTS (gl_errors); + +const gchar * +cogl_gl_error_to_string (GLenum error_code) { - int i; - for (i = 0; Errors[i].String; i++) { - if (Errors[i].Token == errorCode) - return Errors[i].String; - } - return "unknown"; + gint i; + + for (i = 0; i < n_gl_errors; i++) + { + if (gl_errors[i].error_code == error_code) + return gl_errors[i].error_string; + } + + return "Unknown error"; } -#endif +#endif /* COGL_DEBUG */ void cogl_clear (const CoglColor *color, gulong buffers)