Added osg::PagedLOD and osgProducer::DatabasePager class, and linked up osgProducer::Viewer

to manage the pager.
This commit is contained in:
Robert Osfield
2003-07-08 14:44:00 +00:00
parent 9239173019
commit c2eabe1d4b
21 changed files with 810 additions and 59 deletions

View File

@@ -31,6 +31,7 @@ class MatrixTransform;
class PositionAttitudeTransform;
class Projection;
class LOD;
class PagedLOD;
class Switch;
class Impostor;
class ClearNode;
@@ -238,25 +239,49 @@ class SG_EXPORT NodeVisitor : public virtual Referenced
virtual void apply(Switch& node) { apply((Group&)node); }
virtual void apply(Sequence& node) { apply((Group&)node); }
virtual void apply(LOD& node) { apply((Group&)node); }
virtual void apply(PagedLOD& node) { apply((LOD&)node); }
virtual void apply(Impostor& node) { apply((LOD&)node); }
virtual void apply(ClearNode& node) { apply((Group&)node); }
virtual void apply(OccluderNode& node) { apply((Group&)node); }
/** callback for managing database paging, such as generated by PagedLOD nodes.*/
class DatabaseRequestHandler : public osg::Referenced
{
public:
virtual void requestNodeFile(const std::string& fileName,osg::Group* group) = 0;
protected:
virtual ~DatabaseRequestHandler() {}
};
/** Set the handler for database requests.*/
void setDatabaseRequestHandler(DatabaseRequestHandler* handler) { _databaseRequestHandler = handler; }
/** Get the handler for database requests.*/
DatabaseRequestHandler* getDatabaseRequestHandler() { return _databaseRequestHandler.get(); }
/** Get the const handler for database requests.*/
const DatabaseRequestHandler* getDatabaseRequestHandler() const { return _databaseRequestHandler.get(); }
protected:
VisitorType _visitorType;
int _traversalNumber;
VisitorType _visitorType;
int _traversalNumber;
ref_ptr<FrameStamp> _frameStamp;
ref_ptr<FrameStamp> _frameStamp;
TraversalMode _traversalMode;
Node::NodeMask _traversalMask;
Node::NodeMask _nodeMaskOverride;
TraversalMode _traversalMode;
Node::NodeMask _traversalMask;
Node::NodeMask _nodeMaskOverride;
NodePath _nodePath;
NodePath _nodePath;
ref_ptr<Referenced> _userData;
ref_ptr<Referenced> _userData;
ref_ptr<DatabaseRequestHandler> _databaseRequestHandler;
};

89
include/osg/PagedLOD Normal file
View File

@@ -0,0 +1,89 @@
/* -*-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 OSG_PagedLOD
#define OSG_PagedLOD 1
#include <osg/LOD>
namespace osg {
/** PagedLOD.
*/
class SG_EXPORT PagedLOD : public LOD
{
public :
PagedLOD() {}
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
PagedLOD(const PagedLOD&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, PagedLOD);
virtual void traverse(NodeVisitor& nv);
virtual bool addChild(Node *child);
virtual bool addChild(Node *child, float min, float max);
virtual bool addChild(Node *child, float min, float max,const std::string& filename);
virtual bool removeChild(Node *child);
typedef std::vector<std::string> FileNameList;
void setFileName(unsigned int childNo, const std::string& filename);
const std::string& getFileName(unsigned int childNo) const { return _fileNameList[childNo]; }
/** returns the number of filenames currently set. */
inline unsigned int getNumFileNames() const { return _fileNameList.size(); }
/** return the list of filename.*/
inline FileNameList& getFileNameList() { return _fileNameList; }
/** return the list of filename.*/
inline const FileNameList& getFileNameList() const { return _fileNameList; }
typedef std::vector<double> TimeStampList;
void setTimeStamp(unsigned int childNo, double timeStamp);
double getTimeStamp(unsigned int childNo) const { return _timeStampList[childNo]; }
/** returns the number of filenames currently set. */
inline unsigned int getNumTimeStamps() const { return _fileNameList.size(); }
/** return the list of time stamps.*/
inline TimeStampList& getTimeStampList() { return _timeStampList; }
/** return the list of time stamps.*/
inline const TimeStampList& getTimeStampList() const { return _timeStampList; }
void removeExpiredChildren(double expiryTime);
protected :
virtual ~PagedLOD() {}
FileNameList _fileNameList;
TimeStampList _timeStampList;
};
}
#endif

View File

@@ -0,0 +1,98 @@
/* -*-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>
#include <Producer/Thread>
#include <Producer/Mutex>
#include <osgProducer/Export>
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();
/** 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);
/** run does the database paging.*/
virtual void run();
/** add the loaded data to the scene graph.*/
void addLoadedDataToSceneGraph();
/** find all PagedLOD nodes in a subgraph and register them with
* the DatabasePager so it can keep track of expired nodes.*/
void registerPagedLODs(osg::Node* subgraph);
/** 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; }
/** iterate through the active PagedLOD nodes children removing
* children which havn't been visited since specified expiryTime.*/
void removeExpiredSubgraphs(double currentFrameTime);
public:
typedef std::vector< osg::ref_ptr<osg::PagedLOD> > PagedLODList;
protected :
virtual ~DatabasePager() {}
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;
};
typedef std::vector< osg::ref_ptr<DatabaseRequest> > DatabaseRequestList;
DatabaseRequestList _fileRequestList;
Producer::Mutex _fileRequestListMutex;
DatabaseRequestList _fileLoadedList;
Producer::Mutex _fileLoadedListMutex;
PagedLODList _pagedLODList;
double _expiryDelay;
};
}
#endif

View File

@@ -27,6 +27,7 @@
#include <osg/DisplaySettings>
#include <osgProducer/OsgSceneHandler>
#include <osgProducer/DatabasePager>
namespace osgProducer {
@@ -188,6 +189,8 @@ class OSGPRODUCER_EXPORT OsgCameraGroup : public Producer::CameraGroup
osg::Timer _timer;
osg::Timer_t _start_tick;
osg::ref_ptr<osg::FrameStamp> _frameStamp;
osg::ref_ptr<DatabasePager> _databasePager;
void _init();
};

View File

@@ -11,8 +11,8 @@
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_VIEWER_H
#define OSG_VIEWER_H
#ifndef OSGPRODUCER_VIEWER
#define OSGPRODUCER_VIEWER 1
#include <osg/NodeVisitor>
#include <osg/ArgumentParser>

View File

@@ -215,6 +215,8 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
osg::State* getState() { return _state.get(); }
const osg::State* getState() const { return _state.get(); }
protected:
// /** prevent unwanted copy construction.*/
@@ -255,10 +257,10 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
osg::ref_ptr<const osg::ClearNode> _clearNode;
bool _impostorActive;
bool _depthSortImpostorSprites;
float _impostorPixelErrorThreshold;
int _numFramesToKeepImpostorSprites;
bool _impostorActive;
bool _depthSortImpostorSprites;
float _impostorPixelErrorThreshold;
int _numFramesToKeepImpostorSprites;
typedef std::vector< osg::ref_ptr<RenderLeaf> > RenderLeafList;
@@ -267,7 +269,7 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
inline RenderLeaf* createOrReuseRenderLeaf(osg::Drawable* drawable,osg::RefMatrix* projection,osg::RefMatrix* matrix, float depth=0.0f);
osg::ref_ptr<osg::ImpostorSpriteManager> _impostorSpriteManager;
osg::ref_ptr<osg::ImpostorSpriteManager> _impostorSpriteManager;
osg::ref_ptr<osg::State> _state;