From 7e0c30b8843d440ee24a231dd376fa749f5fd698 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 20 Sep 2016 17:23:37 +0100 Subject: [PATCH] Refactored texture sharing code so that it modifies the RefAttributePair directly thus honouring the override flags and fixing a bug of loosing these override flags when sharing --- src/osgDB/SharedStateManager.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/osgDB/SharedStateManager.cpp b/src/osgDB/SharedStateManager.cpp index 346310aea..b95cbd0f7 100644 --- a/src/osgDB/SharedStateManager.cpp +++ b/src/osgDB/SharedStateManager.cpp @@ -175,7 +175,10 @@ void SharedStateManager::shareTextures(osg::StateSet* ss) const osg::StateSet::TextureAttributeList& texAttributes = ss->getTextureAttributeList(); for(unsigned int unit=0;unitgetTextureAttribute(unit, osg::StateAttribute::TEXTURE); + osg::StateSet::RefAttributePair* pair = ss->getTextureAttributePair(unit, osg::StateAttribute::TEXTURE); + if (!pair) continue; + + osg::StateAttribute* texture = pair->first.get(); // Valid Texture to be shared if(texture && shareTexture(texture->getDataVariance())) @@ -185,13 +188,13 @@ void SharedStateManager::shareTextures(osg::StateSet* ss) { // Texture is not in tmp list: // First time it appears in this file, search Texture in sharedAttributeList - osg::StateAttribute *textureFromSharedList = find(texture); + osg::StateAttribute* textureFromSharedList = find(texture); if(textureFromSharedList) { // Texture is in sharedAttributeList: // Share now. Required to be shared all next times if(_mutex) _mutex->lock(); - ss->setTextureAttributeAndModes(unit, textureFromSharedList, osg::StateAttribute::ON); + pair->first = textureFromSharedList; if(_mutex) _mutex->unlock(); tmpSharedTextureList[texture] = TextureSharePair(textureFromSharedList, true); } @@ -210,7 +213,7 @@ void SharedStateManager::shareTextures(osg::StateSet* ss) // Texture is in tmpSharedAttributeList and share flag is on: // It should be shared if(_mutex) _mutex->lock(); - ss->setTextureAttributeAndModes(unit, titr->second.first, osg::StateAttribute::ON); + pair->first = titr->second.first; if(_mutex) _mutex->unlock(); } }