Clear Uniform cache on reset.

This commit is contained in:
Stuart Buchanan
2017-08-01 21:23:35 +01:00
parent 69ba2617d2
commit e8c1baa396
3 changed files with 46 additions and 29 deletions

View File

@@ -89,36 +89,17 @@ using namespace osgUtil;
using namespace effect;
class UniformFactoryImpl {
public:
ref_ptr<Uniform> 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<std::string, Uniform::Type, std::string, std::string> UniformCacheKey;
typedef boost::tuple<ref_ptr<Uniform>, SGPropertyChangeListener*> UniformCacheValue;
std::map<UniformCacheKey,ref_ptr<Uniform> > uniformCache;
typedef std::queue<DeferredPropertyListener*> DeferredListenerList;
DeferredListenerList deferredListenerList;
};
const char* UniformFactoryImpl::vec3Names[] = {"x", "y", "z"};
const char* UniformFactoryImpl::vec4Names[] = {"x", "y", "z", "w"};
ref_ptr<Uniform> UniformFactoryImpl::getUniform( Effect * effect,
const string & name,
Uniform::Type uniformType,
void UniformFactoryImpl::reset()
{
uniformCache.clear();
}
ref_ptr<Uniform> 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<UniformFactoryImpl> UniformFactory;
Effect::Effect()
: _cache(0), _isRealized(false)

View File

@@ -20,8 +20,10 @@
#include <vector>
#include <string>
#include <unordered_map>
#include <queue>
#include <boost/functional/hash.hpp>
#include <boost/tuple/tuple.hpp>
#include <osg/Object>
#include <osg/observer_ptr>
@@ -29,6 +31,9 @@
#include <simgear/props/props.hxx>
#include <simgear/scene/util/UpdateOnceCallback.hxx>
#include <simgear/threads/SGThread.hxx>
#include <simgear/threads/SGGuard.hxx>
#include <simgear/structure/Singleton.hxx>
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<Uniform> 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<std::string, Uniform::Type, std::string, std::string> UniformCacheKey;
typedef boost::tuple<ref_ptr<Uniform>, SGPropertyChangeListener*> UniformCacheValue;
std::map<UniformCacheKey,ref_ptr<Uniform> > uniformCache;
typedef std::queue<DeferredPropertyListener*> DeferredListenerList;
DeferredListenerList deferredListenerList;
};
typedef Singleton<UniformFactoryImpl> UniformFactory;
}
#endif

View File

@@ -278,8 +278,10 @@ Effect* makeEffect(SGPropertyNode* prop,
void clearEffectCache()
{
SG_LOG(SG_INPUT, SG_DEBUG, "clearEffectCache called");
OpenThreads::ScopedLock<OpenThreads::ReentrantMutex> lock(effectMutex);
effectMap.clear();
UniformFactory::instance()->reset();
}
}