]> git.tdb.fi Git - gldbg.git/blobdiff - source/gldecoder.c
Check for and report OpenGL errors after each function call
[gldbg.git] / source / gldecoder.c
index e11d13c46d51ef0a064415eecf7933b7cb0e6b10..6e903736f726a5840c9252056858c52b910d0592 100644 (file)
@@ -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(len<sizeof(int)+sizeof(short))
@@ -48,7 +49,10 @@ int gldecoder_decode(GlDecoder *dec, const char *data, unsigned len)
        pos += read_short(&func, data+pos);
        if(dec)
        {
-               ret = decode_func(dec, func, data+pos);
+               if(func&0x8000)
+                       ret = decode_gldfunc(dec, func, data+pos);
+               else
+                       ret = decode_func(dec, func, data+pos);
                if(ret<0)
                        return -1;
        }
@@ -127,3 +131,22 @@ static unsigned read_string(const unsigned char **v, const char *data)
 }
 
 #include "gldecoder.funcs"
+
+static int decode_gldError(GlDecoder *dec, const char *data)
+{
+       unsigned pos = 0;
+       GLenum code;
+       pos += read_int(&code, data);
+       if(dec->gldError)
+               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;
+       }
+}