OpenSceneGraph/include/osg/GLExtensions
Robert Osfield 12226e4371 Converted the instances of const built in types being returned from methods
and passed as paramters into straight forward non const built in types,
i.e. const bool foogbar(const int) becomes bool foobar(int).
2002-09-02 12:31:35 +00:00

108 lines
3.4 KiB
Plaintext

//C++ header - Open Scene Graph - Copyright (C) 1998-2002 Robert Osfield
//Distributed under the terms of the GNU Library General Public License (LGPL)
//as published by the Free Software Foundation.
#ifndef OSG_GLEXTENSIONS
#define OSG_GLEXTENSIONS 1
#include <osg/Export>
#if defined(WIN32)
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#elif defined(__DARWIN_OSX__)
#include <string>
#include <mach-o/dyld.h>
#else
#include <dlfcn.h>
#endif
namespace osg {
/** return true if OpenGL "extension" is supported.
* note: Must only called within a valid OpenGL context,
* undefined behavior may occur otherwise.
*/
SG_EXPORT extern 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.
*/
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
* not supported by OpenGL library. This is usual for checking something
* like glActiveTexture (which is in OGL1.3) or glActiveTextureARB.
*/
inline void* getGLExtensionFuncPtr(const char *funcName,const char *fallbackFuncName)
{
void* ptr = getGLExtensionFuncPtr(funcName);
if (ptr) return ptr;
return getGLExtensionFuncPtr(fallbackFuncName);
}
/** return true if OpenGL "extension" is supported.
* note: Must only called within a valid OpenGL context,
* undefined behavior may occur otherwise.
*/
SG_EXPORT extern bool isGLUExtensionSupported(const char *extension);
inline void* getGLUExtensionFuncPtr(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("libGLU.so", RTLD_LAZY);
if (lib)
return dlsym(lib, funcName);
else
return NULL;
#endif
}
}
#endif