diff --git a/src/osg/Texture1D.cpp b/src/osg/Texture1D.cpp index 38327b07d..eb07a081a 100644 --- a/src/osg/Texture1D.cpp +++ b/src/osg/Texture1D.cpp @@ -160,10 +160,10 @@ void Texture1D::apply(State& state) const { textureObject->bind(); - if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_1D,state); - if (_subloadCallback.valid()) { + applyTexParameters(GL_TEXTURE_1D,state); + _subloadCallback->subload(*this,state); } else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) @@ -171,9 +171,14 @@ void Texture1D::apply(State& state) const // update the modified count to show that it is up to date. getModifiedCount(contextID) = _image->getModifiedCount(); + applyTexParameters(GL_TEXTURE_1D,state); + applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMipmapLevels); } + if (getTextureParameterDirty(state.getContextID())) + applyTexParameters(GL_TEXTURE_1D,state); + } else if (_subloadCallback.valid()) { diff --git a/src/osg/Texture2D.cpp b/src/osg/Texture2D.cpp index 1090f64e1..06ca1aed3 100644 --- a/src/osg/Texture2D.cpp +++ b/src/osg/Texture2D.cpp @@ -193,11 +193,10 @@ void Texture2D::apply(State& state) const { textureObject->bind(); - if (getTextureParameterDirty(state.getContextID())) - applyTexParameters(GL_TEXTURE_2D,state); - if (_subloadCallback.valid()) { + applyTexParameters(GL_TEXTURE_2D,state); + _subloadCallback->subload(*this,state); } else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount()) @@ -205,6 +204,8 @@ void Texture2D::apply(State& state) const // update the modified tag to show that it is up to date. getModifiedCount(contextID) = _image->getModifiedCount(); + applyTexParameters(GL_TEXTURE_2D,state); + applyTexImage2D_subload(state,GL_TEXTURE_2D,_image.get(), _textureWidth, _textureHeight, _internalFormat, _numMipmapLevels); } @@ -213,6 +214,9 @@ void Texture2D::apply(State& state) const _readPBuffer->bindPBufferToTexture(GL_FRONT); } + if (getTextureParameterDirty(state.getContextID())) + applyTexParameters(GL_TEXTURE_2D,state); + } else if (_subloadCallback.valid()) { diff --git a/src/osg/Texture2DArray.cpp b/src/osg/Texture2DArray.cpp index ff16ba66d..84a1cbd78 100644 --- a/src/osg/Texture2DArray.cpp +++ b/src/osg/Texture2DArray.cpp @@ -278,16 +278,16 @@ void Texture2DArray::apply(State& state) const // bind texture object textureObject->bind(); - // if texture parameters changed, then reset them - if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state); - // if subload is specified, then use it to subload the images to GPU memory if (_subloadCallback.valid()) { + applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state); + _subloadCallback->subload(*this,state); } else { + bool applyParameters = true; GLsizei n = 0; for(Images::const_iterator itr = _images.begin(); itr != _images.end(); @@ -299,13 +299,23 @@ void Texture2DArray::apply(State& state) const if (getModifiedCount(n,contextID) != image->getModifiedCount()) { getModifiedCount(n,contextID) = image->getModifiedCount(); + + if (applyParameters) + { + applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state); + applyParameters = false; + } + applyTexImage2DArray_subload(state, image, n, _textureWidth, _textureHeight, image->r(), _internalFormat, _numMipmapLevels); } n += image->r(); } } - } + } + // if texture parameters changed, then reset them + if (getTextureParameterDirty(state.getContextID())) + applyTexParameters(GL_TEXTURE_2D_ARRAY_EXT,state); } // there is no texture object, but exists a subload callback, so use it to upload images diff --git a/src/osg/Texture3D.cpp b/src/osg/Texture3D.cpp index 5294b5a38..1fc2f26c1 100644 --- a/src/osg/Texture3D.cpp +++ b/src/osg/Texture3D.cpp @@ -241,10 +241,10 @@ void Texture3D::apply(State& state) const // we have a valid image textureObject->bind(); - if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_3D,state); - if (_subloadCallback.valid()) { + applyTexParameters(GL_TEXTURE_3D,state); + _subloadCallback->subload(*this,state); } else if (_image.get() && getModifiedCount(contextID) != _image->getModifiedCount()) @@ -252,11 +252,16 @@ void Texture3D::apply(State& state) const // update the modified count to show that it is up to date. getModifiedCount(contextID) = _image->getModifiedCount(); + applyTexParameters(GL_TEXTURE_3D,state); + computeRequiredTextureDimensions(state,*_image,_textureWidth, _textureHeight, _textureDepth,_numMipmapLevels); applyTexImage3D(GL_TEXTURE_3D,_image.get(),state, _textureWidth, _textureHeight, _textureDepth,_numMipmapLevels); } + if (getTextureParameterDirty(state.getContextID())) + applyTexParameters(GL_TEXTURE_3D,state); + } else if (_subloadCallback.valid()) { diff --git a/src/osg/TextureCubeMap.cpp b/src/osg/TextureCubeMap.cpp index 6618958a9..ed43d2b2c 100644 --- a/src/osg/TextureCubeMap.cpp +++ b/src/osg/TextureCubeMap.cpp @@ -233,24 +233,32 @@ void TextureCubeMap::apply(State& state) const { textureObject->bind(); - if (getTextureParameterDirty(state.getContextID())) applyTexParameters(GL_TEXTURE_CUBE_MAP,state); - if (_subloadCallback.valid()) { + applyTexParameters(GL_TEXTURE_CUBE_MAP,state); + _subloadCallback->subload(*this,state); } else { + bool applyParameters = true; for (int n=0; n<6; n++) { const osg::Image* image = _images[n].get(); if (image && getModifiedCount((Face)n,contextID) != image->getModifiedCount()) { getModifiedCount((Face)n,contextID) = image->getModifiedCount(); + if (applyParameters) + { + applyTexParameters(GL_TEXTURE_CUBE_MAP,state); + applyParameters = false; + } applyTexImage2D_subload( state, faceTarget[n], _images[n].get(), _textureWidth, _textureHeight, _internalFormat, _numMipmapLevels); } } } + if (getTextureParameterDirty(state.getContextID())) + applyTexParameters(GL_TEXTURE_CUBE_MAP,state); } else if (_subloadCallback.valid())