|
View:
New views
2 Messages
—
Rating Filter:
Alert me
|
|
|
Runtime GL library loading patchesAs promised, I said I'd send `a patch' by this weekend [1]. Attached
is a whole set of patches. A quick guide is appended at [2], but they also come with normal commit(-esque?) comments. This work is incomplete, but the patches given seem to leave GLEW on-par with -- and even (very) slightly improved upon -- current functionality. There's an issue that brings to light a more global issue. To get this to work for even a simple `start--establish context--glewInit()--end' program, I had to change glewInit_GLX_VERSION_1_2 such that it conditionally loads GetCurrentDisplay. That is, glXGetCurrentDisplay = ...ProcAddress("glXGetProcAddress")... became: if(glew_convention == GLEW_NAME_CONVENTION_MANGLED_MESA) { glXGetCurrentDisplay = ...ProcAddress("mglXGetProcAddress")... } else { glXGetCurrentDisplay = ...ProcAddress("glXGetProcAddress")... } This and patch 0007 bring to a light the issue: conditionalizing the arguments to glewGetProcAddress (the GL function names). Loading a function `X' must pass the string `mX' in the mangled case. Probably the best solution is to change the generator such that it outputs: ...ProcAddress((glew_convention == ...MESA) ? "mWhatever" : "Whatever"); instead of simply: ...ProcAddress("Whatever"); In the interest of me not having to grok perl code, I propose we simply malloc a new string, start it with the character `m', and then append the argument onto it -- only in the mangled case, of course. It'll probably be damn slow, but that doesn't hurt my use case much. glewInit happens once, rendering happens N times; not a big deal. Otherwise I'll sit down until I grok the code generators; any docs exist for this? -tom [1] http://tinyurl.com/nabble-archive-runtime-GL [2] . 0001-Generate-binaries-from-object-files.patch Unimportant; some makefile changes which I like && have been sitting in my tree `forever'. . 0002-Remove-glew_utils.c.patch Seems to be unused. Confused me, so I killed it. . 0003-Function-prototype-for-new-entry-point.patch Adds the new entry point to the header. Trying to use it after this patch would probably compile, but not link. . 0004-Switch-to-using-a-dynamic-function-loader-on-Linux.patch The `meat'. Adds an internal function which sets a new static variable, __glewXGetProcAddress, to the function loader we want to use. . 0005-cast-to-avoid-warning.patch Changes the glewGetProcAddress macro to to cast its argument. The rest of GLEW seems to cast every time it passes an argument to the macro, which is verbose; I like this better. It doesn't matter too much since all the code I label as `verbose' is autogenerated anyway. . 0006-Add-new-entry-point.patch Adds the new entry point, so that linking will work. . 0007-Use-a-dynamically-loaded-glGetString-on-Linux.patch Call the correct glGetString. From b58caca86d58afa5f539d74d6cfccab3027bde2b Mon Sep 17 00:00:00 2001 From: Tom Fogal <tfogal@...> Date: Mon, 12 Jan 2009 18:38:11 -0700 Subject: [PATCH] Generate binaries from object files. This modifies the targets to build binaries from the object files instead of directly from the source files. --- Makefile | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index d7c71f6..77ab54f 100644 --- a/Makefile +++ b/Makefile @@ -69,10 +69,10 @@ LIB.LIBS = $(GL_LDFLAGS) GLEWINFO.BIN = glewinfo$(BIN.SUFFIX) GLEWINFO.BIN.SRCS = src/glewinfo.c -GLEWINFO.BIN.OBJS = $(GLEWINFO_BIN.SRCS:.c=.o) +GLEWINFO.BIN.OBJS = $(GLEWINFO.BIN.SRCS:.c=.o) VISUALINFO.BIN = visualinfo$(BIN.SUFFIX) VISUALINFO.BIN.SRCS = src/visualinfo.c -VISUALINFO.BIN.OBJS = $(VISUALINFO_BIN.SRCS:.c=.o) +VISUALINFO.BIN.OBJS = $(VISUALINFO.BIN.SRCS:.c=.o) BIN.LIBS = -Llib $(LDFLAGS.DYNAMIC) -l$(NAME) $(LDFLAGS.EXTRA) $(LDFLAGS.GL) all debug: lib/$(LIB.SHARED) lib/$(LIB.STATIC) bin/$(GLEWINFO.BIN) bin/$(VISUALINFO.BIN) @@ -91,11 +91,11 @@ else $(LN) $(LIB.SHARED) lib/$(LIB.DEVLNK) endif -bin/$(GLEWINFO.BIN): $(GLEWINFO.BIN.SRCS) lib/$(LIB.SHARED) - $(CC) $(CFLAGS) -o $@ $(GLEWINFO.BIN.SRCS) $(BIN.LIBS) +bin/$(GLEWINFO.BIN): $(GLEWINFO.BIN.OBJS) lib/$(LIB.SHARED) + $(CC) $(CFLAGS) -o $@ $(GLEWINFO.BIN.OBJS) $(BIN.LIBS) -bin/$(VISUALINFO.BIN): $(VISUALINFO.BIN.SRCS) lib/$(LIB.SHARED) - $(CC) $(CFLAGS) -o $@ $(VISUALINFO.BIN.SRCS) $(BIN.LIBS) +bin/$(VISUALINFO.BIN): $(VISUALINFO.BIN.OBJS) lib/$(LIB.SHARED) + $(CC) $(CFLAGS) -o $@ $(VISUALINFO.BIN.OBJS) $(BIN.LIBS) %.o: %.c $(CC) -c $(CFLAGS) -o $@ $< -- 1.5.6.5 From 970282009c979384c6e03ddec844b4a673a338bc Mon Sep 17 00:00:00 2001 From: Tom Fogal <tfogal@...> Date: Sun, 8 Mar 2009 16:03:22 -0700 Subject: [PATCH] Remove glew_utils.c. Seems to be subsumed by glew_head.c, and it's confusing to keep it around. --- auto/src/glew_utils.c | 162 ------------------------------------------------- 1 files changed, 0 insertions(+), 162 deletions(-) delete mode 100644 auto/src/glew_utils.c diff --git a/auto/src/glew_utils.c b/auto/src/glew_utils.c deleted file mode 100644 index 85fb57f..0000000 --- a/auto/src/glew_utils.c +++ /dev/null @@ -1,162 +0,0 @@ -/* -** The OpenGL Extension Wrangler Library -** Copyright (C) 2002-2008, Milan Ikits <milan ikits[]ieee org> -** Copyright (C) 2002-2008, Marcelo E. Magallon <mmagallo[]debian org> -** Copyright (C) 2002, Lev Povalahev -** All rights reserved. -** -** Redistribution and use in source and binary forms, with or without -** modification, are permitted provided that the following conditions are met: -** -** * Redistributions of source code must retain the above copyright notice, -** this list of conditions and the following disclaimer. -** * Redistributions in binary form must reproduce the above copyright notice, -** this list of conditions and the following disclaimer in the documentation -** and/or other materials provided with the distribution. -** * The name of the author may be used to endorse or promote products -** derived from this software without specific prior written permission. -** -** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE -** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR -** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF -** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS -** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN -** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) -** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF -** THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#include <GL/glew.h> -#if defined(_WIN32) -# include <GL/wglew.h> -#elif !defined(__APPLE__) || defined(GLEW_APPLE_GLX) -# include <GL/glxew.h> -#endif - -#include "glew_utils.h" - -#if defined(__APPLE__) -#include <mach-o/dyld.h> -#include <stdlib.h> -#include <string.h> - -void* NSGLGetProcAddress (const GLubyte *name) -{ - NSSymbol symbol; - char* symbolName; - /* prepend a '_' for the Unix C symbol mangling convention */ - symbolName = malloc(strlen((const char*)name) + 2); - strcpy(symbolName+1, (const char*)name); - symbolName[0] = '_'; - symbol = NULL; - if (NSIsSymbolNameDefined(symbolName)) - symbol = NSLookupAndBindSymbol(symbolName); - free(symbolName); - return symbol ? NSAddressOfSymbol(symbol) : NULL; -} -#endif /* __APPLE__ */ - -#if defined(__sgi) || defined (__sun) -#include <dlfcn.h> -#include <stdio.h> -#include <stdlib.h> - -void* dlGetProcAddress (const GLubyte* name) -{ - static void* h = NULL; - static void* gpa; - - if (h == NULL) - { - if ((h = dlopen(NULL, RTLD_LAZY | RTLD_LOCAL)) == NULL) return NULL; - gpa = dlsym(h, "glXGetProcAddress"); - } - - if (gpa != NULL) - return ((void*(*)(const GLubyte*))gpa)(name); - else - return dlsym(h, (const char*)name); -} -#endif /* __sgi || __sun */ - -/* - * GLEW, just like OpenGL or GLU, does not rely on the standard C library. - * These functions implement the functionality required in this file. - */ - -GLuint _glewStrLen (const GLubyte* s) -{ - GLuint i=0; - while (s+i != NULL && s[i] != '\0') i++; - return i; -} - -GLuint _glewStrCLen (const GLubyte* s, GLubyte c) -{ - GLuint i=0; - while (s+i != NULL && s[i] != '\0' && s[i] != c) i++; - return i; -} - -GLboolean _glewStrSame (const GLubyte* a, const GLubyte* b, GLuint n) -{ - GLuint i=0; - while (i < n && a+i != NULL && b+i != NULL && a[i] == b[i]) i++; - return i == n ? GL_TRUE : GL_FALSE; -} - -GLboolean _glewStrSame1 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb) -{ - while (*na > 0 && (**a == ' ' || **a == '\n' || **a == '\r' || **a == '\t')) - { - *a++; - *na--; - } - if(*na >= nb) - { - GLuint i=0; - while (i < nb && *a+i != NULL && b+i != NULL && *a[i] == b[i]) i++; - if(i == nb) - { - *a = *a + nb; - *na = *na - nb; - return GL_TRUE; - } - } - return GL_FALSE; -} - -GLboolean _glewStrSame2 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb) -{ - if(*na >= nb) - { - GLuint i=0; - while (i < nb && *a+i != NULL && b+i != NULL && *a[i] == b[i]) i++; - if(i == nb) - { - *a = *a + nb; - *na = *na - nb; - return GL_TRUE; - } - } - return GL_FALSE; -} - -GLboolean _glewStrSame3 (GLubyte** a, GLuint* na, const GLubyte* b, GLuint nb) -{ - if(*na >= nb) - { - GLuint i=0; - while (i < nb && *a+i != NULL && b+i != NULL && *a[i] == b[i]) i++; - if (i == nb && (*na == nb || *a[i] == ' ' || *a[i] == '\n' || *a[i] == '\r' || *a[i] == '\t')) - { - *a = *a + nb; - *na = *na - nb; - return GL_TRUE; - } - } - return GL_FALSE; -} -- 1.5.6.5 From 700b15c3faec2e0f138e1a5d17be93acc9f4da5c Mon Sep 17 00:00:00 2001 From: Tom Fogal <tfogal@...> Date: Sun, 8 Mar 2009 15:57:16 -0700 Subject: [PATCH] Function prototype for new entry point. glewInitLibrary allows clients to specify a specific OpenGL library, as well as a naming convention for that library. The current use case is to allow users to specify GLEW should load symbols from a mangled Mesa library, which may be installed parallel to the system GL library. --- auto/src/glew_tail.h | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-) diff --git a/auto/src/glew_tail.h b/auto/src/glew_tail.h index f2f002e..c07e009 100644 --- a/auto/src/glew_tail.h +++ b/auto/src/glew_tail.h @@ -13,6 +13,15 @@ #define GLEW_VERSION_MINOR 3 #define GLEW_VERSION_MICRO 4 +/* + * OpenGL naming convention codes. + * Used to switch between `standard' OpenGL and mangled Mesa implementations. + */ +enum GL_Name_Convention { + GLEW_NAME_CONVENTION_GL = 0, + GLEW_NAME_CONVENTION_MANGLED_MESA +}; + /* API */ #ifdef GLEW_MX @@ -33,6 +42,7 @@ GLEWAPI GLboolean glewContextIsSupported (GLEWContext* ctx, const char* name); #else /* GLEW_MX */ +GLEWAPI GLenum glewInitLibrary (const char *name, enum GL_Name_Convention); GLEWAPI GLenum glewInit (); GLEWAPI GLboolean glewIsSupported (const char* name); #define glewIsExtensionSupported(x) glewIsSupported(x) -- 1.5.6.5 From 7912d91fcdf9c8772063ab10924bc22ee4c197a2 Mon Sep 17 00:00:00 2001 From: Tom Fogal <tfogal@...> Date: Sun, 8 Mar 2009 16:57:45 -0700 Subject: [PATCH] Switch to using a dynamic function loader on Linux. This switches the function loader used on Linux to be a (potentially) dynamically loaded function. A new function is added to initialize the variable, and add a call at the beginning of glewInit(). No machinery exists to select anything other than the default GL implementation. This commit should retain existing functionality. --- auto/src/glew_head.c | 61 ++++++++++++++++++++++++++++++++++++++++++++- auto/src/glew_init_tail.c | 5 +++ 2 files changed, 65 insertions(+), 1 deletions(-) diff --git a/auto/src/glew_head.c b/auto/src/glew_head.c index f233a2e..14fdafa 100644 --- a/auto/src/glew_head.c +++ b/auto/src/glew_head.c @@ -84,6 +84,65 @@ void* dlGetProcAddress (const GLubyte* name) } #endif /* __sgi || __sun */ +#if defined(__linux__) +#include <dlfcn.h> + +typedef void*(*GPA)(const GLubyte*); + +static const char *glew_gl_lib = NULL; +static enum GL_Name_Convention glew_convention = GLEW_NAME_CONVENTION_GL; +static GPA __glewXGetProcAddress = NULL; + +/* Give a couple debugging macros which allow us to report issues, but only if + * a debugging define is given. When defined, GLEW requires the standard C + * library. */ +#if defined(GLEW_DEBUG) && defined(__STDC_VERSION__) && \ + __STDC_VERSION__ >= 199901L +# include <stdio.h> +# include <stdlib.h> +# define warning(...) do { fprintf(stderr, __VA_ARGS__); } while(0) +# define error(...) do { fprintf(stderr, __VA_ARGS__); abort(); } while(0) +#else +# define warning(...) /* nothing */ +# define error(...) /* nothing */ +#endif + +/* Try to initialize our function loader. */ +static void _glewInit_GLX_Loader() +{ + const char *dl_error; + const char glx_gpa[] = "mglXGetProcAddress"; + static void *handle = NULL; + + if(NULL == handle) { + handle = dlopen(glew_gl_lib, RTLD_LAZY | RTLD_LOCAL); + if(NULL == handle) { + warning("Could not load library `%s': %s", glew_gl_lib, dlerror()); + } + } + + dlerror(); /* clear any previous error. */ + switch(glew_convention) { + case GLEW_NAME_CONVENTION_MANGLED_MESA: + __glewXGetProcAddress = dlsym(handle, glx_gpa+0); break; + case GLEW_NAME_CONVENTION_GL: /* FALL THROUGH */ + default: + __glewXGetProcAddress = dlsym(handle, glx_gpa+1); break; + } + if((dl_error = dlerror()) != NULL) { + error("Could not find dynamic loading function; %s", error); + } + + /* If all the above failed, we might still have a chance by using the + * Linux-ABI-required glXGetProcAddressARB. Unfortunately this forces us to + * use the systemGL, so only do it if that's what the user asked for. */ + if(__glewXGetProcAddress == NULL && + glew_convention == GLEW_NAME_CONVENTION_GL) { + __glewXGetProcAddress = (GPA) glXGetProcAddressARB; + } +} +#endif /* __linux__ */ + /* * Define glewGetProcAddress. */ @@ -96,7 +155,7 @@ void* dlGetProcAddress (const GLubyte* name) # if defined(__sgi) || defined(__sun) # define glewGetProcAddress(name) dlGetProcAddress(name) # else /* __linux */ -# define glewGetProcAddress(name) (*glXGetProcAddressARB)(name) +# define glewGetProcAddress(name) (*__glewXGetProcAddress)(name) # endif # endif #endif diff --git a/auto/src/glew_init_tail.c b/auto/src/glew_init_tail.c index 678b91c..0311ae8 100644 --- a/auto/src/glew_init_tail.c +++ b/auto/src/glew_init_tail.c @@ -43,6 +43,11 @@ extern GLenum glxewContextInit (void); GLenum glewInit () { GLenum r; + +#ifdef __linux__ + _glewInit_GLX_Loader(); +#endif + if ( (r = glewContextInit()) ) return r; #if defined(_WIN32) return wglewContextInit(); -- 1.5.6.5 From 5642fa3e5682ea734db95cc1fd768a1066f5bd21 Mon Sep 17 00:00:00 2001 From: Tom Fogal <tfogal@...> Date: Sun, 8 Mar 2009 20:12:17 -0700 Subject: [PATCH] cast to avoid warning --- auto/src/glew_head.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/auto/src/glew_head.c b/auto/src/glew_head.c index 14fdafa..6e7c0ac 100644 --- a/auto/src/glew_head.c +++ b/auto/src/glew_head.c @@ -155,7 +155,8 @@ static void _glewInit_GLX_Loader() # if defined(__sgi) || defined(__sun) # define glewGetProcAddress(name) dlGetProcAddress(name) # else /* __linux */ -# define glewGetProcAddress(name) (*__glewXGetProcAddress)(name) +# define glewGetProcAddress(name) (*__glewXGetProcAddress) \ + ((const GLubyte*)name) # endif # endif #endif -- 1.5.6.5 From ed4a037d4fcc0e859c14ecf6c08ed986e53e90dd Mon Sep 17 00:00:00 2001 From: Tom Fogal <tfogal@...> Date: Sun, 8 Mar 2009 20:12:56 -0700 Subject: [PATCH] Add new entry point. Allows clients to explicitly specify the OpenGL library to use. glXGetProcAddress will be looked up in this library; future function resolution will happen through glXGetProcAddress, as before. The user must also specify the naming convention. This lets us know whether we should use the GL name or Mesa's mangling of the name. The implementation is such that initialization is unified along both entry points. We set some internal GLEW state to defaults which mimic the previous GLEW behavior, and then we always use the new loading method. --- auto/src/glew_init_tail.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/auto/src/glew_init_tail.c b/auto/src/glew_init_tail.c index 0311ae8..c0e10f9 100644 --- a/auto/src/glew_init_tail.c +++ b/auto/src/glew_init_tail.c @@ -40,6 +40,14 @@ extern GLenum wglewContextInit (void); extern GLenum glxewContextInit (void); #endif /* _WIN32 */ +GLenum glewInitLibrary (const char *name, enum GL_Name_Convention conv) +{ + glew_gl_lib = name; + glew_convention = conv; + + return glewInit(); +} + GLenum glewInit () { GLenum r; -- 1.5.6.5 From df240eb5412812a462b3dcd3015acc599483af36 Mon Sep 17 00:00:00 2001 From: Tom Fogal <tfogal@...> Date: Sun, 8 Mar 2009 20:18:40 -0700 Subject: [PATCH] Use a dynamically loaded glGetString on Linux. Otherwise we always use the system GL, even if we just loaded the Mesa implementation! --- auto/src/glew_init_gl.c | 13 +++++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/auto/src/glew_init_gl.c b/auto/src/glew_init_gl.c index aaba1d5..21ab090 100644 --- a/auto/src/glew_init_gl.c +++ b/auto/src/glew_init_gl.c @@ -33,7 +33,20 @@ GLenum glewContextInit (GLEW_CONTEXT_ARG_DEF_LIST) const GLubyte* s; GLuint dot, major, minor; /* query opengl version */ +#ifdef __linux__ + { + typedef const GLubyte*(*GetString)(GLenum); + GetString __glewGetString; + if(glew_convention == GLEW_NAME_CONVENTION_MANGLED_MESA) { + __glewGetString = glewGetProcAddress("mglGetString"); + } else { + __glewGetString = glewGetProcAddress("glGetString"); + } + s = __glewGetString(GL_VERSION); + } +#else s = glGetString(GL_VERSION); +#endif dot = _glewStrCLen(s, '.'); major = dot-1; minor = dot+1; -- 1.5.6.5 ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H _______________________________________________ glew-coders mailing list glew-coders@... https://lists.sourceforge.net/lists/listinfo/glew-coders |
|
|
Re: Runtime GL library loading patchestom fogal <tfogal@...> writes:
> As promised, I said I'd send `a patch' by this weekend [1]. The patchset breaks Mac, and probably all non-Linux platforms actually. The issue is that glewInitLibrary assumes those static vars exist && they only actually get defined on Linux. The attached patch solves the issue. It may make sense for all platforms to follow suite and allow dynamic runtime loading. In the interests of changing as little as possible (and since I only need this for Linux), I tried to avoid that at first. I actually can test on Mac (just forgot initially), so I could do this. Opinions welcome. -tom From adf11188728e79fa2b7238b4fbcdfba9283b4ef0 Mon Sep 17 00:00:00 2001 From: Tom Fogal <tfogal@...> Date: Fri, 20 Mar 2009 10:10:18 -0700 Subject: [PATCH] Fix compilation on non-Linux platforms. The static variables only exist on Linux, so don't try to write them unless we're on Linux. This means other platforms can't do dynamic runtime loading of the GL lib. --- auto/src/glew_init_tail.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/auto/src/glew_init_tail.c b/auto/src/glew_init_tail.c index c0e10f9..aebf88c 100644 --- a/auto/src/glew_init_tail.c +++ b/auto/src/glew_init_tail.c @@ -42,8 +42,10 @@ extern GLenum glxewContextInit (void); GLenum glewInitLibrary (const char *name, enum GL_Name_Convention conv) { +#ifdef __linux__ glew_gl_lib = name; glew_convention = conv; +#endif return glewInit(); } -- 1.5.6.5 ------------------------------------------------------------------------------ Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are powering Web 2.0 with engaging, cross-platform capabilities. Quickly and easily build your RIAs with Flex Builder, the Eclipse(TM)based development software that enables intelligent coding and step-through debugging. Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com _______________________________________________ glew-coders mailing list glew-coders@... https://lists.sourceforge.net/lists/listinfo/glew-coders |
| Free embeddable forum powered by Nabble | Forum Help |