X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=glaze-gl.c;fp=glaze-gl.c;h=7248876b75da4940ee83e71430b9647f41ef801d;hb=6cfcdb728c0a088cc12bb3eb93d78b2a9915969b;hp=453d4606f2be1320b009630bf1e041960b190afc;hpb=e67ec0f4f055ad6b41fb17024cb4496b66054ada;p=glaze diff --git a/glaze-gl.c b/glaze-gl.c index 453d460..7248876 100644 --- a/glaze-gl.c +++ b/glaze-gl.c @@ -31,6 +31,8 @@ void *libgl_handle; void *wrapper_handle; +#define STRNCMP_LITERAL(str, literal) strncmp (str, literal, sizeof (literal) - 1) + static void open_libgl_handle (void) { @@ -104,8 +106,29 @@ glaze_init (void) static void * resolve (const char *name) { + static int before_first_gl_call = 1; void *symbol; + if (before_first_gl_call && + STRNCMP_LITERAL (name, "gl") == 0 && + STRNCMP_LITERAL (name, "glX") != 0) + { + char *callback_name = getenv ("GLAZE_FIRST_GL_CALL_CALLBACK"); + if (callback_name) { + void (*callback) (void) = dlsym (wrapper_handle, + callback_name); + if (callback) { + (callback) (); + } else { + fprintf (stderr, + "Error: Failed to find function %s " + "in GLAZE_WRAPPER library.\n", + callback_name); + } + } + before_first_gl_call = 0; + } + /* The wrapper gets first choice on all symbols. */ symbol = dlsym (wrapper_handle, name); if (symbol)