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).
This commit is contained in:
parent
ff73fe3e1f
commit
e5543a658f
@ -10,6 +10,12 @@ libdisable_npots_la_SOURCES = disable-npots.c
|
|||||||
|
|
||||||
libdisable_npots_la_LIBADD = -ldl
|
libdisable_npots_la_LIBADD = -ldl
|
||||||
|
|
||||||
|
INCLUDES = \
|
||||||
|
-I$(top_srcdir)/clutter \
|
||||||
|
-I$(top_builddir)/clutter \
|
||||||
|
$(CLUTTER_CFLAGS) \
|
||||||
|
-D_GNU_SOURCE
|
||||||
|
|
||||||
all-local : disable-npots.sh
|
all-local : disable-npots.sh
|
||||||
|
|
||||||
clean-local :
|
clean-local :
|
||||||
|
@ -4,13 +4,22 @@
|
|||||||
* overrides glGetString and removes the extension strings.
|
* 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 <dlfcn.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <ctype.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);
|
typedef const GLubyte * (* GetStringFunc) (GLenum name);
|
||||||
|
|
||||||
static const char * const bad_strings[]
|
static const char * const bad_strings[]
|
||||||
@ -23,16 +32,14 @@ const GLubyte *
|
|||||||
glGetString (GLenum name)
|
glGetString (GLenum name)
|
||||||
{
|
{
|
||||||
const GLubyte *ret = NULL;
|
const GLubyte *ret = NULL;
|
||||||
static void *gl_lib = NULL;
|
|
||||||
static GetStringFunc func = NULL;
|
static GetStringFunc func = NULL;
|
||||||
static GLubyte *extensions = NULL;
|
static GLubyte *extensions = NULL;
|
||||||
|
|
||||||
if (gl_lib == NULL
|
if (func == NULL
|
||||||
&& (gl_lib = dlopen ("libGL.so", RTLD_LAZY)) == NULL)
|
&& (func = (GetStringFunc) dlsym (LIB_HANDLE, "glGetString")) == NULL)
|
||||||
fprintf (stderr, "dlopen: %s\n", dlerror ());
|
|
||||||
else if (func == NULL
|
|
||||||
&& (func = (GetStringFunc) dlsym (gl_lib, "glGetString")) == NULL)
|
|
||||||
fprintf (stderr, "dlsym: %s\n", dlerror ());
|
fprintf (stderr, "dlsym: %s\n", dlerror ());
|
||||||
|
else if (func == glGetString)
|
||||||
|
fprintf (stderr, "dlsym returned the wrapper of glGetString\n");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ret = (* func) (name);
|
ret = (* func) (name);
|
||||||
|
Loading…
Reference in New Issue
Block a user