#include <osgDB/Registry>
#include <simgear/compiler.h>
+#include <simgear/structure/Singleton.hxx>
#include <string>
#include <map>
// readNode function is specified as a template with a bunch of
// pluggable (and predefined) policies.
template <typename ProcessPolicy, typename CachePolicy, typename OptimizePolicy,
- typename CopyPolicy, typename SubstitutePolicy>
+ typename CopyPolicy, typename SubstitutePolicy, typename BVHPolicy>
class ModelRegistryCallback : public osgDB::Registry::ReadFileCallback {
public:
ModelRegistryCallback(const std::string& extension) :
_processPolicy(extension), _cachePolicy(extension),
_optimizePolicy(extension), _copyPolicy(extension),
- _substitutePolicy(extension)
+ _substitutePolicy(extension), _bvhPolicy(extension)
{
}
virtual osgDB::ReaderWriter::ReadResult
using namespace osg;
using namespace osgDB;
using osgDB::ReaderWriter;
- Registry* registry = Registry::instance();
+// Registry* registry = Registry::instance();
ref_ptr<osg::Node> optimizedNode = _cachePolicy.find(fileName, opt);
if (!optimizedNode.valid()) {
std::string otherFileName = _substitutePolicy.substitute(fileName,
optimizedNode = _optimizePolicy.optimize(processedNode.get(),
fileName, opt);
}
+ _bvhPolicy.buildBVH(fileName, optimizedNode.get());
_cachePolicy.addToCache(fileName, optimizedNode.get());
}
- return ReaderWriter::ReadResult(_copyPolicy.copy(optimizedNode.get(),
- fileName,
- opt));
+ osg::ref_ptr<osg::Node> copyNode;
+ copyNode = _copyPolicy.copy(optimizedNode.get(), fileName, opt);
+ return ReaderWriter::ReadResult(copyNode);
}
protected:
static osgDB::ReaderWriter::ReadResult
OptimizePolicy _optimizePolicy;
CopyPolicy _copyPolicy;
SubstitutePolicy _substitutePolicy;
+ BVHPolicy _bvhPolicy;
virtual ~ModelRegistryCallback() {}
};
return std::string();
}
};
+
+struct BuildLeafBVHPolicy {
+ BuildLeafBVHPolicy(const std::string& extension) {}
+ void buildBVH(const std::string& fileName, osg::Node* node);
+};
+
+struct BuildGroupBVHPolicy {
+ BuildGroupBVHPolicy(const std::string& extension) {}
+ void buildBVH(const std::string& fileName, osg::Node* node);
+};
+
+struct NoBuildBVHPolicy {
+ NoBuildBVHPolicy(const std::string& extension) {}
+ void buildBVH(const std::string& fileName, osg::Node* node);
+};
+
typedef ModelRegistryCallback<DefaultProcessPolicy, DefaultCachePolicy,
OptimizeModelPolicy, DefaultCopyPolicy,
- OSGSubstitutePolicy> DefaultCallback;
+ OSGSubstitutePolicy, BuildLeafBVHPolicy>
+DefaultCallback;
// The manager for the callbacks
-class ModelRegistry : public osgDB::Registry::ReadFileCallback {
+class ModelRegistry : public osgDB::Registry::ReadFileCallback,
+ public ReferencedSingleton<ModelRegistry> {
public:
ModelRegistry();
virtual osgDB::ReaderWriter::ReadResult
void addNodeCallbackForExtension(const std::string& extension,
osgDB::Registry::ReadFileCallback*
callback);
- static ModelRegistry* getInstance();
virtual ~ModelRegistry() {}
protected:
- static osg::ref_ptr<ModelRegistry> instance;
typedef std::map<std::string, osg::ref_ptr<osgDB::Registry::ReadFileCallback> >
CallbackMap;
CallbackMap imageCallbackMap;
// postprocessing.
typedef ModelRegistryCallback<DefaultProcessPolicy, NoCachePolicy,
NoOptimizePolicy, NoCopyPolicy,
- NoSubstitutePolicy> LoadOnlyCallback;
+ NoSubstitutePolicy, BuildLeafBVHPolicy>
+LoadOnlyCallback;
// Proxy for registering extension-based callbacks
public:
ModelRegistryCallbackProxy(std::string extension)
{
- ModelRegistry::getInstance()
+ ModelRegistry::instance()
->addNodeCallbackForExtension(extension, new T(extension));
}
};