From 64b727d329c72fdf88c4430500638e480a5deeee 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. --- common/cogl-internal.h | 20 ++++++++-------- common/cogl.c | 52 ++++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/common/cogl-internal.h b/common/cogl-internal.h index 595242168..6e7867e81 100644 --- a/common/cogl-internal.h +++ b/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/common/cogl.c b/common/cogl.c index e6341a8ac..f002231d7 100644 --- a/common/cogl.c +++ b/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)