From 2e4b266c39178e40a761a30ee9e36fe346e43d94 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 17 May 2005 11:00:13 +0000 Subject: [PATCH] Added differentiation between Non power of two textures when mip mapped vs when not mipped mapped to get round the issue of incomplete support under ATI cards. --- include/osg/Texture | 10 ++++++++-- src/osg/Texture.cpp | 20 ++++++++++++++++---- src/osg/Texture1D.cpp | 5 ++++- src/osg/Texture3D.cpp | 4 ++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/include/osg/Texture b/include/osg/Texture index 6dbdba59c..9b8388161 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -480,7 +480,12 @@ class OSG_EXPORT Texture : public osg::StateAttribute bool isClientStorageSupported() const { return _isClientStorageSupported; } - bool isNonPowerOfTwoTextureSupported() const { return _isNonPowerOfTwoTextureSupported; } + bool isNonPowerOfTwoTextureSupported(GLenum filter) const + { + return (filter==GL_LINEAR || filter==GL_NEAREST) ? + _isNonPowerOfTwoTextureNonMipMappedSupported : + _isNonPowerOfTwoTextureMipMappedSupported; + } protected: @@ -497,7 +502,8 @@ class OSG_EXPORT Texture : public osg::StateAttribute bool _isShadowSupported; bool _isShadowAmbientSupported; bool _isClientStorageSupported; - bool _isNonPowerOfTwoTextureSupported; + bool _isNonPowerOfTwoTextureMipMappedSupported; + bool _isNonPowerOfTwoTextureNonMipMappedSupported; GLint _maxTextureSize; GLint _numTextureUnits; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 946695c47..8c76cc337 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -713,7 +713,7 @@ void Texture::computeRequiredTextureDimensions(State& state, const osg::Image& i int width,height; - if( !_resizeNonPowerOfTwoHint && extensions->isNonPowerOfTwoTextureSupported() ) + if( !_resizeNonPowerOfTwoHint && extensions->isNonPowerOfTwoTextureSupported(_min_filter) ) { width = image.s(); height = image.t(); @@ -1286,7 +1286,8 @@ Texture::Extensions::Extensions(const Extensions& rhs): _isClientStorageSupported = rhs._isClientStorageSupported; - _isNonPowerOfTwoTextureSupported = rhs._isNonPowerOfTwoTextureSupported; + _isNonPowerOfTwoTextureMipMappedSupported = rhs._isNonPowerOfTwoTextureMipMappedSupported; + _isNonPowerOfTwoTextureNonMipMappedSupported = rhs._isNonPowerOfTwoTextureNonMipMappedSupported; } void Texture::Extensions::lowestCommonDenominator(const Extensions& rhs) @@ -1315,12 +1316,15 @@ void Texture::Extensions::lowestCommonDenominator(const Extensions& rhs) if (!rhs._isClientStorageSupported) _isClientStorageSupported = false; - if (!rhs._isNonPowerOfTwoTextureSupported) _isNonPowerOfTwoTextureSupported = false; + if (!rhs._isNonPowerOfTwoTextureMipMappedSupported) _isNonPowerOfTwoTextureMipMappedSupported = false; + if (!rhs._isNonPowerOfTwoTextureNonMipMappedSupported) _isNonPowerOfTwoTextureNonMipMappedSupported = false; } void Texture::Extensions::setupGLExtensions(unsigned int contextID) { float glVersion = atof( (const char *)glGetString( GL_VERSION ) ); + const char* renderer = (const char*) glGetString(GL_RENDERER); + std::string rendererString(renderer ? renderer : ""); _isMultiTexturingSupported = ( glVersion >= 1.3 ) || isGLExtensionSupported(contextID,"GL_ARB_multitexture") || @@ -1344,9 +1348,17 @@ void Texture::Extensions::setupGLExtensions(unsigned int contextID) _isClientStorageSupported = isGLExtensionSupported(contextID,"GL_APPLE_client_storage"); - _isNonPowerOfTwoTextureSupported = ( glVersion >= 2.0 ) || + _isNonPowerOfTwoTextureNonMipMappedSupported = ( glVersion >= 2.0 ) || isGLExtensionSupported(contextID,"GL_ARB_texture_non_power_of_two"); + _isNonPowerOfTwoTextureMipMappedSupported = _isNonPowerOfTwoTextureNonMipMappedSupported; + + if (rendererString.find("Radeon")!=std::string::npos) + { + _isNonPowerOfTwoTextureMipMappedSupported = false; + osg::notify(osg::INFO)<<"Disabling _isNonPowerOfTwoTextureMipMappedSupported for ATI hardware."<isNonPowerOfTwoTextureSupported() || inwidth > extensions->maxTextureSize() ) + if( _resizeNonPowerOfTwoHint || !extensions->isNonPowerOfTwoTextureSupported(_min_filter) || inwidth > extensions->maxTextureSize() ) + { + // this is not thread safe... should really create local image data and rescale to that as per Texture2D. image->ensureValidSizeForTexturing(extensions->maxTextureSize()); + } glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index b57e47892..82a46d5be 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -101,7 +101,7 @@ void Texture3D::computeRequiredTextureDimensions(State& state, const osg::Image& int width,height,depth; - if( !_resizeNonPowerOfTwoHint && texExtensions->isNonPowerOfTwoTextureSupported() ) + if( !_resizeNonPowerOfTwoHint && texExtensions->isNonPowerOfTwoTextureSupported(_min_filter) ) { width = image.s(); height = image.t(); @@ -278,7 +278,7 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz } //Rescale if resize hint is set or NPOT not supported or dimensions exceed max size - if( _resizeNonPowerOfTwoHint || !texExtensions->isNonPowerOfTwoTextureSupported() + if( _resizeNonPowerOfTwoHint || !texExtensions->isNonPowerOfTwoTextureSupported(_min_filter) || inwidth > extensions->maxTexture3DSize() || inheight > extensions->maxTexture3DSize() || indepth > extensions->maxTexture3DSize() )