]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/ModelRegistry.hxx
Merge branch 'timoore/aptsign' into next
[simgear.git] / simgear / scene / model / ModelRegistry.hxx
index 7b7ffe4eb2b43b180c623e388035df76e5654211..94931bca1e287674f2653111efc2dea772d3a285 100644 (file)
@@ -19,8 +19,6 @@
 #ifndef _SG_MODELREGISTRY_HXX
 #define _SG_MODELREGISTRY_HXX 1
 
-#include <OpenThreads/ReentrantMutex>
-
 #include <osg/ref_ptr>
 #include <osg/Node>
 #include <osgDB/FileUtils>
@@ -61,13 +59,13 @@ namespace simgear
 // 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 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)
+        _optimizePolicy(extension),
+        _substitutePolicy(extension), _bvhPolicy(extension)
     {
     }
     virtual osgDB::ReaderWriter::ReadResult
@@ -77,7 +75,7 @@ public:
         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,
@@ -97,11 +95,10 @@ public:
                 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));
+        return ReaderWriter::ReadResult(optimizedNode);
     }
 protected:
     static osgDB::ReaderWriter::ReadResult
@@ -119,8 +116,8 @@ protected:
     ProcessPolicy _processPolicy;
     CachePolicy _cachePolicy;
     OptimizePolicy _optimizePolicy;
-    CopyPolicy _copyPolicy;
     SubstitutePolicy _substitutePolicy;
+    BVHPolicy _bvhPolicy;
     virtual ~ModelRegistryCallback() {}
 };
 
@@ -167,21 +164,6 @@ struct NoOptimizePolicy {
     }
 };
 
-struct DefaultCopyPolicy {
-    DefaultCopyPolicy(const std::string& extension) {}
-    osg::Node* copy(osg::Node* node, const std::string& fileName,
-                    const osgDB::ReaderWriter::Options* opt);
-};
-
-struct NoCopyPolicy {
-    NoCopyPolicy(const std::string& extension) {}
-    osg::Node* copy(osg::Node* node, const std::string& fileName,
-                    const osgDB::ReaderWriter::Options* opt)
-    {
-        return node;
-    }
-};
-
 struct OSGSubstitutePolicy {
     OSGSubstitutePolicy(const std::string& extension) {}
     std::string substitute(const std::string& name,
@@ -196,9 +178,26 @@ struct NoSubstitutePolicy {
         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;
+                              OptimizeModelPolicy,
+                              OSGSubstitutePolicy, BuildLeafBVHPolicy>
+DefaultCallback;
 
 // The manager for the callbacks
 class ModelRegistry : public osgDB::Registry::ReadFileCallback,
@@ -224,16 +223,14 @@ protected:
     CallbackMap imageCallbackMap;
     CallbackMap nodeCallbackMap;
     osg::ref_ptr<DefaultCallback> _defaultCallback;
-    // Protect against simultaneous calls from main thread (MP models)
-    // and pager thread.
-    OpenThreads::ReentrantMutex readerMutex;
 };
 
 // Callback that only loads the file without any caching or
 // postprocessing.
 typedef ModelRegistryCallback<DefaultProcessPolicy, NoCachePolicy,
-                              NoOptimizePolicy, NoCopyPolicy,
-                              NoSubstitutePolicy> LoadOnlyCallback;
+                              NoOptimizePolicy,
+                              NoSubstitutePolicy, BuildLeafBVHPolicy>
+LoadOnlyCallback;
 
 // Proxy for registering extension-based callbacks