diff --git a/include/osg/Texture b/include/osg/Texture index e5541ed4b..dc94a3fe0 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -109,7 +109,7 @@ class SG_EXPORT Texture : public osg::StateAttribute /** Sets the border color for this texture. Makes difference only if * wrap mode is CLAMP_TO_BORDER */ - void setBorderColor(const Vec4& color) { _borderColor = color; _texParametersDirty = true; } + void setBorderColor(const Vec4& color) { _borderColor = color; dirtyTextureParameters(); } const Vec4& getBorderColor() const { return _borderColor; } @@ -181,7 +181,7 @@ class SG_EXPORT Texture : public osg::StateAttribute /** Get the handle to the texture object for the current context.*/ /** return the OpenGL texture object for specified context.*/ - inline GLuint& getTextureObject(const uint contextID) const + inline GLuint& getTextureObject(uint contextID) const { // pad out handle list if required. if (_handleList.size()<=contextID) @@ -191,7 +191,7 @@ class SG_EXPORT Texture : public osg::StateAttribute return _handleList[contextID]; } - inline uint& getModifiedTag(const uint contextID) const + inline uint& getModifiedTag(uint contextID) const { // pad out handle list if required. if (_modifiedTag.size()<=contextID) @@ -201,9 +201,21 @@ class SG_EXPORT Texture : public osg::StateAttribute return _modifiedTag[contextID]; } + inline uint& getTextureParameterDity(uint contextID) const + { + // pad out handle list if required. + if (_texParametersDirtyList.size()<=contextID) + _texParametersDirtyList.resize(contextID+1,0); + + // get the dirty flag for the current contextID. + return _texParametersDirtyList[contextID]; + } + /** Force a recompile on next apply() of associated OpenGL texture objects.*/ void dirtyTextureObject(); + /** Force a resetting on next apply() of associated OpenGL texture parameters.*/ + void dirtyTextureParameters(); /** use deleteTextureObject instead of glDeleteTextures to allow @@ -253,6 +265,8 @@ class SG_EXPORT Texture : public osg::StateAttribute typedef std::vector ImageModifiedTag; mutable ImageModifiedTag _modifiedTag; + typedef std::vector TexParameterDirtyList; + mutable TexParameterDirtyList _texParametersDirtyList; WrapMode _wrap_s; WrapMode _wrap_t; @@ -264,10 +278,6 @@ class SG_EXPORT Texture : public osg::StateAttribute Vec4 _borderColor; - // true if apply tex parameters required. - mutable bool _texParametersDirty; - - InternalFormatMode _internalFormatMode; mutable GLint _internalFormat; diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index c6e6010df..a97502982 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -20,12 +20,12 @@ Texture::Texture(): _mag_filter(LINEAR), _maxAnisotropy(1.0f), _borderColor(0.0, 0.0, 0.0, 0.0), - _texParametersDirty(true), _internalFormatMode(USE_IMAGE_DATA_FORMAT), _internalFormat(0) { _handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); _modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); + _texParametersDirtyList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),true); } Texture::Texture(const Texture& text,const CopyOp& copyop): @@ -37,12 +37,12 @@ Texture::Texture(const Texture& text,const CopyOp& copyop): _mag_filter(text._mag_filter), _maxAnisotropy(text._maxAnisotropy), _borderColor(text._borderColor), - _texParametersDirty(false), _internalFormatMode(text._internalFormatMode), _internalFormat(text._internalFormat) { _handleList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); _modifiedTag.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),0); + _texParametersDirtyList.resize(DisplaySettings::instance()->getMaxNumberOfGraphicsContexts(),true); } Texture::~Texture() @@ -70,9 +70,9 @@ void Texture::setWrap(WrapParameter which, WrapMode wrap) { switch( which ) { - case WRAP_S : _wrap_s = wrap; _texParametersDirty = true; break; - case WRAP_T : _wrap_t = wrap; _texParametersDirty = true; break; - case WRAP_R : _wrap_r = wrap; _texParametersDirty = true; break; + case WRAP_S : _wrap_s = wrap; dirtyTextureParameters(); break; + case WRAP_T : _wrap_t = wrap; dirtyTextureParameters(); break; + case WRAP_R : _wrap_r = wrap; dirtyTextureParameters(); break; default : notify(WARN)<<"Error: invalid 'which' passed Texture::setWrap("<<(unsigned int)which<<","<<(unsigned int)wrap<<")"<