Make libdisable-npots a bit more portable
authorNeil Roberts <neil@linux.intel.com>
Mon, 5 Jan 2009 17:05:30 +0000 (17:05 +0000)
committerNeil Roberts <neil@linux.intel.com>
Mon, 5 Jan 2009 17:11:44 +0000 (17:11 +0000)
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
tests/tools/disable-npots.c

index af5efce..43fd46c 100644 (file)
@@ -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 :
index baa1f57..2a942d2 100644 (file)
@@ -4,13 +4,22 @@
  * overrides glGetString and removes the extension strings.
  */
 
-#include <GL/gl.h>
+/* This is just included to get the right GL header */
+#include <cogl/cogl.h>
+
 #include <dlfcn.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
 #include <ctype.h>
 
+/* 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);