From: Mikko Rasa Date: Tue, 27 Oct 2009 07:56:39 +0000 (+0000) Subject: Check for and report OpenGL errors after each function call X-Git-Url: http://git.tdb.fi/?p=gldbg.git;a=commitdiff_plain;h=6475e8951e1901b247f5d1d1dd9fcfc1e77e163a Check for and report OpenGL errors after each function call --- diff --git a/gl.files b/gl.files index 8be2a33..d6631d8 100644 --- a/gl.files +++ b/gl.files @@ -4,3 +4,4 @@ spec gl.spec prefix gl ignore category VERSION_3_2 ignore category ARB_sync +ignore function glGetError diff --git a/source/functions.enum.t b/source/functions.enum.t index fc0987c..ad1bc2d 100644 --- a/source/functions.enum.t +++ b/source/functions.enum.t @@ -3,4 +3,5 @@ :{ : FUNC_NONE, wl(' FUNC_%s,', func.name.upper()) +: FUNC_GLDERROR = 0x8000 :}; diff --git a/source/gldecoder.c b/source/gldecoder.c index e11d13c..6e90373 100644 --- a/source/gldecoder.c +++ b/source/gldecoder.c @@ -12,7 +12,8 @@ Distributed under the GPL static unsigned read_short(short *, const char *); static unsigned read_int(int *, const char *); -static int decode_func(GlDecoder *, short, const char *); +static int decode_func(GlDecoder *, unsigned short, const char *); +static int decode_gldfunc(GlDecoder *, unsigned short, const char *); GlDecoder *gldecoder_new(void *user_data, void (*destroy)(void *)) { @@ -37,7 +38,7 @@ int gldecoder_decode(GlDecoder *dec, const char *data, unsigned len) { unsigned pos = 0; int pktlen; - short func; + unsigned short func; int ret; if(lengldError) + dec->gldError(dec->user_data, code); + return pos; +} + +static int decode_gldfunc(GlDecoder *dec, unsigned short func, const char *data) +{ + switch(func) + { + case FUNC_GLDERROR: return decode_gldError(dec, data); + default: return -1; + } +} diff --git a/source/gldecoder.funcs.t b/source/gldecoder.funcs.t index 8d054b0..af820a4 100644 --- a/source/gldecoder.funcs.t +++ b/source/gldecoder.funcs.t @@ -24,7 +24,7 @@ for p in params: wl(');') wl(' return pos;') wl('}') -:static int decode_func(GlDecoder *dec, short func, const char *data) +:static int decode_func(GlDecoder *dec, unsigned short func, const char *data) :{ : switch(func) : { diff --git a/source/gldecoder.struct.t b/source/gldecoder.struct.t index e05e910..5b46aca 100644 --- a/source/gldecoder.struct.t +++ b/source/gldecoder.struct.t @@ -9,4 +9,5 @@ if ret.ctype!="void": for p in params: w(', %s', p.ctype) wl(');') +: void (*gldError)(void *, GLenum); :} GlDecoder; diff --git a/source/glprint.c b/source/glprint.c index 3c07559..fbf6e0e 100644 --- a/source/glprint.c +++ b/source/glprint.c @@ -18,6 +18,7 @@ typedef struct sGlPrintData static void init_print(GlDecoder *); static void glprint_data_free(void *); +static void print_gldError(void *, GLenum); GlDecoder *glprint_new(char *buffer, unsigned bufsize) { @@ -38,6 +39,7 @@ GlDecoder *glprint_new(char *buffer, unsigned bufsize) dec = gldecoder_new(gpd, free); init_print(dec); + dec->gldError = print_gldError; } char *glprint_get_buffer(GlDecoder *dec) @@ -52,4 +54,10 @@ static void glprint_data_free(void *data) free(gpd); } +static void print_gldError(void *user_data, GLenum code) +{ + GlPrintData *gpd = (GlPrintData *)user_data; + snprintf(gpd->buffer, gpd->bufsize, "ERROR: %s", describe_enum(code, "ErrorCode")); +} + #include "glprint.funcs" diff --git a/source/glwrap.c b/source/glwrap.c index 224a0fa..0a22c3c 100644 --- a/source/glwrap.c +++ b/source/glwrap.c @@ -239,6 +239,32 @@ static inline int mapsize(GLenum target) return 1; } +GLenum cur_error = GL_NO_ERROR; + +static void check_error() +{ + GLenum (*orig_glGetError)() = 0; + GLenum code; + if(!orig_glGetError) + orig_glGetError = glsym("glGetError"); + code = orig_glGetError(); + if(code!=GL_NO_ERROR) + { + begin_packet(FUNC_GLDERROR); + write_int(code); + send_packet(); + if(cur_error==GL_NO_ERROR) + cur_error = code; + } +} + +GLenum APIENTRY glGetError() +{ + GLenum ret = cur_error; + cur_error = GL_NO_ERROR; + return ret; +} + void (*glXGetProcAddress(const GLubyte *procname))(void) { void *handle = dlopen(NULL, RTLD_LAZY); diff --git a/source/glwrap.funcs.t b/source/glwrap.funcs.t index decf22e..a58a1c5 100644 --- a/source/glwrap.funcs.t +++ b/source/glwrap.funcs.t @@ -21,6 +21,8 @@ for p in params: else: wl(' write_pointer(%s);', p.name) wl(' send_packet();') +if not func.name.startswith("glX"): + wl(' check_error();') if ret.ctype!='void': wl(' return ret;') wl('}')