return counter->id;
}
-static void *
-lookup (const char *name)
+void *
+glwrap_lookup (char *name)
{
const char *libgl_filename = "libGL.so.1";
static void *libgl_handle = NULL;
return dlwrap_real_dlsym (libgl_handle, name);
}
-/* Defer to the underlying, ''real'' function to do the real work. */
-#define DEFER(function,...) do { \
- static typeof(&function) real_ ## function; \
- if (! real_ ## function) \
- real_ ## function = lookup (#function); \
- real_ ## function(__VA_ARGS__); \
-} while (0);
-
/* Execute a glBegineQuery/glEndQuery pair around an OpenGL call. */
#define TIMED_DEFER(function,...) do { \
unsigned counter; \
counter = add_counter (); \
glBeginQuery (GL_TIME_ELAPSED, counter); \
- DEFER(function, __VA_ARGS__); \
+ GLWRAP_DEFER(function, __VA_ARGS__); \
glEndQuery (GL_TIME_ELAPSED); \
} while (0);
{
current_context.program = program;
- DEFER(glUseProgram, program);
+ GLWRAP_DEFER(glUseProgram, program);
}
void
{
current_context.program = programObj;
- DEFER(glUseProgramObjectARB, programObj);
+ GLWRAP_DEFER(glUseProgramObjectARB, programObj);
}
static void
#ifndef GLWRAP_H
#define GLWRAP_H
+/* Lookup a function named 'name' in the underlying, real, libGL.so */
+void *
+glwrap_lookup (char *name);
+
+/* Defer to the real 'function' (from libGL.so) to do the real work.
+ * The symbol is looked up once and cached in a static variable for
+ * future uses.
+ */
+#define GLWRAP_DEFER(function,...) do { \
+ static typeof(&function) real_ ## function; \
+ if (! real_ ## function) \
+ real_ ## function = glwrap_lookup (#function); \
+ real_ ## function(__VA_ARGS__); \
+} while (0);
+
/* Should be called at the end of ever function wrapper for an OpenGL
* function that ends a frame, (glXSwapBuffers and similar).
*/
#include "glwrap.h"
-typedef void (* fips_glXSwapBuffers_t)(Display *dpy, GLXDrawable drawable);
-
-static void *
-lookup (const char *name)
-{
- const char *libgl_filename = "libGL.so.1";
- static void *libgl_handle = NULL;
-
- if (! libgl_handle) {
- libgl_handle = dlwrap_real_dlopen (libgl_filename, RTLD_NOW | RTLD_DEEPBIND);
- if (! libgl_handle) {
- fprintf (stderr, "Error: Failed to dlopen %s\n",
- libgl_filename);
- exit (1);
- }
- }
-
- return dlwrap_real_dlsym (libgl_handle, name);
-}
-
-static void
-call_glXSwapBuffers (Display *dpy, GLXDrawable drawable)
-{
- static fips_glXSwapBuffers_t real_glXSwapBuffers = NULL;
- const char *name = "glXSwapBuffers";
-
- if (! real_glXSwapBuffers) {
- real_glXSwapBuffers = (fips_glXSwapBuffers_t) lookup (name);
- if (! real_glXSwapBuffers) {
- fprintf (stderr, "Error: Failed to find function %s.\n",
- name);
- return;
- }
- }
- real_glXSwapBuffers (dpy, drawable);
-}
-
void
glXSwapBuffers (Display *dpy, GLXDrawable drawable)
{
- call_glXSwapBuffers (dpy, drawable);
+ GLWRAP_DEFER (glXSwapBuffers, dpy, drawable);
glwrap_end_frame ();
}
{
__GLXextFuncPtr ptr;
static fips_glXGetProcAddressARB_t real_glXGetProcAddressARB = NULL;
- const char *name = "glXGetProcAddressARB";
+ char *name = "glXGetProcAddressARB";
if (! real_glXGetProcAddressARB) {
- real_glXGetProcAddressARB = (fips_glXGetProcAddressARB_t) lookup (name);
+ real_glXGetProcAddressARB = glwrap_lookup (name);
if (! real_glXGetProcAddressARB) {
fprintf (stderr, "Error: Failed to find function %s.\n",
name);