diff --git a/include/osg/Texture b/include/osg/Texture index 29b0586e6..a8b4aec39 100644 --- a/include/osg/Texture +++ b/include/osg/Texture @@ -201,11 +201,6 @@ class SG_EXPORT Texture : public osg::StateAttribute return _handleList[contextID]; } - inline unsigned int& getModifiedTag(unsigned int contextID) const - { - // get the modified tag for the current contextID. - return _modifiedTag[contextID]; - } inline unsigned int& getTextureParameterDirty(unsigned int contextID) const { @@ -327,9 +322,6 @@ class SG_EXPORT Texture : public osg::StateAttribute typedef buffered_value TextureNameList; mutable TextureNameList _handleList; - typedef buffered_value ImageModifiedTag; - mutable ImageModifiedTag _modifiedTag; - typedef buffered_value TexParameterDirtyList; mutable TexParameterDirtyList _texParametersDirtyList; diff --git a/include/osg/Texture1D b/include/osg/Texture1D index 57687275a..c90784c0b 100644 --- a/include/osg/Texture1D +++ b/include/osg/Texture1D @@ -50,6 +50,12 @@ class SG_EXPORT Texture1D : public Texture /** Get the const texture image. */ inline const Image* getImage() const { return _image.get(); } + inline unsigned int& getModifiedTag(unsigned int contextID) const + { + // get the modified tag for the current contextID. + return _modifiedTag[contextID]; + } + /** Set the texture width and height. If width or height are zero then * the repsective size value is calculated from the source image sizes. */ @@ -128,6 +134,11 @@ class SG_EXPORT Texture1D : public Texture mutable GLsizei _numMimpmapLevels; ref_ptr _subloadCallback; + + typedef buffered_value ImageModifiedTag; + mutable ImageModifiedTag _modifiedTag; + + }; } diff --git a/include/osg/Texture2D b/include/osg/Texture2D index 2d60f360c..d8f4fa4ed 100644 --- a/include/osg/Texture2D +++ b/include/osg/Texture2D @@ -50,6 +50,11 @@ class SG_EXPORT Texture2D : public Texture /** Get the const texture image. */ inline const Image* getImage() const { return _image.get(); } + inline unsigned int& getModifiedTag(unsigned int contextID) const + { + // get the modified tag for the current contextID. + return _modifiedTag[contextID]; + } /** Set the texture width and height. If width or height are zero then * the repsective size value is calculated from the source image sizes. */ @@ -132,6 +137,10 @@ class SG_EXPORT Texture2D : public Texture mutable GLsizei _numMimpmapLevels; ref_ptr _subloadCallback; + + typedef buffered_value ImageModifiedTag; + mutable ImageModifiedTag _modifiedTag; + }; } diff --git a/include/osg/Texture3D b/include/osg/Texture3D index a5056379c..8a302e1f2 100644 --- a/include/osg/Texture3D +++ b/include/osg/Texture3D @@ -48,6 +48,11 @@ class SG_EXPORT Texture3D : public Texture /** Get the const texture image. */ inline const Image* getImage() const { return _image.get(); } + inline unsigned int& getModifiedTag(unsigned int contextID) const + { + // get the modified tag for the current contextID. + return _modifiedTag[contextID]; + } /** Set the texture width and height. If width or height are zero then * the repsective size value is calculated from the source image sizes. */ @@ -174,6 +179,10 @@ class SG_EXPORT Texture3D : public Texture mutable GLsizei _numMimpmapLevels; ref_ptr _subloadCallback; + + typedef buffered_value ImageModifiedTag; + mutable ImageModifiedTag _modifiedTag; + }; } diff --git a/include/osg/TextureCubeMap b/include/osg/TextureCubeMap index 8fa5587b9..63ea6babe 100644 --- a/include/osg/TextureCubeMap +++ b/include/osg/TextureCubeMap @@ -61,6 +61,11 @@ class SG_EXPORT TextureCubeMap : public Texture /** Get the const texture image for specified face. */ const Image* getImage(Face) const; + inline unsigned int& getModifiedTag(Face face,unsigned int contextID) const + { + // get the modified tag for the current contextID. + return _modifiedTag[face][contextID]; + } /** Set the texture width and height. If width or height are zero then * the repsective size value is calculated from the source image sizes. */ @@ -159,6 +164,9 @@ class SG_EXPORT TextureCubeMap : public Texture mutable GLsizei _numMimpmapLevels; ref_ptr _subloadCallback; + + typedef buffered_value ImageModifiedTag; + mutable ImageModifiedTag _modifiedTag[6]; }; } diff --git a/src/osg/Texture.cpp b/src/osg/Texture.cpp index 2a7b56deb..e4694f801 100644 --- a/src/osg/Texture.cpp +++ b/src/osg/Texture.cpp @@ -379,16 +379,11 @@ void Texture::applyTexImage2D_load(GLenum target, const Image* image, State& sta bool generateMipMapSupported = extensions->isGenerateMipMapSupported(); - - // update the modified tag to show that it is upto date. - getModifiedTag(contextID) = image->getModifiedTag(); - - // compute the internal texture format, this set the _internalFormat to an appropriate value. computeInternalFormat(); // select the internalFormat required for the texture. - bool compressed_image = isCompressedInternalFormat((GLenum)image->getPixelFormat()); +; bool compressed_image = isCompressedInternalFormat((GLenum)image->getPixelFormat()); glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking()); @@ -592,11 +587,6 @@ void Texture::applyTexImage2D_subload(GLenum target, const Image* image, State& bool generateMipMapSupported = extensions->isGenerateMipMapSupported(); - - // update the modified tag to show that it is upto date. - getModifiedTag(contextID) = image->getModifiedTag(); - - // compute the internal texture format, this set the _internalFormat to an appropriate value. computeInternalFormat(); diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index 9ac7ece34..4b124d96d 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -80,6 +80,8 @@ void Texture1D::setImage(Image* image) dirtyTextureObject(); _image = image; + _modifiedTag.setAllElementsTo(0); + } @@ -106,6 +108,9 @@ void Texture1D::apply(State& state) const else if (_image.valid() && getModifiedTag(contextID) != _image->getModifiedTag()) { applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMimpmapLevels); + + // update the modified tag to show that it is upto date. + getModifiedTag(contextID) = _image->getModifiedTag(); } } @@ -136,6 +141,10 @@ void Texture1D::apply(State& state) const applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMimpmapLevels); + // update the modified tag to show that it is upto date. + getModifiedTag(contextID) = _image->getModifiedTag(); + + // in theory the following line is redundent, but in practice // have found that the first frame drawn doesn't apply the textures // unless a second bind is called?!! @@ -165,9 +174,6 @@ void Texture1D::applyTexImage1D(GLenum target, Image* image, State& state, GLsiz const unsigned int contextID = state.getContextID(); const Extensions* extensions = getExtensions(contextID,true); - // update the modified tag to show that it is upto date. - getModifiedTag(contextID) = image->getModifiedTag(); - // compute the internal texture format, this set the _internalFormat to an appropriate value. computeInternalFormat(); diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index ca96f940e..628291705 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -80,13 +80,8 @@ int Texture2D::compare(const StateAttribute& sa) const void Texture2D::setImage(Image* image) { - // delete old texture objects. - // dirtyTextureObject(); - - // replace dirtyTextureObject() with reseting the modified tag. - _modifiedTag.setAllElementsTo(0); - _image = image; + _modifiedTag.setAllElementsTo(0); } @@ -114,6 +109,10 @@ void Texture2D::apply(State& state) const { applyTexImage2D_subload(GL_TEXTURE_2D,_image.get(),state, _textureWidth, _textureHeight, _numMimpmapLevels); + + // update the modified tag to show that it is upto date. + getModifiedTag(contextID) = _image->getModifiedTag(); + } } @@ -145,6 +144,9 @@ void Texture2D::apply(State& state) const applyTexImage2D_load(GL_TEXTURE_2D,_image.get(),state, _textureWidth, _textureHeight, _numMimpmapLevels); + // update the modified tag to show that it is upto date. + getModifiedTag(contextID) = _image->getModifiedTag(); + // in theory the following line is redundent, but in practice // have found that the first frame drawn doesn't apply the textures // unless a second bind is called?!! diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 5dd67d08c..a65941af9 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -88,6 +88,8 @@ void Texture3D::setImage(Image* image) // delete old texture objects. dirtyTextureObject(); + _modifiedTag.setAllElementsTo(0); + _image = image; } @@ -123,6 +125,9 @@ void Texture3D::apply(State& state) const else if (_image.get() && getModifiedTag(contextID) != _image->getModifiedTag()) { applyTexImage3D(GL_TEXTURE_3D,_image.get(),state, _textureWidth, _textureHeight, _textureDepth,_numMimpmapLevels); + + // update the modified tag to show that it is upto date. + getModifiedTag(contextID) = _image->getModifiedTag(); } } @@ -153,6 +158,9 @@ void Texture3D::apply(State& state) const applyTexImage3D(GL_TEXTURE_3D,_image.get(),state, _textureWidth, _textureHeight, _textureDepth,_numMimpmapLevels); + // update the modified tag to show that it is upto date. + getModifiedTag(contextID) = _image->getModifiedTag(); + // in theory the following line is redundent, but in practice // have found that the first frame drawn doesn't apply the textures // unless a second bind is called?!! @@ -181,12 +189,7 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz // current OpenGL context. const unsigned int contextID = state.getContextID(); - const Extensions* extensions = getExtensions(contextID,true); - - - // update the modified tag to show that it is upto date. - getModifiedTag(contextID) = image->getModifiedTag(); - + const Extensions* extensions = getExtensions(contextID,true); // compute the internal texture format, this set the _internalFormat to an appropriate value. computeInternalFormat(); diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index b7fbf43ee..82baa86b0 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -107,6 +107,13 @@ TextureCubeMap::TextureCubeMap(const TextureCubeMap& text,const CopyOp& copyop): _images[4] = copyop(text._images[4].get()); _images[5] = copyop(text._images[5].get()); + _modifiedTag[0].setAllElementsTo(0); + _modifiedTag[1].setAllElementsTo(0); + _modifiedTag[2].setAllElementsTo(0); + _modifiedTag[3].setAllElementsTo(0); + _modifiedTag[4].setAllElementsTo(0); + _modifiedTag[5].setAllElementsTo(0); + } @@ -160,6 +167,7 @@ void TextureCubeMap::setImage( Face face, Image* image) { dirtyTextureObject(); _images[face] = image; + _modifiedTag[face].setAllElementsTo(0); } Image* TextureCubeMap::getImage(Face face) @@ -211,6 +219,15 @@ void TextureCubeMap::apply(State& state) const } else { + for (int n=0; n<6; n++) + { + osg::Image* image = _images[n].get(); + if (image && getModifiedTag((Face)n,contextID) != image->getModifiedTag()) + { + applyTexImage2D_subload( faceTarget[n], _images[n].get(), state, _textureWidth, _textureHeight, _numMimpmapLevels); + getModifiedTag((Face)n,contextID) = image->getModifiedTag(); + } + } } } @@ -245,6 +262,15 @@ void TextureCubeMap::apply(State& state) const applyTexImage2D_load( faceTarget[n], _images[n].get(), state, _textureWidth, _textureHeight, _numMimpmapLevels); } + for (int n=0; n<6; n++) + { + osg::Image* image = _images[n].get(); + if (image) + { + applyTexImage2D_load( faceTarget[n], _images[n].get(), state, _textureWidth, _textureHeight, _numMimpmapLevels); + getModifiedTag((Face)n,contextID) = image->getModifiedTag(); + } + } // in theory the following line is redundent, but in practice // have found that the first frame drawn doesn't apply the textures