X-Git-Url: https://git.cworth.org/git?p=fips;a=blobdiff_plain;f=glwrap.h;h=6acf3fcdb98cc00c86f690d217a070ddc1d0a96e;hp=81e1e34c9f0ccc11980de3e70caf42366dd501c2;hb=79edc7574c353a7ae8d2455ecc3a94aa956b3c8e;hpb=b8b9a79e315bf3a030c3b0840ad1490746b5a8e0 diff --git a/glwrap.h b/glwrap.h index 81e1e34..6acf3fc 100644 --- a/glwrap.h +++ b/glwrap.h @@ -22,10 +22,31 @@ #ifndef GLWRAP_H #define GLWRAP_H -/* Should be called at the end of ever function wrapper for an OpenGL - * function that ends a frame, (glXSwapBuffers and similar). - */ +/* Lookup a function named 'name' in the underlying, real, libGL.so */ +void * +glwrap_lookup (char *name); + +/* Register a dlopened handle to be used by glwrap. */ void -glwrap_end_frame (void); +glwrap_set_gl_handle (void *handle); + +/* 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); + +/* As GLWRAP_DEFER, but also set 'ret' to the return value */ +#define GLWRAP_DEFER_WITH_RETURN(ret, function,...) do { \ + static typeof(&function) real_ ## function; \ + if (! real_ ## function) \ + real_ ## function = glwrap_lookup (#function); \ + (ret) = real_ ## function(__VA_ARGS__); \ +} while (0); #endif