GlExtensionLoader.cpp

Go to the documentation of this file.
00001 /*************** <auto-copyright.pl BEGIN do not edit this line> **************
00002  *
00003  * VR Juggler is (C) Copyright 1998-2006 by Iowa State University
00004  *
00005  * Original Authors:
00006  *   Allen Bierbaum, Christopher Just,
00007  *   Patrick Hartling, Kevin Meinert,
00008  *   Carolina Cruz-Neira, Albert Baker
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Library General Public
00012  * License as published by the Free Software Foundation; either
00013  * version 2 of the License, or (at your option) any later version.
00014  *
00015  * This library is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00018  * Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public
00021  * License along with this library; if not, write to the
00022  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00023  * Boston, MA 02111-1307, USA.
00024  *
00025  * -----------------------------------------------------------------
00026  * File:          $RCSfile$
00027  * Date modified: $Date: 2006-04-14 17:42:22 -0500 (Fri, 14 Apr 2006) $
00028  * Version:       $Revision: 18672 $
00029  * -----------------------------------------------------------------
00030  *
00031  *************** <auto-copyright.pl END do not edit this line> ***************/
00032 
00033 #include <vrj/Draw/OGL/GlExtensionLoader.h>
00034 #include <vpr/vprConfig.h>
00035 #include <vpr/Util/Debug.h>
00036 
00037 #include <GL/gl.h>
00038 
00039 #if !defined(WIN32) && !defined(VPR_OS_Darwin)
00040 #include <GL/glx.h>
00041 #endif
00042 
00043 #if defined(VPR_OS_Darwin)
00044 #include <mach-o/dyld.h>
00045 #elif !defined(WIN32)
00046 #include <dlfcn.h>
00047 #endif
00048 
00049 
00050 namespace vrj
00051 {
00052 
00053 GlExtensionLoader::VoidExtFunc GlExtensionLoader::getFunctionByName(const char* name)
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 }
00139 
00140 } // namespace vrj
00141 

Generated on Thu Jan 4 10:56:51 2007 for VR Juggler by  doxygen 1.5.1