1
0
Fork 0

[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.
This commit is contained in:
Emmanuele Bassi 2009-05-18 19:38:03 +01:00
parent e725bd21bf
commit 3115a61688
2 changed files with 37 additions and 35 deletions

View file

@ -55,17 +55,17 @@ typedef struct _CoglBoxedValue
#include <stdio.h> #include <stdio.h>
const char *_cogl_error_string(GLenum errorCode); const gchar *cogl_gl_error_to_string (GLenum error_code);
#define GE(x...) G_STMT_START { \ #define GE(x...) G_STMT_START { \
GLenum err; \ GLenum __err; \
(x); \ (x); \
while ((err = glGetError()) != GL_NO_ERROR) { \ while ((err = glGetError ()) != GL_NO_ERROR) \
fprintf(stderr, "glError: %s caught at %s:%u\n", \ { \
(char *)_cogl_error_string(err), \ g_warning ("%s: GL error (%d): %s\n", \
__FILE__, __LINE__); \ G_STRLOC, \
} \ cogl_gl_error_to_string (err));\
} G_STMT_END } } G_STMT_END
#else /* COGL_DEBUG */ #else /* COGL_DEBUG */

View file

@ -46,39 +46,41 @@ typedef CoglFuncPtr (*GLXGetProcAddressProc) (const guint8 *procName);
#include "cogl-gles2-wrapper.h" #include "cogl-gles2-wrapper.h"
#endif #endif
#ifdef COGL_DEBUG
/* GL error to string conversion */ /* GL error to string conversion */
#if COGL_DEBUG static const struct {
struct token_string GLuint error_code;
{ const gchar *error_string;
GLuint Token; } gl_errors[] = {
const char *String; { 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 #ifdef GL_INVALID_FRAMEBUFFER_OPERATION_EXT
{ GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "invalid framebuffer operation" }, { GL_INVALID_FRAMEBUFFER_OPERATION_EXT, "Invalid framebuffer operation" }
#endif #endif
{ ~0, NULL }
}; };
const char* static const guint n_gl_errors = G_N_ELEMENTS (gl_errors);
_cogl_error_string(GLenum errorCode)
const gchar *
cogl_gl_error_to_string (GLenum error_code)
{ {
int i; gint i;
for (i = 0; Errors[i].String; i++) {
if (Errors[i].Token == errorCode) for (i = 0; i < n_gl_errors; i++)
return Errors[i].String; {
} if (gl_errors[i].error_code == error_code)
return "unknown"; return gl_errors[i].error_string;
}
return "Unknown error";
} }
#endif #endif /* COGL_DEBUG */
void void
cogl_clear (const CoglColor *color, gulong buffers) cogl_clear (const CoglColor *color, gulong buffers)