Further updates to the DatabasePager.

This commit is contained in:
Robert Osfield 2003-07-09 19:48:04 +00:00
parent 5aa47a77c2
commit 809168d5f8
2 changed files with 68 additions and 5 deletions

View File

@ -17,12 +17,15 @@
#include <osg/NodeVisitor>
#include <osg/Group>
#include <osg/PagedLOD>
#include <osg/Drawable>
#include <Producer/Thread>
#include <Producer/Mutex>
#include <osgProducer/Export>
#include <map>
namespace osgProducer {
/** Database paging class which manages the loading of files in a background thread,
@ -80,16 +83,21 @@ class OSGPRODUCER_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseReques
* note, should only be called from the draw thread.*/
void compileRenderingObjects(osg::State& state);
public:
typedef std::vector< osg::ref_ptr<osg::PagedLOD> > PagedLODList;
protected :
virtual ~DatabasePager() {}
// make friends with helper classes defined in DatabasePager.cpp.
class FindRenderingObjectsVisitor;
class FindPagedLODsVisitor;
typedef std::vector< osg::ref_ptr<osg::PagedLOD> > PagedLODList;
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
typedef std::vector< osg::ref_ptr<osg::Drawable> > DrawableList;
typedef std::pair<StateSetList,DrawableList> DataToCompile;
typedef std::map< unsigned int, DataToCompile > DataToCompileMap;
struct DatabaseRequest : public osg::Referenced
{
@ -101,6 +109,8 @@ class OSGPRODUCER_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseReques
unsigned int _numOfRequests;
osg::ref_ptr<osg::Group> _groupForAddingLoadedSubgraph;
osg::ref_ptr<osg::Node> _loadedModel;
DataToCompileMap _dataToCompileMap;
};
typedef std::vector< osg::ref_ptr<DatabaseRequest> > DatabaseRequestList;

View File

@ -1,7 +1,10 @@
#include <osgProducer/DatabasePager>
#include <osgDB/ReadFile>
#include <osg/Geode>
#ifndef WIN32
#ifdef WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
@ -77,6 +80,56 @@ void DatabasePager::requestNodeFile(const std::string& fileName,osg::Group* grou
}
}
class DatabasePager::FindRenderingObjectsVisitor : public osg::NodeVisitor
{
public:
FindRenderingObjectsVisitor(DatabasePager::DataToCompile& dataToCompile):
osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN),
_dataToCompile(dataToCompile)
{
}
virtual void apply(osg::Node& node)
{
apply(node.getStateSet());
traverse(node);
}
virtual void apply(osg::Geode& geode)
{
apply(geode.getStateSet());
for(unsigned int i=0;i<geode.getNumDrawables();++i)
{
apply(geode.getDrawable(i));
}
traverse(geode);
}
inline void apply(osg::StateSet* stateset)
{
if (stateset)
{
_dataToCompile.first.push_back(stateset);
}
}
inline void apply(osg::Drawable* drawable)
{
apply(drawable->getStateSet());
if (drawable->getUseDisplayList() || drawable->getUseVertexBufferObjects())
{
_dataToCompile.second.push_back(drawable);
}
}
DatabasePager::DataToCompile& _dataToCompile;
};
void DatabasePager::run()
{
std::cout<<"DatabasePager::run()"<<std::endl;
@ -206,7 +259,7 @@ void DatabasePager::removeExpiredSubgraphs(double currentFrameTime)
}
class FindPagedLODsVisitor : public osg::NodeVisitor
class DatabasePager::FindPagedLODsVisitor : public osg::NodeVisitor
{
public:
FindPagedLODsVisitor(DatabasePager::PagedLODList& pagedLODList):