Added osg::setGLExtensionDisableString && osg::getGLExtensionDisableString()
functions the GLExtensions file, and made the isGLExtensionSupported() function use the extension disable string when extension are querried.
This commit is contained in:
@@ -15,13 +15,13 @@
|
||||
#define OSG_GLEXTENSIONS 1
|
||||
|
||||
#include <osg/Export>
|
||||
#include <string>
|
||||
|
||||
#if defined(WIN32)
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#elif defined(__DARWIN_OSX__)
|
||||
#include <string>
|
||||
#include <mach-o/dyld.h>
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
namespace osg {
|
||||
|
||||
|
||||
|
||||
/** return true if OpenGL "extension" is supported.
|
||||
* note: Must only called within a valid OpenGL context,
|
||||
* undefined behavior may occur otherwise.
|
||||
@@ -71,6 +73,21 @@ inline void* getGLExtensionFuncPtr(const char *funcName)
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Set a list of extensions to disable for different OpenGL renders, this allows
|
||||
* OSG applications to work around OpenGL drivers bugs which are due to problemenatic extension support.
|
||||
* The format of the string is:
|
||||
* "GLRendererString : ExtensionName, ExtensionName; GLRenderString2 : ExtensionName;"
|
||||
* An example of is : "SUN_XVR1000:GL_EXT_texture_filter_anisotropic"
|
||||
* The default setting of GLExtensionDisableString is obtain from the OSG_GL_EXTENSION_DISABLE
|
||||
* environmental variable.
|
||||
*/
|
||||
extern SG_EXPORT void setGLExtensionDisableString(const std::string& disableString);
|
||||
|
||||
/** Get the list of extensions that are disabled for various OpenGL renders.*/
|
||||
extern SG_EXPORT std::string& getGLExtensionDisableString();
|
||||
|
||||
|
||||
|
||||
/** 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
|
||||
|
||||
@@ -58,12 +58,91 @@ bool osg::isGLExtensionSupported(const char *extension)
|
||||
// true if extension found in extensionSet.
|
||||
bool result = s_extensionSet.find(extension)!=s_extensionSet.end();
|
||||
|
||||
if (result) osg::notify(INFO)<<"OpenGL extension '"<<extension<<"' is supported."<<std::endl;
|
||||
bool extensionDisabled = false;
|
||||
|
||||
if (result)
|
||||
{
|
||||
|
||||
const std::string& disableString = getGLExtensionDisableString();
|
||||
if (!disableString.empty())
|
||||
{
|
||||
|
||||
static const GLubyte* s_renderer = glGetString(GL_RENDERER);
|
||||
static std::string s_rendererString(s_renderer?(const char*)s_renderer:"");
|
||||
|
||||
std::string::size_type pos=0;
|
||||
while ( pos!=std::string::npos && (pos=disableString.find(extension,pos))!=std::string::npos )
|
||||
{
|
||||
std::string::size_type previousColon = disableString.find_last_of(':',pos);
|
||||
std::string::size_type previousSemiColon = disableString.find_last_of(';',pos);
|
||||
|
||||
std::string renderer = "";
|
||||
if (previousColon!=std::string::npos)
|
||||
{
|
||||
if (previousSemiColon==std::string::npos) renderer = disableString.substr(0,previousColon);
|
||||
else if (previousSemiColon<previousColon) renderer = disableString.substr(previousSemiColon+1,previousColon-previousSemiColon-1);
|
||||
}
|
||||
|
||||
if (!renderer.empty())
|
||||
{
|
||||
|
||||
// remove leading spaces if they exist.
|
||||
std::string::size_type leadingSpaces = renderer.find_first_not_of(' ');
|
||||
if (leadingSpaces==std::string::npos) renderer = ""; // nothing but spaces
|
||||
else if (leadingSpaces!=0) renderer.erase(0,leadingSpaces);
|
||||
|
||||
// remove trailing spaces if they exist.
|
||||
std::string::size_type trailingSpaces = renderer.find_last_not_of(' ');
|
||||
if (trailingSpaces!=std::string::npos) renderer.erase(trailingSpaces+1,std::string::npos);
|
||||
|
||||
}
|
||||
|
||||
std::cout<<"render='"<<renderer<<"'"<<std::endl;
|
||||
|
||||
if (renderer.empty())
|
||||
{
|
||||
extensionDisabled = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (s_rendererString.find(renderer)!=std::string::npos)
|
||||
{
|
||||
extensionDisabled = true;
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
// move the position in the disable string along so that the same extension is found multiple times
|
||||
++pos;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (result)
|
||||
{
|
||||
if (!extensionDisabled) osg::notify(INFO)<<"OpenGL extension '"<<extension<<"' is supported."<<std::endl;
|
||||
else osg::notify(INFO)<<"OpenGL extension '"<<extension<<"' is supported by OpenGL\ndriver but has been disabled by osg::getGLExtensionDisableString()."<<std::endl;
|
||||
}
|
||||
else osg::notify(INFO)<<"OpenGL extension '"<<extension<<"' is not supported."<<std::endl;
|
||||
|
||||
return result;
|
||||
|
||||
return result && !extensionDisabled;
|
||||
}
|
||||
|
||||
void osg::setGLExtensionDisableString(const std::string& disableString)
|
||||
{
|
||||
getGLExtensionDisableString() = disableString;
|
||||
}
|
||||
|
||||
std::string& osg::getGLExtensionDisableString()
|
||||
{
|
||||
static const char* envVar = getenv("OSG_GL_EXTENSION_DISABLE");
|
||||
static std::string s_GLExtensionDisableString(envVar?envVar:"Nothing defined");
|
||||
return s_GLExtensionDisableString;
|
||||
}
|
||||
|
||||
|
||||
bool osg::isGLUExtensionSupported(const char *extension)
|
||||
{
|
||||
typedef std::set<std::string> ExtensionSet;
|
||||
|
||||
Reference in New Issue
Block a user