Fixed the TextureObject's + GLBufferObject reassignment to a new set.

Disabled the unref after apply for a Texture classes when the texture pool is enabled
This commit is contained in:
Robert Osfield
2009-10-06 13:42:12 +00:00
parent e6a1429335
commit 69557c060b
9 changed files with 68 additions and 34 deletions

View File

@@ -362,6 +362,7 @@ class OSG_EXPORT GLBufferObjectSet : public Referenced
void addToBack(GLBufferObject* to);
void orphan(GLBufferObject* to);
void remove(GLBufferObject* to);
void moveToSet(GLBufferObject* to, GLBufferObjectSet* set);
unsigned int size() const { return _profile._size * _numOfGLBufferObjects; }

View File

@@ -1016,6 +1016,7 @@ class OSG_EXPORT Texture : public osg::StateAttribute
void addToBack(TextureObject* to);
void orphan(TextureObject* to);
void remove(TextureObject* to);
void moveToSet(TextureObject* to, TextureObjectSet* set);
unsigned int size() const { return _profile._size * _numOfTextureObjects; }

View File

@@ -174,16 +174,10 @@ void GLBufferObject::compileBuffer()
osg::notify(osg::NOTICE)<<"newTotalSize="<<newTotalSize<<", _profile._size="<<_profile._size<<std::endl;
_profile._size = newTotalSize;
if (_set)
{
// remove self from original set
_set->remove(this);
// get the new set for the new profile
_set = _set->getParent()->getGLBufferObjectSet(_profile);
// register self with new set.
_set->addToBack(this);
_set->moveToSet(this, _set->getParent()->getGLBufferObjectSet(_profile));
}
}
@@ -882,6 +876,23 @@ void GLBufferObjectSet::remove(GLBufferObject* to)
}
void GLBufferObjectSet::moveToSet(GLBufferObject* to, GLBufferObjectSet* set)
{
if (set==this) return;
if (!set) return;
// remove 'to' from original set
--_numOfGLBufferObjects;
remove(to);
// register 'to' with new set.
to->_set = set;
++set->_numOfGLBufferObjects;
set->addToBack(to);
}
GLBufferObjectManager::GLBufferObjectManager(unsigned int contextID):
_contextID(contextID),
_numActiveGLBufferObjects(0),

View File

@@ -90,14 +90,7 @@ void Texture::TextureObject::setAllocated(GLint numMipmapLevels,
if (_set)
{
// remove self from original set
_set->remove(this);
// get the new set for the new profile
_set = _set->getParent()->getTextureObjectSet(_profile);
// register self with new set.
_set->addToBack(this);
_set->moveToSet(this, _set->getParent()->getTextureObjectSet(_profile));
}
}
}
@@ -383,7 +376,7 @@ Texture::TextureObject* Texture::TextureObjectSet::takeFromOrphans(Texture* text
// place at back of active list
addToBack(to.get());
// osg::notify(osg::NOTICE)<<"Reusing orhpahned TextureObject, _numOfTextureObjects="<<_numOfTextureObjects<<std::endl;
osg::notify(osg::NOTICE)<<"Reusing orhpahned TextureObject, _numOfTextureObjects="<<_numOfTextureObjects<<std::endl;
return to.release();
}
@@ -422,11 +415,11 @@ Texture::TextureObject* Texture::TextureObjectSet::takeOrGenerate(Texture* textu
if (original_texture.valid())
{
original_texture->setTextureObject(_contextID,0);
// osg::notify(osg::NOTICE)<<"TextureObjectSet="<<this<<": Reusing an active TextureObject "<<to.get()<<" _numOfTextureObjects="<<_numOfTextureObjects<<" width="<<_profile._width<<" height="<<_profile._height<<std::endl;
osg::notify(osg::NOTICE)<<"TextureObjectSet="<<this<<": Reusing an active TextureObject "<<to.get()<<" _numOfTextureObjects="<<_numOfTextureObjects<<" width="<<_profile._width<<" height="<<_profile._height<<std::endl;
}
else
{
// osg::notify(osg::NOTICE)<<"Reusing a recently orphaned active TextureObject "<<to.get()<<std::endl;
osg::notify(osg::NOTICE)<<"Reusing a recently orphaned active TextureObject "<<to.get()<<std::endl;
}
moveToBack(to.get());
@@ -453,7 +446,7 @@ Texture::TextureObject* Texture::TextureObjectSet::takeOrGenerate(Texture* textu
addToBack(to);
// osg::notify(osg::NOTICE)<<"Created new TextureObject, _numOfTextureObjects "<<_numOfTextureObjects<<std::endl;
osg::notify(osg::NOTICE)<<"Created new TextureObject, _numOfTextureObjects "<<_numOfTextureObjects<<std::endl;
return to;
}
@@ -602,6 +595,21 @@ void Texture::TextureObjectSet::remove(Texture::TextureObject* to)
to->_previous = 0;
}
void Texture::TextureObjectSet::moveToSet(TextureObject* to, TextureObjectSet* set)
{
if (set==this) return;
if (!set) return;
// remove 'to' from original set
--_numOfTextureObjects;
remove(to);
// register 'to' with new set.
to->_set = set;
++set->_numOfTextureObjects;
set->addToBack(to);
}
Texture::TextureObjectManager::TextureObjectManager(unsigned int contextID):
_contextID(contextID),

View File

@@ -190,7 +190,7 @@ void Texture1D::apply(State& state) const
_textureObjectBuffer[contextID] = textureObject;
if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && _image->getDataVariance()==STATIC)
if (state.getMaxTexturePoolSize()==0 && _unrefImageDataAfterApply && areAllTextureObjectsLoaded() && _image->getDataVariance()==STATIC)
{
Texture1D* non_const_this = const_cast<Texture1D*>(this);
non_const_this->_image = 0;

View File

@@ -311,7 +311,7 @@ void Texture2DArray::apply(State& state) const
_textureObjectBuffer[contextID] = textureObject;
// no idea what this for ;-)
if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded())
if (state.getMaxTexturePoolSize()==0 && _unrefImageDataAfterApply && areAllTextureObjectsLoaded())
{
Texture2DArray* non_const_this = const_cast<Texture2DArray*>(this);
for (int n=0; n<_textureDepth; n++)

View File

@@ -278,7 +278,7 @@ void Texture3D::apply(State& state) const
_textureObjectBuffer[contextID] = textureObject;
if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && _image->getDataVariance()==STATIC)
if (state.getMaxTexturePoolSize()==0 && _unrefImageDataAfterApply && areAllTextureObjectsLoaded() && _image->getDataVariance()==STATIC)
{
Texture3D* non_const_this = const_cast<Texture3D*>(this);
non_const_this->_image = 0;

View File

@@ -293,7 +293,7 @@ void TextureCubeMap::apply(State& state) const
_textureObjectBuffer[contextID] = textureObject;
if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded())
if (state.getMaxTexturePoolSize()==0 && _unrefImageDataAfterApply && areAllTextureObjectsLoaded())
{
TextureCubeMap* non_const_this = const_cast<TextureCubeMap*>(this);
for (int n=0; n<6; n++)

View File

@@ -211,26 +211,39 @@ void TextureRectangle::apply(State& state) const
else if (_image.valid() && _image->data())
{
// we don't have a applyTexImage1D_subload yet so can't reuse.. so just generate a new texture object.
textureObject = generateTextureObject(this, contextID,GL_TEXTURE_RECTANGLE);
// keep the image around at least till we go out of scope.
osg::ref_ptr<osg::Image> image = _image;
// compute the internal texture format, this set the _internalFormat to an appropriate value.
computeInternalFormat();
_textureWidth = image->s();
_textureHeight = image->t();
_textureObjectBuffer[contextID] = textureObject = generateTextureObject(
this, contextID,GL_TEXTURE_RECTANGLE,1,_internalFormat,_textureWidth,_textureHeight,1,0);
textureObject->bind();
applyTexParameters(GL_TEXTURE_RECTANGLE, state);
applyTexImage_load(GL_TEXTURE_RECTANGLE, _image.get(), state, _textureWidth, _textureHeight);
textureObject->setAllocated(1,_internalFormat,_textureWidth,_textureHeight,1,0);
_textureObjectBuffer[contextID] = textureObject;
if (textureObject->isAllocated())
{
applyTexImage_subload(GL_TEXTURE_RECTANGLE, _image.get(), state, _textureWidth, _textureHeight, _internalFormat);
}
else
{
applyTexImage_load(GL_TEXTURE_RECTANGLE, _image.get(), state, _textureWidth, _textureHeight);
textureObject->setAllocated(true);
}
if (_unrefImageDataAfterApply && areAllTextureObjectsLoaded() && _image->getDataVariance()==STATIC)
if (state.getMaxTexturePoolSize()==0 && _unrefImageDataAfterApply && areAllTextureObjectsLoaded() && _image->getDataVariance()==STATIC)
{
TextureRectangle* non_const_this = const_cast<TextureRectangle*>(this);
non_const_this->_image = 0;
}
}
else if ( (_textureWidth!=0) && (_textureHeight!=0) && (_internalFormat!=0) )
{