diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index e5dbef39a..e6eb7df4d 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -131,7 +131,26 @@ void Texture1D::apply(State& state) const // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID); - if (textureObject != 0) + if (textureObject) + { + if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) + { + // compute the internal texture format, this set the _internalFormat to an appropriate value. + computeInternalFormat(); + + GLsizei new_width = _image->s(); + GLsizei new_numMipmapLevels = _numMipmapLevels; + + if (!textureObject->match(GL_TEXTURE_1D, new_numMipmapLevels, _internalFormat, new_width, 1, 1, _borderWidth)) + { + Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get()); + _textureObjectBuffer[contextID] = 0; + textureObject = 0; + } + } + } + + if (textureObject) { textureObject->bind(); diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index 3a6da201a..7b00453a1 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -225,8 +225,30 @@ void Texture2DArray::apply(State& state) const // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID); - // if we already have an texture object, then - if (textureObject != 0) + if (textureObject && _textureDepth>0) + { + const osg::Image* image = _images[0].get(); + if (image && getModifiedCount(0, contextID) != image->getModifiedCount()) + { + // compute the internal texture format, this set the _internalFormat to an appropriate value. + computeInternalFormat(); + + GLsizei new_width, new_height, new_numMipmapLevels; + + // compute the dimensions of the texture. + computeRequiredTextureDimensions(state, *image, new_width, new_height, new_numMipmapLevels); + + if (!textureObject->match(GL_TEXTURE_2D_ARRAY_EXT, new_numMipmapLevels, _internalFormat, new_width, new_height, 1, _borderWidth)) + { + Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get()); + _textureObjectBuffer[contextID] = 0; + textureObject = 0; + } + } + } + + // if we already have an texture object, then + if (textureObject) { // bind texture object textureObject->bind(); diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 0d75c0b5a..f46c2dcb4 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -210,7 +210,28 @@ void Texture3D::apply(State& state) const // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID); - + + if (textureObject) + { + if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) + { + // compute the internal texture format, this set the _internalFormat to an appropriate value. + computeInternalFormat(); + + GLsizei new_width, new_height, new_depth, new_numMipmapLevels; + + // compute the dimensions of the texture. + computeRequiredTextureDimensions(state, *_image, new_width, new_height, new_depth, new_numMipmapLevels); + + if (!textureObject->match(GL_TEXTURE_3D, new_numMipmapLevels, _internalFormat, new_width, new_height, new_depth, _borderWidth)) + { + Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get()); + _textureObjectBuffer[contextID] = 0; + textureObject = 0; + } + } + } + if (textureObject) { // we have a valid image diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index 45d4385b6..666185905 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -209,7 +209,29 @@ void TextureCubeMap::apply(State& state) const // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID); - if (textureObject != 0) + if (textureObject) + { + const osg::Image* image = _images[0].get(); + if (image && getModifiedCount(0, contextID) != image->getModifiedCount()) + { + // compute the internal texture format, this set the _internalFormat to an appropriate value. + computeInternalFormat(); + + GLsizei new_width, new_height, new_numMipmapLevels; + + // compute the dimensions of the texture. + computeRequiredTextureDimensions(state, *image, new_width, new_height, new_numMipmapLevels); + + if (!textureObject->match(GL_TEXTURE_CUBE_MAP, new_numMipmapLevels, _internalFormat, new_width, new_height, 1, _borderWidth)) + { + Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get()); + _textureObjectBuffer[contextID] = 0; + textureObject = 0; + } + } + } + + if (textureObject) { textureObject->bind(); diff --git a/src/osg/TextureRectangle.cpp b/src/osg/TextureRectangle.cpp index 1e3eac392..fa44f6a1a 100644 --- a/src/osg/TextureRectangle.cpp +++ b/src/osg/TextureRectangle.cpp @@ -170,12 +170,32 @@ void TextureRectangle::apply(State& state) const // get the texture object for the current contextID. TextureObject* textureObject = getTextureObject(contextID); - - - if (textureObject != 0) - { + if (textureObject) + { + if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) + { + // compute the internal texture format, this set the _internalFormat to an appropriate value. + computeInternalFormat(); + + GLsizei new_width, new_height, new_numMipmapLevels; + + // compute the dimensions of the texture. + computeRequiredTextureDimensions(state, *_image, new_width, new_height, new_numMipmapLevels); + + if (!textureObject->match(GL_TEXTURE_RECTANGLE, new_numMipmapLevels, _internalFormat, new_width, new_height, 1, _borderWidth)) + { + Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get()); + _textureObjectBuffer[contextID] = 0; + textureObject = 0; + } + } + } + + if (textureObject) + { textureObject->bind(); + if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_RECTANGLE, state);