]> git.tdb.fi Git - gldbg.git/blobdiff - source/glwrap.c
Check for and report OpenGL errors after each function call
[gldbg.git] / source / glwrap.c
index 59bf1fb12cedc3333a77abf1e1a044edf26edc22..0a22c3c1ce4b6677c0bb66cdb10d559294fbe160 100644 (file)
@@ -10,7 +10,9 @@ Distributed under the GPL
 #include <string.h>
 #include <dlfcn.h>
 #include <sys/uio.h>
+#include <X11/Xlib.h>
 #include <GL/gl.h>
+#include <GL/glx.h>
 #include "functions.h"
 
 static inline void *glsym(const char *sym)
@@ -237,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);