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."
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
#include <OpenThreads/Condition>
|
||||
|
||||
#include <osgDB/SharedStateManager>
|
||||
#include <osgDB/ReaderWriter>
|
||||
#include <osgDB/Export>
|
||||
|
||||
#include <map>
|
||||
@@ -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<osg::Group> _groupForAddingLoadedSubgraph;
|
||||
osg::ref_ptr<osg::Node> _loadedModel;
|
||||
DataToCompileMap _dataToCompileMap;
|
||||
|
||||
osg::ref_ptr<ReaderWriter::Options> _loadOptions;
|
||||
};
|
||||
|
||||
typedef std::vector< osg::ref_ptr<DatabaseRequest> > DatabaseRequestList;
|
||||
|
||||
@@ -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<OpenThreads::Mutex> 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 "<<osg::Timer::instance()->delta_m(before,osg::Timer::instance()->tick())<<" ms"<<std::endl;
|
||||
|
||||
Reference in New Issue
Block a user