From e5543a658f74bcc6efb477d34953e5f2bf08d930 Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Mon, 5 Jan 2009 17:05:30 +0000 Subject: [PATCH] Make libdisable-npots a bit more portable Instead of including GL/gl.h directly it now includes cogl/cogl.h instead which should include the right GL header. Instead of using dlopen to specifically open libGL it now tries to use dlsym with RTLD_NEXT. This requires defining _GNU_SOURCE on GNU systems. If RTLD_NEXT is not available it will try passing NULL which is unlikely to work but it will at least catch the case where it returns the wrapper version of glGetString to prevent infinite recursion. This should hopefully make it work on OS X where the name of the header and library are different (although this is currently untested). --- tests/tools/Makefile.am | 6 ++++++ tests/tools/disable-npots.c | 21 ++++++++++++++------- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am index af5efce4d..43fd46ca6 100644 --- a/tests/tools/Makefile.am +++ b/tests/tools/Makefile.am @@ -10,6 +10,12 @@ libdisable_npots_la_SOURCES = disable-npots.c libdisable_npots_la_LIBADD = -ldl +INCLUDES = \ + -I$(top_srcdir)/clutter \ + -I$(top_builddir)/clutter \ + $(CLUTTER_CFLAGS) \ + -D_GNU_SOURCE + all-local : disable-npots.sh clean-local : diff --git a/tests/tools/disable-npots.c b/tests/tools/disable-npots.c index baa1f5778..2a942d2af 100644 --- a/tests/tools/disable-npots.c +++ b/tests/tools/disable-npots.c @@ -4,13 +4,22 @@ * overrides glGetString and removes the extension strings. */ -#include +/* This is just included to get the right GL header */ +#include + #include #include #include #include #include +/* If RTLD_NEXT isn't available then try just using NULL */ +#ifdef RTLD_NEXT +#define LIB_HANDLE RTLD_NEXT +#else +#define LIB_HANDLE NULL +#endif + typedef const GLubyte * (* GetStringFunc) (GLenum name); static const char * const bad_strings[] @@ -23,16 +32,14 @@ const GLubyte * glGetString (GLenum name) { const GLubyte *ret = NULL; - static void *gl_lib = NULL; static GetStringFunc func = NULL; static GLubyte *extensions = NULL; - if (gl_lib == NULL - && (gl_lib = dlopen ("libGL.so", RTLD_LAZY)) == NULL) - fprintf (stderr, "dlopen: %s\n", dlerror ()); - else if (func == NULL - && (func = (GetStringFunc) dlsym (gl_lib, "glGetString")) == NULL) + if (func == NULL + && (func = (GetStringFunc) dlsym (LIB_HANDLE, "glGetString")) == NULL) fprintf (stderr, "dlsym: %s\n", dlerror ()); + else if (func == glGetString) + fprintf (stderr, "dlsym returned the wrapper of glGetString\n"); else { ret = (* func) (name);