diff --git a/include/osg/GLExtensions b/include/osg/GLExtensions index 8cbb81f9e..ad9d567dc 100644 --- a/include/osg/GLExtensions +++ b/include/osg/GLExtensions @@ -7,6 +7,14 @@ #include +#if defined(WIN32) +#include +#elif defined(__DARWIN_OSX__) +#include +#else +#include +#endif + namespace osg { /** return true if OpenGL "extension" is supported. @@ -17,8 +25,36 @@ SG_EXPORT extern const bool isGLExtensionSupported(const char *extension); /** return the address of the specified OpenGL function. * return NULL if function not supported by OpenGL library. + * Note, glGLExtensionFuncPtr is declared inline so that the code + * is compiled localy to the calling code. This should get by Windows + * dumb implementation of having different GL function ptr's for each + * library when links to it. */ -SG_EXPORT extern void* getGLExtensionFuncPtr(const char *funcName); +inline void* getGLExtensionFuncPtr(const char *funcName) +{ +#if defined(WIN32) + return wglGetProcAddress(funcName); +#elif defined(__DARWIN_OSX__) + std::string temp( "_" ); + temp += funcName; // Mac OS X prepends an underscore on function names + if ( NSIsSymbolNameDefined( temp.c_str() ) ) + { + NSSymbol symbol = NSLookupAndBindSymbol( temp.c_str() ); + return NSAddressOfSymbol( symbol ); + } else + return NULL; +#else // all other unixes + // Note: although we use shl_load() etc. for Plugins on HP-UX, it's + // not neccessary here since we only used them because library + // intialization was not taking place with dlopen() which renders + // Plugins useless on HP-UX. + static void *lib = dlopen("libGL.so", RTLD_LAZY); + if (lib) + return dlsym(lib, funcName); + else + return NULL; +#endif +} /** return the address of the specified OpenGL function, if not found then * check a second function name, if this fails then return NULL as function is diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index a6d7185da..2546c3f71 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -1,10 +1,3 @@ -#if defined(WIN32) -#include -#elif defined(__DARWIN_OSX__) -#include -#else -#include -#endif #include #include @@ -58,27 +51,3 @@ const bool osg::isGLExtensionSupported(const char *extension) return result; } - - -void* osg::getGLExtensionFuncPtr(const char *funcName) -{ -#if defined(WIN32) - return wglGetProcAddress(funcName); -#elif defined(__DARWIN_OSX__) - std::string temp( "_" ); - NSSymbol symbol; - temp += funcName; // Mac OS X prepends an underscore on function names - symbol = NSLookupAndBindSymbol( temp.c_str() ); - return NSAddressOfSymbol( symbol ); -#else // all other unixes - // Note: although we use shl_load() etc. for Plugins on HP-UX, it's - // not neccessary here since we only used them because library - // intialization was not taking place with dlopen() which renders - // Plugins useless on HP-UX. - static void *lib = dlopen("libGL.so", RTLD_LAZY); - if (lib) - return dlsym(lib, funcName); - else - return NULL; -#endif -} diff --git a/src/osg/Geometry.cpp b/src/osg/Geometry.cpp index 784e70179..3f1762001 100644 --- a/src/osg/Geometry.cpp +++ b/src/osg/Geometry.cpp @@ -241,7 +241,6 @@ void Geometry::drawImmediateMode(State& state) } } - static SecondaryColor3ubvProc s_glSecondaryColor3ubv = (SecondaryColor3ubvProc) osg::getGLExtensionFuncPtr("glSecondaryColor3ubv","glSecondaryColor3ubvEXT"); static SecondaryColor3fvProc s_glSecondaryColor3fv = diff --git a/src/osg/State.cpp b/src/osg/State.cpp index 38291c1d5..ea3f4f0b7 100644 --- a/src/osg/State.cpp +++ b/src/osg/State.cpp @@ -469,7 +469,7 @@ void State::setSecondaryColorPointer( GLint size, GLenum type, GLsizei stride, const GLvoid *ptr ) { static SecondaryColorPointerProc s_glSecondaryColorPointer = - (SecondaryColorPointerProc) osg::getGLExtensionFuncPtr("glFogCoordPointer","glFogCoordPointerEXT"); + (SecondaryColorPointerProc) osg::getGLExtensionFuncPtr("glSecondaryColorPointer","glSecondaryColorPointerEXT"); if (s_glSecondaryColorPointer) {