diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index bfbc1412..70792a7a 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -89,36 +89,17 @@ using namespace osgUtil; using namespace effect; -class UniformFactoryImpl { -public: - ref_ptr getUniform( Effect * effect, - const string & name, - Uniform::Type uniformType, - SGConstPropertyNode_ptr valProp, - const SGReaderWriterOptions* options ); - void updateListeners( SGPropertyNode* propRoot ); - void addListener(DeferredPropertyListener* listener); -private: - // Default names for vector property components - static const char* vec3Names[]; - static const char* vec4Names[]; - - SGMutex _mutex; - - typedef boost::tuple UniformCacheKey; - typedef boost::tuple, SGPropertyChangeListener*> UniformCacheValue; - std::map > uniformCache; - - typedef std::queue DeferredListenerList; - DeferredListenerList deferredListenerList; -}; - const char* UniformFactoryImpl::vec3Names[] = {"x", "y", "z"}; const char* UniformFactoryImpl::vec4Names[] = {"x", "y", "z", "w"}; -ref_ptr UniformFactoryImpl::getUniform( Effect * effect, - const string & name, - Uniform::Type uniformType, +void UniformFactoryImpl::reset() +{ + uniformCache.clear(); +} + +ref_ptr UniformFactoryImpl::getUniform( Effect * effect, + const string & name, + Uniform::Type uniformType, SGConstPropertyNode_ptr valProp, const SGReaderWriterOptions* options ) { @@ -223,8 +204,6 @@ void UniformFactoryImpl::updateListeners( SGPropertyNode* propRoot ) } } -typedef Singleton UniformFactory; - Effect::Effect() : _cache(0), _isRealized(false) diff --git a/simgear/scene/material/Effect.hxx b/simgear/scene/material/Effect.hxx index 84a25222..56a84769 100644 --- a/simgear/scene/material/Effect.hxx +++ b/simgear/scene/material/Effect.hxx @@ -20,8 +20,10 @@ #include #include #include +#include #include +#include #include #include @@ -29,6 +31,9 @@ #include #include +#include +#include +#include namespace osg { @@ -48,6 +53,9 @@ class Technique; class Effect; class SGReaderWriterOptions; +using namespace osg; +using namespace std; + /** * Object to be initialized at some point after an effect -- and its * containing effect geode -- are hooked into the scene graph. Some @@ -168,5 +176,33 @@ void mergePropertyTrees(SGPropertyNode* resultNode, const SGPropertyNode* left, const SGPropertyNode* right); } + +class UniformFactoryImpl { +public: + ref_ptr getUniform( Effect * effect, + const string & name, + Uniform::Type uniformType, + SGConstPropertyNode_ptr valProp, + const SGReaderWriterOptions* options ); + void updateListeners( SGPropertyNode* propRoot ); + void addListener(DeferredPropertyListener* listener); + void reset(); +private: + // Default names for vector property components + static const char* vec3Names[]; + static const char* vec4Names[]; + + SGMutex _mutex; + + typedef boost::tuple UniformCacheKey; + typedef boost::tuple, SGPropertyChangeListener*> UniformCacheValue; + std::map > uniformCache; + + typedef std::queue DeferredListenerList; + DeferredListenerList deferredListenerList; +}; + +typedef Singleton UniformFactory; + } #endif diff --git a/simgear/scene/material/makeEffect.cxx b/simgear/scene/material/makeEffect.cxx index 628d7143..cfbb87af 100644 --- a/simgear/scene/material/makeEffect.cxx +++ b/simgear/scene/material/makeEffect.cxx @@ -278,8 +278,10 @@ Effect* makeEffect(SGPropertyNode* prop, void clearEffectCache() { + SG_LOG(SG_INPUT, SG_DEBUG, "clearEffectCache called"); OpenThreads::ScopedLock lock(effectMutex); effectMap.clear(); + UniformFactory::instance()->reset(); } }