* THE SOFTWARE.
*/
-#include <stdio.h>
-#include <stdlib.h>
-
-#include <dlfcn.h>
+#include "fips.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 *libgl_handle = NULL;
if (! libgl_handle) {
- libgl_handle = dlopen (libgl_filename, RTLD_NOW);
+ libgl_handle = dlwrap_real_dlopen (libgl_filename, RTLD_NOW | RTLD_DEEPBIND);
if (! libgl_handle) {
fprintf (stderr, "Error: Failed to dlopen %s\n",
libgl_filename);
}
}
- return dlsym (libgl_handle, name);
+ return dlwrap_real_dlsym (libgl_handle, name);
}
static void
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);
+ glwrap_end_frame ();
+}
+
- fps = (double) frames / (tv_now.tv_sec - tv_start.tv_sec +
- (tv_now.tv_usec - tv_start.tv_usec) / 1.0e6);
+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";
- printf("FPS: %.3f\n", fps);
+ if (! real_glXGetProcAddressARB) {
+ real_glXGetProcAddressARB = (fips_glXGetProcAddressARB_t) lookup (name);
+ if (! real_glXGetProcAddressARB) {
+ fprintf (stderr, "Error: Failed to find function %s.\n",
+ name);
+ return NULL;
+ }
}
+
+ /* 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);
}