Moved the modified tag's from osg::Texture into the osg::Texture1D,2D,3D and

CubeMap classes.
This commit is contained in:
Robert Osfield 2003-04-07 09:46:06 +00:00
parent 98f691f693
commit 7e58786b11
10 changed files with 90 additions and 34 deletions

View File

@ -201,11 +201,6 @@ class SG_EXPORT Texture : public osg::StateAttribute
return _handleList[contextID]; 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 inline unsigned int& getTextureParameterDirty(unsigned int contextID) const
{ {
@ -327,9 +322,6 @@ class SG_EXPORT Texture : public osg::StateAttribute
typedef buffered_value<GLuint> TextureNameList; typedef buffered_value<GLuint> TextureNameList;
mutable TextureNameList _handleList; mutable TextureNameList _handleList;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
typedef buffered_value<unsigned int> TexParameterDirtyList; typedef buffered_value<unsigned int> TexParameterDirtyList;
mutable TexParameterDirtyList _texParametersDirtyList; mutable TexParameterDirtyList _texParametersDirtyList;

View File

@ -50,6 +50,12 @@ class SG_EXPORT Texture1D : public Texture
/** Get the const texture image. */ /** Get the const texture image. */
inline const Image* getImage() const { return _image.get(); } 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 /** Set the texture width and height. If width or height are zero then
* the repsective size value is calculated from the source image sizes. */ * the repsective size value is calculated from the source image sizes. */
@ -128,6 +134,11 @@ class SG_EXPORT Texture1D : public Texture
mutable GLsizei _numMimpmapLevels; mutable GLsizei _numMimpmapLevels;
ref_ptr<SubloadCallback> _subloadCallback; ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
}; };
} }

View File

@ -50,6 +50,11 @@ class SG_EXPORT Texture2D : public Texture
/** Get the const texture image. */ /** Get the const texture image. */
inline const Image* getImage() const { return _image.get(); } 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 /** Set the texture width and height. If width or height are zero then
* the repsective size value is calculated from the source image sizes. */ * the repsective size value is calculated from the source image sizes. */
@ -132,6 +137,10 @@ class SG_EXPORT Texture2D : public Texture
mutable GLsizei _numMimpmapLevels; mutable GLsizei _numMimpmapLevels;
ref_ptr<SubloadCallback> _subloadCallback; ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
}; };
} }

View File

@ -48,6 +48,11 @@ class SG_EXPORT Texture3D : public Texture
/** Get the const texture image. */ /** Get the const texture image. */
inline const Image* getImage() const { return _image.get(); } 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 /** Set the texture width and height. If width or height are zero then
* the repsective size value is calculated from the source image sizes. */ * the repsective size value is calculated from the source image sizes. */
@ -174,6 +179,10 @@ class SG_EXPORT Texture3D : public Texture
mutable GLsizei _numMimpmapLevels; mutable GLsizei _numMimpmapLevels;
ref_ptr<SubloadCallback> _subloadCallback; ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag;
}; };
} }

View File

@ -61,6 +61,11 @@ class SG_EXPORT TextureCubeMap : public Texture
/** Get the const texture image for specified face. */ /** Get the const texture image for specified face. */
const Image* getImage(Face) const; 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 /** Set the texture width and height. If width or height are zero then
* the repsective size value is calculated from the source image sizes. */ * the repsective size value is calculated from the source image sizes. */
@ -159,6 +164,9 @@ class SG_EXPORT TextureCubeMap : public Texture
mutable GLsizei _numMimpmapLevels; mutable GLsizei _numMimpmapLevels;
ref_ptr<SubloadCallback> _subloadCallback; ref_ptr<SubloadCallback> _subloadCallback;
typedef buffered_value<unsigned int> ImageModifiedTag;
mutable ImageModifiedTag _modifiedTag[6];
}; };
} }

View File

@ -379,16 +379,11 @@ void Texture::applyTexImage2D_load(GLenum target, const Image* image, State& sta
bool generateMipMapSupported = extensions->isGenerateMipMapSupported(); 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. // compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat(); computeInternalFormat();
// select the internalFormat required for the texture. // 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()); glPixelStorei(GL_UNPACK_ALIGNMENT,image->getPacking());
@ -592,11 +587,6 @@ void Texture::applyTexImage2D_subload(GLenum target, const Image* image, State&
bool generateMipMapSupported = extensions->isGenerateMipMapSupported(); 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. // compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat(); computeInternalFormat();

View File

@ -80,6 +80,8 @@ void Texture1D::setImage(Image* image)
dirtyTextureObject(); dirtyTextureObject();
_image = image; _image = image;
_modifiedTag.setAllElementsTo(0);
} }
@ -106,6 +108,9 @@ void Texture1D::apply(State& state) const
else if (_image.valid() && getModifiedTag(contextID) != _image->getModifiedTag()) else if (_image.valid() && getModifiedTag(contextID) != _image->getModifiedTag())
{ {
applyTexImage1D(GL_TEXTURE_1D,_image.get(),state, _textureWidth, _numMimpmapLevels); 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); 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 // in theory the following line is redundent, but in practice
// have found that the first frame drawn doesn't apply the textures // have found that the first frame drawn doesn't apply the textures
// unless a second bind is called?!! // 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 unsigned int contextID = state.getContextID();
const Extensions* extensions = getExtensions(contextID,true); 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. // compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat(); computeInternalFormat();

View File

@ -80,13 +80,8 @@ int Texture2D::compare(const StateAttribute& sa) const
void Texture2D::setImage(Image* image) void Texture2D::setImage(Image* image)
{ {
// delete old texture objects.
// dirtyTextureObject();
// replace dirtyTextureObject() with reseting the modified tag.
_modifiedTag.setAllElementsTo(0);
_image = image; _image = image;
_modifiedTag.setAllElementsTo(0);
} }
@ -114,6 +109,10 @@ void Texture2D::apply(State& state) const
{ {
applyTexImage2D_subload(GL_TEXTURE_2D,_image.get(),state, applyTexImage2D_subload(GL_TEXTURE_2D,_image.get(),state,
_textureWidth, _textureHeight, _numMimpmapLevels); _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, applyTexImage2D_load(GL_TEXTURE_2D,_image.get(),state,
_textureWidth, _textureHeight, _numMimpmapLevels); _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 // in theory the following line is redundent, but in practice
// have found that the first frame drawn doesn't apply the textures // have found that the first frame drawn doesn't apply the textures
// unless a second bind is called?!! // unless a second bind is called?!!

View File

@ -88,6 +88,8 @@ void Texture3D::setImage(Image* image)
// delete old texture objects. // delete old texture objects.
dirtyTextureObject(); dirtyTextureObject();
_modifiedTag.setAllElementsTo(0);
_image = image; _image = image;
} }
@ -123,6 +125,9 @@ void Texture3D::apply(State& state) const
else if (_image.get() && getModifiedTag(contextID) != _image->getModifiedTag()) else if (_image.get() && getModifiedTag(contextID) != _image->getModifiedTag())
{ {
applyTexImage3D(GL_TEXTURE_3D,_image.get(),state, _textureWidth, _textureHeight, _textureDepth,_numMimpmapLevels); 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); 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 // in theory the following line is redundent, but in practice
// have found that the first frame drawn doesn't apply the textures // have found that the first frame drawn doesn't apply the textures
// unless a second bind is called?!! // unless a second bind is called?!!
@ -181,12 +189,7 @@ void Texture3D::applyTexImage3D(GLenum target, Image* image, State& state, GLsiz
// current OpenGL context. // current OpenGL context.
const unsigned int contextID = state.getContextID(); const unsigned int contextID = state.getContextID();
const Extensions* extensions = getExtensions(contextID,true); 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. // compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat(); computeInternalFormat();

View File

@ -107,6 +107,13 @@ TextureCubeMap::TextureCubeMap(const TextureCubeMap& text,const CopyOp& copyop):
_images[4] = copyop(text._images[4].get()); _images[4] = copyop(text._images[4].get());
_images[5] = copyop(text._images[5].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(); dirtyTextureObject();
_images[face] = image; _images[face] = image;
_modifiedTag[face].setAllElementsTo(0);
} }
Image* TextureCubeMap::getImage(Face face) Image* TextureCubeMap::getImage(Face face)
@ -211,6 +219,15 @@ void TextureCubeMap::apply(State& state) const
} }
else 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); 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 // in theory the following line is redundent, but in practice
// have found that the first frame drawn doesn't apply the textures // have found that the first frame drawn doesn't apply the textures