Fixed texture optimization problem associated with mixing already compiled scene graphs - resulting

in incorrect texture assignment.  Solution was to a compareTextureObjects() test to the Texture*::compare(..) method that
the osgUtil::Optimizer::StateSetVisitor uses to determine uniqueness.
This commit is contained in:
Robert Osfield
2006-08-14 19:42:22 +00:00
parent fb27b27e5e
commit be60b32add
7 changed files with 73 additions and 0 deletions

View File

@@ -599,6 +599,9 @@ class OSG_EXPORT Texture : public osg::StateAttribute
/** Returns -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
int compareTexture(const Texture& rhs) const;
/** Returns -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
int compareTextureObjects(const Texture& rhs) const;
typedef buffered_value<unsigned int> TexParameterDirtyList;
mutable TexParameterDirtyList _texParametersDirtyList;

View File

@@ -417,6 +417,17 @@ int Texture::compareTexture(const Texture& rhs) const
return 0;
}
int Texture::compareTextureObjects(const Texture& rhs) const
{
if (_textureObjectBuffer.size()<rhs._textureObjectBuffer.size()) return -1;
if (rhs._textureObjectBuffer.size()<_textureObjectBuffer.size()) return 1;
for(unsigned int i=0; i<_textureObjectBuffer.size(); ++i)
{
if (_textureObjectBuffer[i] < rhs._textureObjectBuffer[i]) return -1;
else if (rhs._textureObjectBuffer[i] < _textureObjectBuffer[i]) return 1;
}
return 0;
}
void Texture::setWrap(WrapParameter which, WrapMode wrap)
{

View File

@@ -64,6 +64,17 @@ int Texture1D::compare(const StateAttribute& sa) const
}
}
if (!_image && !rhs._image)
{
// no image attached to either Texture2D
// but could these textures already be downloaded?
// check the _textureObjectBuffer to see if they have been
// downloaded
int result = compareTextureObjects(rhs);
if (result!=0) return result;
}
int result = compareTexture(rhs);
if (result!=0) return result;

View File

@@ -76,6 +76,17 @@ int Texture2D::compare(const StateAttribute& sa) const
}
}
if (!_image && !rhs._image)
{
// no image attached to either Texture2D
// but could these textures already be downloaded?
// check the _textureObjectBuffer to see if they have been
// downloaded
int result = compareTextureObjects(rhs);
if (result!=0) return result;
}
int result = compareTexture(rhs);
if (result!=0) return result;

View File

@@ -71,6 +71,17 @@ int Texture3D::compare(const StateAttribute& sa) const
}
}
if (!_image && !rhs._image)
{
// no image attached to either Texture2D
// but could these textures already be downloaded?
// check the _textureObjectBuffer to see if they have been
// downloaded
int result = compareTextureObjects(rhs);
if (result!=0) return result;
}
int result = compareTexture(rhs);
if (result!=0) return result;

View File

@@ -76,8 +76,12 @@ int TextureCubeMap::compare(const StateAttribute& sa) const
// used by the COMPARE_StateAttribute_Paramter macro's below.
COMPARE_StateAttribute_Types(TextureCubeMap,sa)
bool noImages = true;
for (int n=0; n<6; n++)
{
if (noImages && _images[n].valid()) noImages = false;
if (noImages && rhs._images[n].valid()) noImages = false;
if (_images[n]!=rhs._images[n]) // smart pointer comparison.
{
if (_images[n].valid())
@@ -99,6 +103,17 @@ int TextureCubeMap::compare(const StateAttribute& sa) const
}
}
if (noImages)
{
// no image attached to either Texture2D
// but could these textures already be downloaded?
// check the _textureObjectBuffer to see if they have been
// downloaded
int result = compareTextureObjects(rhs);
if (result!=0) return result;
}
int result = compareTexture(rhs);
if (result!=0) return result;

View File

@@ -99,6 +99,17 @@ int TextureRectangle::compare(const StateAttribute& sa) const
}
}
if (!_image && !rhs._image)
{
// no image attached to either Texture2D
// but could these textures already be downloaded?
// check the _textureObjectBuffer to see if they have been
// downloaded
int result = compareTextureObjects(rhs);
if (result!=0) return result;
}
int result = compareTexture(rhs);
if (result!=0) return result;