From 3177494aa4e6ae49ce81c6003358a6e17ac99d0b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 5 Dec 2006 14:50:46 +0000 Subject: [PATCH] From Bryan Thrall, "Currently, the DatabasePager always loads requested Nodes using the default Registry Options object, but it would be useful to be able to request loading with a different Options object. The attached files allow you to do that (based off the OSG 1.2 source). For example, I'm implementing a loader that requires context information when it pages in subgraphs, which becomes significantly complicated when multiple scenegraphs are requesting subgraph loads with different contexts (the loader needs to know which context to use, and the Registry Options needs to be carefully managed so the context settings don't clobber each other, especially in multithreaded situations). Being able to pass an Options instance along with the Node request resolves this problem." --- include/osgDB/DatabasePager | 10 ++++++++-- src/osgDB/DatabasePager.cpp | 19 +++++++++++++++---- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index abc777ff0..1553b7e2a 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -26,6 +26,7 @@ #include #include +#include #include #include @@ -45,7 +46,12 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl DatabasePager(); /** Add a request to load a node file to end the the database request list.*/ - virtual void requestNodeFile(const std::string& fileName,osg::Group* group, float priority, const osg::FrameStamp* framestamp); + virtual void requestNodeFile(const std::string& fileName,osg::Group* group, + float priority, const osg::FrameStamp* framestamp); + + virtual void requestNodeFile(const std::string& fileName,osg::Group* group, + float priority, const osg::FrameStamp* framestamp, + ReaderWriter::Options* loadOptions); /** Run does the database paging.*/ virtual void run(); @@ -266,7 +272,7 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl osg::ref_ptr _groupForAddingLoadedSubgraph; osg::ref_ptr _loadedModel; DataToCompileMap _dataToCompileMap; - + osg::ref_ptr _loadOptions; }; typedef std::vector< osg::ref_ptr > DatabaseRequestList; diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 732ebe60f..a630018a0 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -181,7 +181,15 @@ void DatabasePager::clear() // _activeGraphicsContexts } -void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* group, float priority, const osg::FrameStamp* framestamp) +void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* group, + float priority, const osg::FrameStamp* framestamp) +{ + requestNodeFile(fileName,group,priority,framestamp,Registry::instance()->getOptions()); +} + +void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* group, + float priority, const osg::FrameStamp* framestamp, + ReaderWriter::Options* loadOptions) { if (!_acceptNewRequests) return; @@ -264,6 +272,7 @@ void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* grou databaseRequest->_timestampLastRequest = timestamp; databaseRequest->_priorityLastRequest = priority; databaseRequest->_groupForAddingLoadedSubgraph = group; + databaseRequest->_loadOptions = loadOptions; _fileRequestList.push_back(databaseRequest); @@ -509,12 +518,14 @@ void DatabasePager::run() // do *not* assume that we only have one DatabasePager, or that reaNodeFile is thread safe... static OpenThreads::Mutex s_serialize_readNodeFile_mutex; OpenThreads::ScopedLock lock(s_serialize_readNodeFile_mutex); - databaseRequest->_loadedModel = osgDB::readNodeFile(databaseRequest->_fileName); + databaseRequest->_loadedModel = osgDB::readNodeFile(databaseRequest->_fileName, + databaseRequest->_loadOptions.get()); } else { - // assume that we only have one DatabasePager, or that reaNodeFile is thread safe... - databaseRequest->_loadedModel = osgDB::readNodeFile(databaseRequest->_fileName); + // assume that we only have one DatabasePager, or that readNodeFile is thread safe... + databaseRequest->_loadedModel = osgDB::readNodeFile(databaseRequest->_fileName, + databaseRequest->_loadOptions.get()); } //osg::notify(osg::NOTICE)<<" node read in "<delta_m(before,osg::Timer::instance()->tick())<<" ms"<