vrj::GlExtensionLoader Class Reference

Base class for OpenGL extension registration and lookup. More...

#include <GlExtensionLoader.h>

Inheritance diagram for vrj::GlExtensionLoader:

Inheritance graph
[legend]
List of all members.

Public Types

typedef void(*) VoidExtFunc (void)
 Void type to use when treating extensions the same.

Public Member Functions

 GlExtensionLoader ()
virtual ~GlExtensionLoader ()
virtual void registerExtensions ()
 Register common extensions that we may need to use.
VoidExtFunc getFunctionByName (const char *name)
 Return pointer to extension if it exists.

Detailed Description

Base class for OpenGL extension registration and lookup.

This is a the base for a simple helper class for getting at OpenGL/WGL/GLX extensions that we need for VRJ.

Definition at line 43 of file GlExtensionLoader.h.


Member Typedef Documentation

typedef void(*) vrj::GlExtensionLoader::VoidExtFunc(void)

Void type to use when treating extensions the same.

Definition at line 47 of file GlExtensionLoader.h.


Constructor & Destructor Documentation

vrj::GlExtensionLoader::GlExtensionLoader (  )  [inline]

Definition at line 50 of file GlExtensionLoader.h.

00051    {;}

virtual vrj::GlExtensionLoader::~GlExtensionLoader (  )  [inline, virtual]

Definition at line 53 of file GlExtensionLoader.h.

00054    {;}


Member Function Documentation

virtual void vrj::GlExtensionLoader::registerExtensions (  )  [inline, virtual]

Register common extensions that we may need to use.

Reimplemented in vrj::GlExtensionLoaderWin32, and vrj::GlxExtensionLoader.

Definition at line 57 of file GlExtensionLoader.h.

Referenced by vrj::GlxExtensionLoader::registerExtensions(), and vrj::GlExtensionLoaderWin32::registerExtensions().

00058    {;}

GlExtensionLoader::VoidExtFunc vrj::GlExtensionLoader::getFunctionByName ( const char *  name  ) 

Return pointer to extension if it exists.

Definition at line 53 of file GlExtensionLoader.cpp.

Referenced by vrj::GlxExtensionLoader::registerExtensions(), and vrj::GlExtensionLoaderWin32::registerExtensions().

00054 {
00055    VoidExtFunc found_func(NULL);
00056 
00057 #if defined(VPR_OS_Darwin)
00058    if (NSIsSymbolNameDefined(name))
00059    {
00060       NSSymbol symbol = NSLookupAndBindSymbol(name);
00061       if (0 != symbol)
00062       {
00063          found_func = VoidExtFunc(NSAddressOfSymbol(symbol)); 
00064       }
00065    }
00066 #elif defined(WIN32)
00067 
00068    found_func = (void(__cdecl*)(void)) wglGetProcAddress(name);
00069 
00070 #elif defined(VPR_OS_IRIX) || defined(VPR_OS_HPUX) || \
00071    defined(VPR_OS_Linux) || defined(VPR_OS_FreeBSD) || defined(VPR_OS_Solaris)
00072 
00073    /* Workaround for multiple nVidia/Linux installation bugs, based on code in OpenSG */      
00074    static void (*(*__GetProcAddress)(const GLubyte *))(void) = NULL; 
00075 
00076    static void* lib_handle(NULL); 
00077 
00078    if (lib_handle == NULL)
00079    {
00080       lib_handle = dlopen(NULL, RTLD_NOW | RTLD_LOCAL); 
00081 
00082       if (!lib_handle)
00083       {
00084          vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL) << "Error in dlopen:" << dlerror() << vprDEBUG_FLUSH;         
00085       }
00086    }
00087 
00088    if (__GetProcAddress == NULL)
00089    {
00090       __GetProcAddress = (void (*(*)(const GLubyte*))()) dlsym(lib_handle, "glXGetProcAddressARB"); 
00091 
00092       if (__GetProcAddress == NULL)
00093       {
00094          __GetProcAddress = (void (*(*)(const GLubyte*))()) dlsym(lib_handle, "glXGetProcAddress"); 
00095 
00096          if (__GetProcAddress == NULL)
00097          {
00098             vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL) << "WARNING: Neither glXGetProcAddress nor "
00099                      "glXGetProcAddressARB found! Disabling all "
00100                      " extensions lookups.\n" << vprDEBUG_FLUSH;                   
00101          }
00102          else
00103          {
00104             vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) << "Using glXGetProcAddress for GL extension handling.\n" << vprDEBUG_FLUSH;
00105          }
00106       }
00107       else
00108       {
00109          vprDEBUG(vprDBG_ALL, vprDBG_STATE_LVL) << "Using glXGetProcAddressARB for GL extension handling.\n" << vprDEBUG_FLUSH;
00110       }
00111    }
00112 
00113    if (__GetProcAddress != NULL)
00114    {
00115       found_func = reinterpret_cast<VoidExtFunc>(__GetProcAddress((const GLubyte*)name)); 
00116    }
00117    else
00118    {
00119       found_func = (VoidExtFunc)(dlsym(lib_handle, name)); 
00120    } 
00121 
00122 #else
00123    vprDEBUG(vprDBG_ALL, vprDBG_WARNING_LVL) 
00124       << "Warnining: Missing implementation for extension registration on this platform.\n"
00125       << "OpenGL extensions will not be available to VR Juggler.\n" << vprDEBUG_FLUSH;
00126 #endif
00127 
00128    if (found_func == NULL)
00129    {
00130       vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL) << "GlExtensionLoader:: Couldn't find function " << name << std::endl << vprDEBUG_FLUSH;          
00131    }
00132    else
00133    {
00134       vprDEBUG(vprDBG_ALL, vprDBG_HVERB_LVL) << "GlExtensionLoader:: Found function " << name << std::endl << vprDEBUG_FLUSH;          
00135    }
00136 
00137    return found_func;
00138 }


The documentation for this class was generated from the following files:
Generated on Thu Jan 4 10:58:17 2007 for VR Juggler by  doxygen 1.5.1