Changeset 851

Show
Ignore:
Timestamp:
07/26/07 10:09:33 (1 year ago)
Author:
allenb
Message:

- On GLX, attempt to use glxGetproc directly if we think it is available.

This change closes up a HUGE set of potential bugs where an incorrect libGL.so can be found on the system and therefore an invalid method be lookedup and called
at run-time. This change may need fixed up a bit to make it work more places, but it is definitely needed.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/fcptr_stable_jun07/Source/System/Window/Base/OSGWindow.cpp

    r850 r851  
    9191#endif 
    9292 
     93#define TRY_USING_GLXGETPROC_DIRECTLY 1    // If true, then try just calling get proc 
     94 
    9395// Documentation for this class is emited in the 
    9496// OSGWindowBase.cpp file. 
     
    15451547    GLExtensionFunction retval = NULL; 
    15461548 
     1549    FINFO(("Window::getFunctionByName: %s", s)); 
     1550 
     1551    FDEBUG(("Window %p: GL Vendor: %s\n", this,  
     1552                glGetString(GL_VENDOR) )); 
     1553 
    15471554#if defined(__APPLE__) 
    15481555 
     
    15731580 
    15741581    static void *libHandle = NULL;  
    1575  
     1582    std::string  libHandleName; 
     1583 
     1584    // If we haven't found the library previously, then look for it. 
    15761585    if(libHandle == NULL)  
    15771586    {  
     
    15801589        if(!libHandle)  
    15811590        {  
    1582             FWARNING(("Error in dlopen: %s\n",dlerror()));  
     1591            FWARNING(("Error in dlopen when opening GL lib: %s\n",dlerror()));  
    15831592            abort();  
    15841593        }  
    15851594        else 
    15861595        { 
    1587             FDEBUG(("Opened lib %s for GL extension handling.\n",  
    1588                     (_glLibraryName==NULL) ? "(executable)" : _glLibraryName)); 
     1596            libHandleName = std::string((_glLibraryName==NULL) ? "(executable)" : _glLibraryName); 
     1597            FINFO(("Opened lib %s for GL extension handling.\n",  
     1598                    libHandleName.c_str())); 
    15891599        } 
    15901600    }  
     
    15921602    if(__GetProcAddress == NULL)  
    15931603    {  
    1594         __GetProcAddress =  
    1595             (void (*(*)(const GLubyte*))()) dlsym(libHandle,  
    1596                                                   "glXGetProcAddressARB");  
    1597  
    1598         if(__GetProcAddress == NULL)  
    1599         {  
    1600             __GetProcAddress =  
    1601                 (void (*(*)(const GLubyte*))()) dlsym(libHandle,  
    1602                                                       "glXGetProcAddress");  
    1603  
    1604             if(__GetProcAddress == NULL)  
    1605             { 
    1606                 // Couldn't find it linked to the executable. Try to open 
    1607                 // libGL.so directly. 
    1608                  
    1609                 dlclose(libHandle); 
    1610                  
    1611                 libHandle = dlopen("libGL.so", RTLD_NOW | RTLD_GLOBAL);  
    1612  
    1613                 if(!libHandle)  
    1614                 {  
    1615                     FWARNING(("Error in dlopen: %s\n",dlerror()));  
    1616                     abort();  
    1617                 }  
    1618                 else 
    1619                 { 
    1620                     FDEBUG(("Opened libGL.so for GL extension handling.\n")); 
    1621                 } 
    1622                  
    1623                 __GetProcAddress =  
    1624                     (void (*(*)(const GLubyte*))()) dlsym( 
    1625                         libHandle, "glXGetProcAddressARB");  
    1626  
    1627                 if(__GetProcAddress == NULL)  
    1628                 {  
    1629                     __GetProcAddress =  
    1630                         (void (*(*)(const GLubyte*))())dlsym( 
    1631                             libHandle, "glXGetProcAddress");  
    1632                 } 
    1633  
    1634  
    1635                 if(__GetProcAddress == NULL)  
    1636                 { 
    1637                     FWARNING(("Neither glXGetProcAddress nor " 
    1638                               "glXGetProcAddressARB found! Disabling all " 
    1639                               " extensions for Window %p!\n"));  
    1640                      
    1641                     _availExtensions.clear(); 
    1642                     _availExtensions.resize(_registeredExtensions.size(),  
    1643                                             false); 
    1644                 } 
    1645             }  
    1646             else 
    1647             { 
    1648                 FDEBUG(("Using glXGetProcAddress for GL " 
    1649                         "extension handling.\n")); 
    1650             } 
    1651         }  
    1652         else 
    1653         { 
    1654             FDEBUG(("Using glXGetProcAddressARB for GL " 
    1655                     "extension handling.\n")); 
     1604       FINFO(("Finding glxGetProcAddress method: ")); 
     1605 
     1606#ifdef TRY_USING_GLXGETPROC_DIRECTLY 
     1607 
     1608       // Try pulling in ARB function directly 
     1609/* 
     1610#ifdef GLX_ARB_get_proc_address 
     1611        if(__GetProcAddress == NULL) 
     1612        { 
     1613           __GetProcAddress = glXGetProcAddressARB; 
     1614           FINFO((" Using glxGetProcAddressARB directly.\n")); 
     1615        } 
     1616#endif 
     1617*/ 
     1618       // If GLX version is 1.4 or greater then the method should exist 
     1619#ifdef GLX_VERSION_1_4 
     1620        if(__GetProcAddress == NULL) 
     1621        { 
     1622           __GetProcAddress = glXGetProcAddress; 
     1623           FINFO((" Using glxGetProcAddress directly.\n")); 
     1624        } 
     1625#endif 
     1626#endif 
     1627        if(__GetProcAddress == NULL) 
     1628        { 
     1629           __GetProcAddress =  
     1630               (void (*(*)(const GLubyte*))()) dlsym(libHandle,  
     1631                                                     "glXGetProcAddressARB");  
     1632    
     1633           if(__GetProcAddress == NULL)  
     1634           {  
     1635               __GetProcAddress =  
     1636                   (void (*(*)(const GLubyte*))()) dlsym(libHandle,  
     1637                                                         "glXGetProcAddress");  
     1638    
     1639               if(__GetProcAddress == NULL)  
     1640               { 
     1641                   // Couldn't find it linked to the executable. Try to open 
     1642                   // libGL.so directly. 
     1643                    
     1644                   dlclose(libHandle); 
     1645                    
     1646                   libHandle = dlopen("libGL.so", RTLD_NOW | RTLD_GLOBAL);  
     1647    
     1648                   if(!libHandle)  
     1649                   {  
     1650                       FWARNING(("Error in dlopen: %s\n",dlerror()));  
     1651                       abort();  
     1652                   }  
     1653                   else 
     1654                   { 
     1655                       FINFO((" Using libGL.so directly.\n"));                     
     1656                   } 
     1657                    
     1658                   __GetProcAddress =  
     1659                       (void (*(*)(const GLubyte*))()) dlsym( 
     1660                           libHandle, "glXGetProcAddressARB");  
     1661    
     1662                   if(__GetProcAddress == NULL)  
     1663                   {  
     1664                       __GetProcAddress =  
     1665                           (void (*(*)(const GLubyte*))())dlsym( 
     1666                               libHandle, "glXGetProcAddress");  
     1667                   } 
     1668    
     1669    
     1670                   if(__GetProcAddress == NULL)  
     1671                   { 
     1672                       FWARNING(("Neither glXGetProcAddress nor " 
     1673                                 "glXGetProcAddressARB found! Disabling all " 
     1674                                 " extensions for Window %p!\n"));  
     1675                        
     1676                       _availExtensions.clear(); 
     1677                       _availExtensions.resize(_registeredExtensions.size(),  
     1678                                               false); 
     1679                   } 
     1680               }  
     1681               else 
     1682               { 
     1683                   FINFO((" Using glXGetProcAddress (from %s).\n", libHandleName.c_str())); 
     1684               } 
     1685           }  
     1686           else 
     1687           { 
     1688               FINFO(("Using glXGetProcAddressARB (from %s).\n", libHandleName.c_str()));                     
     1689           } 
    16561690        } 
    16571691    }