2003-07-08 22:44:00 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2003 Robert Osfield
|
|
|
|
*
|
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSGPRODUCER_DATABASEPAGER
|
|
|
|
#define OSGPRODUCER_DATABASEPAGER 1
|
|
|
|
|
|
|
|
#include <osg/NodeVisitor>
|
|
|
|
#include <osg/Group>
|
|
|
|
#include <osg/PagedLOD>
|
2003-07-10 03:48:04 +08:00
|
|
|
#include <osg/Drawable>
|
2003-07-08 22:44:00 +08:00
|
|
|
|
|
|
|
#include <Producer/Thread>
|
|
|
|
#include <Producer/Mutex>
|
|
|
|
|
|
|
|
#include <osgProducer/Export>
|
|
|
|
|
2003-07-10 03:48:04 +08:00
|
|
|
#include <map>
|
2003-07-10 19:10:39 +08:00
|
|
|
#include <set>
|
2003-07-10 03:48:04 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
namespace osgProducer {
|
|
|
|
|
|
|
|
/** Database paging class which manages the loading of files in a background thread,
|
|
|
|
* and syncronizing of loaded models with the main scene graph.*/
|
|
|
|
class OSGPRODUCER_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandler, public Producer::Thread
|
|
|
|
{
|
|
|
|
public :
|
|
|
|
|
|
|
|
DatabasePager();
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
/** Add a request to load a node file to end the the database request list.*/
|
2003-07-08 22:44:00 +08:00
|
|
|
virtual void requestNodeFile(const std::string& fileName,osg::Group* group);
|
|
|
|
|
|
|
|
/** run does the database paging.*/
|
|
|
|
virtual void run();
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
|
|
|
|
/** Add the loaded data to the scene graph.*/
|
2003-07-08 22:44:00 +08:00
|
|
|
void addLoadedDataToSceneGraph();
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
|
|
|
|
/** Find all PagedLOD nodes in a subgraph and register them with
|
|
|
|
* the DatabasePager so it can keep track of expired nodes.
|
|
|
|
* note, should be only be called from the update thread. */
|
2003-07-08 22:44:00 +08:00
|
|
|
void registerPagedLODs(osg::Node* subgraph);
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
/** Set the amount of time that a subgraph will be kept without being visited in the cull traversal
|
|
|
|
* before being removed.*/
|
|
|
|
void setExpiryDelay(double expiryDelay) { _expiryDelay = expiryDelay; }
|
|
|
|
|
|
|
|
/** Get the amount of time that a subgraph will be kept without being visited in the cull traversal
|
|
|
|
* before being removed.*/
|
|
|
|
double getExpiryDelay() const { return _expiryDelay; }
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
/** set whether the removed subgraphs should be deleted in the database thread or not.*/
|
|
|
|
void setDeleteRemovedSubgraphsInDatabaseThread(bool flag) { _deleteRemovedSubgraphsInDatabaseThread = flag; }
|
|
|
|
|
|
|
|
/** get whether the removed subgraphs should be deleted in the database thread or not.*/
|
|
|
|
bool getDeleteRemovedSubgraphsInDatabaseThread() const { return _deleteRemovedSubgraphsInDatabaseThread; }
|
|
|
|
|
|
|
|
/** Iterate through the active PagedLOD nodes children removing
|
|
|
|
* children which havn't been visited since specified expiryTime.
|
|
|
|
* note, should be only be called from the update thread. */
|
2003-07-08 22:44:00 +08:00
|
|
|
void removeExpiredSubgraphs(double currentFrameTime);
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
|
2003-07-10 19:10:39 +08:00
|
|
|
/** Turn the compilation of rendering objects for specfied graphics context on (true) or off(false).*/
|
|
|
|
void setCompileRenderingObjectsForContexID(unsigned int contextID, bool on);
|
|
|
|
|
|
|
|
/** Get whether the compilation of rendering objects for specfied graphics context on (true) or off(false).*/
|
|
|
|
bool getCompileRenderingObjectsForContexID(unsigned int contextID);
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
/* Set the maximum amount of time available for compile rendering objects. */
|
|
|
|
void setMaximumTimeForCompilingRenderingObjects(double time) { _maximumTimeForCompiling = time; }
|
|
|
|
|
|
|
|
/* Get the maximum amount of time available for compile rendering objects. */
|
|
|
|
double getMaximumTimeForCompilingRenderingObjects() const { return _maximumTimeForCompiling; }
|
|
|
|
|
|
|
|
/** Compile the rendering objects (display lists,texture objects, VBO's) on loaded subgraph.
|
|
|
|
* note, should only be called from the draw thread.*/
|
|
|
|
void compileRenderingObjects(osg::State& state);
|
2003-07-08 22:44:00 +08:00
|
|
|
|
|
|
|
|
|
|
|
protected :
|
|
|
|
|
|
|
|
virtual ~DatabasePager() {}
|
2003-07-09 22:55:39 +08:00
|
|
|
|
2003-07-10 03:48:04 +08:00
|
|
|
// make friends with helper classes defined in DatabasePager.cpp.
|
2003-07-10 19:10:39 +08:00
|
|
|
class FindCompileableRenderingObjectsVisitor;
|
2003-07-10 03:48:04 +08:00
|
|
|
class FindPagedLODsVisitor;
|
|
|
|
|
|
|
|
typedef std::vector< osg::ref_ptr<osg::PagedLOD> > PagedLODList;
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
typedef std::vector< osg::ref_ptr<osg::StateSet> > StateSetList;
|
|
|
|
typedef std::vector< osg::ref_ptr<osg::Drawable> > DrawableList;
|
2003-07-10 03:48:04 +08:00
|
|
|
typedef std::pair<StateSetList,DrawableList> DataToCompile;
|
|
|
|
typedef std::map< unsigned int, DataToCompile > DataToCompileMap;
|
2003-07-08 22:44:00 +08:00
|
|
|
|
2003-07-10 19:10:39 +08:00
|
|
|
typedef std::set<unsigned int> ActiveGraphicsContexts;
|
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
struct DatabaseRequest : public osg::Referenced
|
|
|
|
{
|
|
|
|
DatabaseRequest():
|
|
|
|
_numOfRequests(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
std::string _fileName;
|
|
|
|
unsigned int _numOfRequests;
|
|
|
|
osg::ref_ptr<osg::Group> _groupForAddingLoadedSubgraph;
|
|
|
|
osg::ref_ptr<osg::Node> _loadedModel;
|
2003-07-10 03:48:04 +08:00
|
|
|
DataToCompileMap _dataToCompileMap;
|
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::vector< osg::ref_ptr<DatabaseRequest> > DatabaseRequestList;
|
|
|
|
|
|
|
|
DatabaseRequestList _fileRequestList;
|
|
|
|
Producer::Mutex _fileRequestListMutex;
|
|
|
|
|
2003-07-10 19:10:39 +08:00
|
|
|
DatabaseRequestList _dataToCompileList;
|
|
|
|
Producer::Mutex _dataToCompileListMutex;
|
2003-07-09 22:55:39 +08:00
|
|
|
|
|
|
|
bool _deleteRemovedSubgraphsInDatabaseThread;
|
|
|
|
osg::NodeList _childrenToDeleteList;
|
|
|
|
Producer::Mutex _childrenToDeleteListMutex;
|
|
|
|
|
|
|
|
DatabaseRequestList _dataToMergeList;
|
2003-07-10 19:10:39 +08:00
|
|
|
Producer::Mutex _dataToMergeListMutex;
|
2003-07-09 22:55:39 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
|
|
|
|
PagedLODList _pagedLODList;
|
|
|
|
|
|
|
|
double _expiryDelay;
|
|
|
|
|
2003-07-09 22:55:39 +08:00
|
|
|
double _maximumTimeForCompiling;
|
2003-07-10 19:10:39 +08:00
|
|
|
ActiveGraphicsContexts _activeGraphicsContexts;
|
2003-07-09 22:55:39 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|