]> git.cworth.org Git - fips/blobdiff - glxwrap.c
Wrap all OpenGL drawing calls, measure GPU time of each, and account to shader.
[fips] / glxwrap.c
index e4252d3942405d1209a6a529956d88092dfc44f9..78627d42005a223eca6128dd12177d06e8278257 100644 (file)
--- a/glxwrap.c
+++ b/glxwrap.c
 
 #include "fips.h"
 
-#include <dlfcn.h>
-
 #include <X11/Xlib.h>
 #include <GL/gl.h>
 #include <GL/glx.h>
-#include <GL/glext.h>
-
-#include <sys/time.h>
 
 #include "dlwrap.h"
 
+#include "glwrap.h"
+
 typedef void (* fips_glXSwapBuffers_t)(Display *dpy, GLXDrawable drawable);
 
 static void *
@@ -72,28 +69,9 @@ call_glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 void
 glXSwapBuffers (Display *dpy, GLXDrawable drawable)
 {
-       static int initialized = 0;
-       static int frames;
-       static struct timeval tv_start, tv_now;
-
-       if (! initialized) {
-               frames = 0;
-               gettimeofday (&tv_start, NULL);
-               initialized = 1;
-       }
-
        call_glXSwapBuffers (dpy, drawable);
 
-       frames++;
-       if (frames % 60 == 0) {
-               double fps;
-               gettimeofday (&tv_now, NULL);
-
-               fps = (double) frames / (tv_now.tv_sec - tv_start.tv_sec +
-                                        (tv_now.tv_usec - tv_start.tv_usec) / 1.0e6);
-
-               printf("FPS: %.3f\n", fps);
-       }
+       glwrap_end_frame ();
 }
 
 
@@ -101,6 +79,7 @@ typedef __GLXextFuncPtr (* fips_glXGetProcAddressARB_t)(const GLubyte *func);
 __GLXextFuncPtr
 glXGetProcAddressARB (const GLubyte *func)
 {
+       __GLXextFuncPtr ptr;
        static fips_glXGetProcAddressARB_t real_glXGetProcAddressARB = NULL;
        const char *name = "glXGetProcAddressARB";
 
@@ -113,8 +92,11 @@ glXGetProcAddressARB (const GLubyte *func)
                }
        }
 
-       if (strcmp ((const char *)func, "glXSwapBuffers") == 0)
-               return (__GLXextFuncPtr) glXSwapBuffers;
-       else
-               return real_glXGetProcAddressARB (func);
+       /* If our library has this symbol, that's what we want to give. */
+       ptr = dlwrap_real_dlsym (NULL, (const char *) func);
+       if (ptr)
+               return ptr;
+
+       /* Otherwise, just defer to the real glXGetProcAddressARB. */
+       return real_glXGetProcAddressARB (func);
 }