/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #if defined(WIN32) #include #endif typedef std::set ExtensionSet; static osg::buffered_object s_glExtensionSetList; static osg::buffered_object s_glRendererList; static osg::buffered_value s_glInitializedList; static osg::buffered_object s_gluExtensionSetList; static osg::buffered_object s_gluRendererList; static osg::buffered_value s_gluInitializedList; float osg::getGLVersionNumber() { // needs to be extended to do proper things with subversions like 1.5.1, etc. char *versionstring = (char*) glGetString( GL_VERSION ); if (!versionstring) return 0.0; std::string vs( versionstring ); return( asciiToFloat( vs.substr( 0, vs.find( " " ) ).c_str() ) ); } bool osg::isExtensionInExtensionString(const char *extension, const char *extensionString) { const char *startOfWord = extensionString; const char *endOfWord; while ((endOfWord = strchr(startOfWord,' ')) != 0) { if (strncmp(extension, startOfWord, endOfWord - startOfWord) == 0) return true; startOfWord = endOfWord+1; } if (*startOfWord && strcmp(extension, startOfWord) == 0) return true; return false; } bool osg::isGLExtensionSupported(unsigned int contextID, const char *extension) { return osg::isGLExtensionOrVersionSupported(contextID, extension, FLT_MAX); } bool osg::isGLExtensionOrVersionSupported(unsigned int contextID, const char *extension, float requiredGLVersion) { ExtensionSet& extensionSet = s_glExtensionSetList[contextID]; std::string& rendererString = s_glRendererList[contextID]; // first check to see if GL version number of recent enough. bool result = requiredGLVersion <= osg::getGLVersionNumber(); if (!result) { // if not already set up, initialize all the per graphic context values. if (!s_glInitializedList[contextID]) { s_glInitializedList[contextID] = 1; // set up the renderer const GLubyte* renderer = glGetString(GL_RENDERER); rendererString = renderer ? (const char*)renderer : ""; // get the extension list from OpenGL. #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) if( osg::getGLVersionNumber() >= 3.0 ) { // OpenGL 3.0 adds the concept of indexed strings and // deprecates calls to glGetString( GL_EXTENSIONS ), which // will now generate GL_INVALID_ENUM. // Get extensions using new indexed string interface. typedef const GLubyte * APIENTRY PFNGLGETSTRINGIPROC( GLenum, GLuint ); PFNGLGETSTRINGIPROC* glGetStringi = 0; setGLExtensionFuncPtr( glGetStringi, "glGetStringi"); if( glGetStringi != NULL ) { # ifndef GL_NUM_EXTENSIONS # define GL_NUM_EXTENSIONS 0x821D # endif GLint numExt; glGetIntegerv( GL_NUM_EXTENSIONS, &numExt ); int idx; for( idx=0; idx #elif defined(__APPLE__) // The NS*Symbol* stuff found in is deprecated. // Since 10.3 (Panther) OS X has provided the dlopen/dlsym/dlclose // family of functions under . Since 10.4 (Tiger), Apple claimed // the dlfcn family was significantly faster than the NS*Symbol* family. // Since 'deprecated' needs to be taken very seriously with the // coming of 10.5 (Leopard), it makes sense to use the dlfcn family when possible. #include #if !defined(MAC_OS_X_VERSION_10_3) || (MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_3) #define USE_APPLE_LEGACY_NSSYMBOL #include #else #include #endif #else #include #endif void* osg::getGLExtensionFuncPtr(const char *funcName) { // OSG_NOTIFY(osg::NOTICE)<<"osg::getGLExtensionFuncPtr("<(GetProcAddress(hmodule, funcName)); #elif defined(OSG_GLES1_AVAILABLE) static HMODULE hmodule = GetModuleHandleA(TEXT("libgles_cm.dll")); return convertPointerType(GetProcAddress(hmodule, funcName)); #else return convertPointerType(wglGetProcAddress(funcName)); #endif #elif defined(__APPLE__) #if defined(USE_APPLE_LEGACY_NSSYMBOL) 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 // I am uncertain of the correct and ideal usage of dlsym here. // On the surface, it would seem that the FreeBSD implementation // would be the ideal one to copy, but ELF and Mach-o are different // and Apple's man page says the following about using RTLD_DEFAULT: // "This can be a costly search and should be avoided." // The documentation mentions nothing about passing in 0 so I must // assume the behavior is undefined. // So I could try copying the Sun method which I think all this // actually originated from. // return dlsym( RTLD_DEFAULT, funcName ); static void *handle = dlopen((const char *)0L, RTLD_LAZY); return dlsym(handle, funcName); #endif #elif defined (__sun) static void *handle = dlopen((const char *)0L, RTLD_LAZY); return dlsym(handle, funcName); #elif defined (__sgi) static void *handle = dlopen((const char *)0L, RTLD_LAZY); return dlsym(handle, funcName); #elif defined (__FreeBSD__) return dlsym( RTLD_DEFAULT, funcName ); #elif defined (__linux__) typedef void (*__GLXextFuncPtr)(void); typedef __GLXextFuncPtr (*GetProcAddressARBProc)(const char*); #if !defined(OSG_GLES1_AVAILABLE) && !defined(OSG_GLES2_AVAILABLE) static GetProcAddressARBProc s_glXGetProcAddressARB = convertPointerType(dlsym(0, "glXGetProcAddressARB")); if (s_glXGetProcAddressARB) { return convertPointerType((s_glXGetProcAddressARB)(funcName)); } #endif return dlsym(0, funcName); #elif defined (__QNX__) return dlsym(RTLD_DEFAULT, funcName); #else // all other unixes return dlsym(0, funcName); #endif }