From 0a746faa2d018d93e19d36e6a583cca100f7c68a Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 12 Jul 2012 16:41:53 +0000 Subject: [PATCH] Introduced Texture::Extensions::s/getPreferGenerateMipmapSGISForPowerOfTwo() flag that defaults to false for Radeon, true elsewhere. This is used to workaround mipmapping bugs with ATI/AMD cards. --- include/osg/Texture | 4 ++++ src/osg/Texture.cpp | 30 ++++++++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index e1c2554b6..899a6df8b 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -678,6 +678,9 @@ class OSG_EXPORT Texture : public osg::StateAttribute void setGenerateMipMapSupported(bool flag) { _isGenerateMipMapSupported=flag; } bool isGenerateMipMapSupported() const { return _isGenerateMipMapSupported; } + void setPreferGenerateMipmapSGISForPowerOfTwo(bool flag) { _preferGenerateMipmapSGISForPowerOfTwo = flag; } + bool getPreferGenerateMipmapSGISForPowerOfTwo() const { return _preferGenerateMipmapSGISForPowerOfTwo; } + void setTextureMultisampledSupported(bool flag) { _isTextureMultisampledSupported=flag; } bool isTextureMultisampledSupported() const { return _isTextureMultisampledSupported; } @@ -773,6 +776,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute bool _isTextureEdgeClampSupported; bool _isTextureBorderClampSupported; bool _isGenerateMipMapSupported; + bool _preferGenerateMipmapSGISForPowerOfTwo; bool _isTextureMultisampledSupported; bool _isShadowSupported; bool _isShadowAmbientSupported; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 15ffb09cc..1e20514c4 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -2330,22 +2330,24 @@ Texture::GenerateMipmapMode Texture::mipmapBeforeTexImage(const State& state, bo #if defined( OSG_GLES2_AVAILABLE ) || defined( OSG_GL3_AVAILABLE ) return GENERATE_MIPMAP; #else - int width = getTextureWidth(); - int height = getTextureHeight(); - //quick bithack to determine whether width or height are non-power-of-two - if ((width & (width - 1)) || (height & (height - 1))) + bool useGenerateMipMap = FBOExtensions::instance(state.getContextID(), true)->glGenerateMipmap!=0; + + if (useGenerateMipMap) { - //GL_GENERATE_MIPMAP_SGIS with non-power-of-two textures on NVIDIA hardware - //is extremely slow. Use glGenerateMipmapEXT() instead if supported. - if (_internalFormatType != SIGNED_INTEGER && - _internalFormatType != UNSIGNED_INTEGER) + if (Texture::getExtensions(state.getContextID(),true)->getPreferGenerateMipmapSGISForPowerOfTwo()) { - if (FBOExtensions::instance(state.getContextID(), true)->glGenerateMipmap) - { - return GENERATE_MIPMAP; - } + int width = getTextureWidth(); + int height = getTextureHeight(); + useGenerateMipMap = ((width & (width - 1)) || (height & (height - 1))); } + + if (useGenerateMipMap) + { + useGenerateMipMap = (_internalFormatType != SIGNED_INTEGER && _internalFormatType != UNSIGNED_INTEGER); + } + + if (useGenerateMipMap) return GENERATE_MIPMAP; } glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE); @@ -2470,6 +2472,8 @@ Texture::Extensions::Extensions(unsigned int contextID) const char* renderer = (const char*) glGetString(GL_RENDERER); std::string rendererString(renderer ? renderer : ""); + bool radeonHardwareDetected = (rendererString.find("Radeon")!=std::string::npos || rendererString.find("RADEON")!=std::string::npos); + bool builtInSupport = OSG_GLES2_FEATURES || OSG_GL3_FEATURES; _isMultiTexturingSupported = builtInSupport || OSG_GLES1_FEATURES || @@ -2507,6 +2511,8 @@ Texture::Extensions::Extensions(unsigned int contextID) _isGenerateMipMapSupported = builtInSupport || isGLExtensionOrVersionSupported(contextID,"GL_SGIS_generate_mipmap", 1.4f); + _preferGenerateMipmapSGISForPowerOfTwo = radeonHardwareDetected ? false : true; + _isTextureMultisampledSupported = isGLExtensionSupported(contextID,"GL_ARB_texture_multisample"); _isShadowSupported = OSG_GL3_FEATURES || isGLExtensionSupported(contextID,"GL_ARB_shadow");