Added a mutex to protect the removal and addition of Uniform and Program to StateSet to avoid parents being invalidated when multi-threading.

This commit is contained in:
Robert Osfield
2012-08-14 20:15:00 +00:00
parent fb83c2b061
commit 52861ecbb0
2 changed files with 5 additions and 0 deletions

View File

@@ -187,6 +187,7 @@ protected:
osg::ref_ptr<osg::Texture2D> _fallbackShadowMapTexture;
typedef std::vector< osg::ref_ptr<osg::Uniform> > Uniforms;
mutable OpenThreads::Mutex _accessUnfiromsAndProgramMutex;
Uniforms _uniforms;
osg::ref_ptr<osg::Program> _program;
};

View File

@@ -1161,6 +1161,8 @@ void ViewDependentShadowMap::createShaders()
unsigned int _baseTextureUnit = 0;
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_accessUnfiromsAndProgramMutex);
_shadowCastingStateSet = new osg::StateSet;
ShadowSettings* settings = getShadowedScene()->getShadowSettings();
@@ -2342,6 +2344,8 @@ osg::StateSet* ViewDependentShadowMap::selectStateSetForRenderingShadow(ViewDepe
osg::ref_ptr<osg::StateSet> stateset = vdd.getStateSet();
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_accessUnfiromsAndProgramMutex);
vdd.getStateSet()->clear();
vdd.getStateSet()->setTextureAttributeAndModes(0, _fallbackBaseTexture.get(), osg::StateAttribute::ON);