Introduced bool Texture2D::textureObjectValid(State) and bool SubloadCallback::textureObjectValid(Texture2D&,State&) method to make it tell Texture2D::apply() whether the texture object is still valid or whether it's no longed valid for the any changes to the image attached to the Texture
This commit is contained in:
parent
0754a78ddb
commit
06509b9769
@ -87,6 +87,12 @@ class OSG_EXPORT Texture2D : public Texture
|
|||||||
class OSG_EXPORT SubloadCallback : public Referenced
|
class OSG_EXPORT SubloadCallback : public Referenced
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
virtual bool textureObjectValid(const Texture2D& texture, State& state) const
|
||||||
|
{
|
||||||
|
return texture.textureObjectValid(state);
|
||||||
|
}
|
||||||
|
|
||||||
virtual TextureObject* generateTextureObject(const Texture2D& texture, State& state) const
|
virtual TextureObject* generateTextureObject(const Texture2D& texture, State& state) const
|
||||||
{
|
{
|
||||||
return osg::Texture::generateTextureObject(&texture, state.getContextID(), GL_TEXTURE_2D);
|
return osg::Texture::generateTextureObject(&texture, state.getContextID(), GL_TEXTURE_2D);
|
||||||
@ -132,6 +138,8 @@ class OSG_EXPORT Texture2D : public Texture
|
|||||||
* compiled, create the texture mipmap levels. */
|
* compiled, create the texture mipmap levels. */
|
||||||
virtual void apply(State& state) const;
|
virtual void apply(State& state) const;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected :
|
protected :
|
||||||
|
|
||||||
virtual ~Texture2D();
|
virtual ~Texture2D();
|
||||||
@ -139,6 +147,10 @@ class OSG_EXPORT Texture2D : public Texture
|
|||||||
virtual void computeInternalFormat() const;
|
virtual void computeInternalFormat() const;
|
||||||
void allocateMipmap(State& state) const;
|
void allocateMipmap(State& state) const;
|
||||||
|
|
||||||
|
/** Return true of the TextureObject assigned to the context associate with osg::State object is valid.*/
|
||||||
|
bool textureObjectValid(State& state) const;
|
||||||
|
|
||||||
|
friend class SubloadCallback;
|
||||||
|
|
||||||
ref_ptr<Image> _image;
|
ref_ptr<Image> _image;
|
||||||
|
|
||||||
|
@ -125,6 +125,25 @@ void Texture2D::setImage(Image* image)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Texture2D::textureObjectValid(State& state) const
|
||||||
|
{
|
||||||
|
TextureObject* textureObject = getTextureObject(state.getContextID());
|
||||||
|
if (!textureObject) return false;
|
||||||
|
|
||||||
|
// return true if image isn't assigned as we won't be override the value.
|
||||||
|
if (!_image) return true;
|
||||||
|
|
||||||
|
// 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);
|
||||||
|
|
||||||
|
return textureObject->match(GL_TEXTURE_2D, new_numMipmapLevels, _internalFormat, new_width, new_height, 1, _borderWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void Texture2D::apply(State& state) const
|
void Texture2D::apply(State& state) const
|
||||||
{
|
{
|
||||||
@ -141,25 +160,24 @@ void Texture2D::apply(State& state) const
|
|||||||
|
|
||||||
// get the texture object for the current contextID.
|
// get the texture object for the current contextID.
|
||||||
TextureObject* textureObject = getTextureObject(contextID);
|
TextureObject* textureObject = getTextureObject(contextID);
|
||||||
|
if (textureObject && !textureObjectValid(state))
|
||||||
if (textureObject)
|
|
||||||
{
|
{
|
||||||
if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount())
|
bool textureObjectInvalidated = false;
|
||||||
|
if (_subloadCallback.valid())
|
||||||
{
|
{
|
||||||
// compute the internal texture format, this set the _internalFormat to an appropriate value.
|
textureObjectInvalidated = !_subloadCallback->textureObjectValid(*this, state);
|
||||||
computeInternalFormat();
|
}
|
||||||
|
else if (_image.valid() && getModifiedCount(contextID) != _image->getModifiedCount())
|
||||||
|
{
|
||||||
|
textureObjectInvalidated = !textureObjectValid(state);
|
||||||
|
}
|
||||||
|
|
||||||
GLsizei new_width, new_height, new_numMipmapLevels;
|
if (textureObjectInvalidated)
|
||||||
|
{
|
||||||
// compute the dimensions of the texture.
|
OSG_NOTICE<<"Discarding TextureObject"<<std::endl;
|
||||||
computeRequiredTextureDimensions(state, *_image, new_width, new_height, new_numMipmapLevels);
|
Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get());
|
||||||
|
_textureObjectBuffer[contextID] = 0;
|
||||||
if (!textureObject->match(GL_TEXTURE_2D, new_numMipmapLevels, _internalFormat, new_width, new_height, 1, _borderWidth))
|
textureObject = 0;
|
||||||
{
|
|
||||||
Texture::releaseTextureObject(contextID, _textureObjectBuffer[contextID].get());
|
|
||||||
_textureObjectBuffer[contextID] = 0;
|
|
||||||
textureObject = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user