]> git.mxchange.org Git - simgear.git/blobdiff - simgear/scene/model/SGPagedLOD.cxx
Merge branch 'next' of git.gitorious.org:fg/simgear into next
[simgear.git] / simgear / scene / model / SGPagedLOD.cxx
index 02b187ea9b3db9f422be5fc2682eae33492ee70a..b44019b7ec5ada7b3168f8cee6b6af4ce48d3508 100644 (file)
@@ -35,6 +35,8 @@
 using namespace osg;
 using namespace simgear;
 
+bool SGPagedLOD::_cache = true;
+
 SGPagedLOD::SGPagedLOD()
         : PagedLOD()
 {
@@ -46,11 +48,27 @@ SGPagedLOD::~SGPagedLOD()
 }
 
 SGPagedLOD::SGPagedLOD(const SGPagedLOD& plod,const CopyOp& copyop)
-        : osg::PagedLOD(plod, copyop),
-        _readerWriterOptions(plod._readerWriterOptions)
+        : osg::PagedLOD(plod, copyop)
+#if !SG_PAGEDLOD_HAS_OPTIONS
+        ,  _readerWriterOptions(plod._readerWriterOptions)
+#endif
 {
 }
 
+void
+SGPagedLOD::setReaderWriterOptions(osgDB::ReaderWriter::Options *options)
+{
+    if (_cache)
+        options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
+    else
+        options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_NONE);
+#if SG_PAGEDLOD_HAS_OPTIONS
+    setDatabaseOptions(options);
+#else
+    _readerWriterOptions = options;
+#endif
+}
+
 bool SGPagedLOD::addChild(osg::Node *child)
 {
     if (!PagedLOD::addChild(child))
@@ -61,37 +79,30 @@ bool SGPagedLOD::addChild(osg::Node *child)
     return true;
 }
 
-void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, osg::FrameStamp* framestamp)
+// Work around interface change in osgDB::DatabasePager::requestNodeFile
+struct NodePathProxy
+{
+    NodePathProxy(NodePath& nodePath)
+        : _nodePath(nodePath)
+    {
+    }
+    operator Group* () { return static_cast<Group*>(_nodePath.back()); }
+    operator NodePath& () { return _nodePath; }
+    NodePath& _nodePath;
+};
+
+void SGPagedLOD::forceLoad(osgDB::DatabasePager *dbp, FrameStamp* framestamp,
+                           NodePath& path)
 {
     //SG_LOG(SG_GENERAL, SG_ALERT, "SGPagedLOD::forceLoad(" <<
     //getFileName(getNumChildren()) << ")");
     unsigned childNum = getNumChildren();
     setTimeStamp(childNum, 0);
     double priority=1.0;
-#if SG_OSG_MIN_VERSION_REQUIRED(2,9,11)
-    // osgDB::DatabasePager::requestNodeFile changed with OSG 2.9.11 
-
-    #ifdef __GNUC__
-        #warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-        #warning !! Your version of OpenSceneGraph is currently unsupported.
-        #warning !! Use latest stable OSG (2.8.3) or a OSG developer release up to 2.9.10.
-        #warning !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-    #else
-        // Alas! Why is MSVC different (again)? :)
-        #pragma WARNING( Your version of OpenSceneGraph is currently unsupported. )
-        #pragma WARNING( Use latest stable OSG (2.8.3) or a OSG developer release up to 2.9.10. )
-    #endif
-
-    //TODO We need to adapt to OSG 2.9.11 (and future releases). This doesn't work yet...
-    dbp->requestNodeFile(getFileName(childNum),this,priority,framestamp,
+    dbp->requestNodeFile(getFileName(childNum), NodePathProxy(path),
+                         priority, framestamp,
                          getDatabaseRequest(childNum),
-                         _readerWriterOptions.get());
-#else
-    // OSG revisions up to 2.9.10 
-    dbp->requestNodeFile(getFileName(childNum),this,priority,framestamp,
-                         getDatabaseRequest(childNum),
-                         _readerWriterOptions.get());
-#endif
+                         getReaderWriterOptions());
 }
 
 bool SGPagedLOD_writeLocalData(const Object& obj, osgDB::Output& fw)