Added new statc prototype() and create() methods to CullVisitor and DatabasePager to allow overriding of the default implementations

This commit is contained in:
Robert Osfield
2007-08-08 08:10:38 +00:00
parent 58db6fd81a
commit e3b7b2f617
7 changed files with 108 additions and 10 deletions

View File

@@ -45,6 +45,19 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
DatabasePager();
DatabasePager(const DatabasePager& rhs);
/** Create a shallow copy on the DatabasePager.*/
virtual DatabasePager* clone() const { return new DatabasePager(*this); }
/** get the prototype singleton used by DatabasePager::create().*/
static osg::ref_ptr<DatabasePager>& prototype();
/** create a DatabasePager by cloning DatabasePager::prototype().*/
static DatabasePager* create();
/** 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);

View File

@@ -53,9 +53,18 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
CullVisitor();
virtual ~CullVisitor();
/// Copy constructor that does a shallow copy.
CullVisitor(const CullVisitor&);
virtual CullVisitor* cloneType() const { return new CullVisitor(); }
/** Create a shallow copy on the CullVisitor.*/
virtual CullVisitor* clone() const { return new CullVisitor(*this); }
/** get the prototype singleton used by CullVisitor::create().*/
static osg::ref_ptr<CullVisitor>& prototype();
/** create a CullVisitor by cloning CullVisitor::prototype().*/
static CullVisitor* create();
virtual void reset();
@@ -258,6 +267,8 @@ class OSGUTIL_EXPORT CullVisitor : public osg::NodeVisitor, public osg::CullStac
protected:
virtual ~CullVisitor();
/** Prevent unwanted copy operator.*/
CullVisitor& operator = (const CullVisitor&) { return *this; }

View File

@@ -115,11 +115,62 @@ DatabasePager::DatabasePager()
//osgDB::Registry::instance()->setUseObjectCacheHint(true);
}
DatabasePager::DatabasePager(const DatabasePager& rhs)
{
//osg::notify(osg::INFO)<<"Constructing DatabasePager(const DatabasePager& )"<<std::endl;
_startThreadCalled = false;
_done = false;
_acceptNewRequests = true;
_databasePagerThreadPaused = false;
_useFrameBlock = rhs._useFrameBlock;
_numFramesActive = 0;
_frameNumber = 0;
_frameBlock = new osg::RefBlock;
_databasePagerThreadBlock = new osg::RefBlock;
_threadPriorityDuringFrame = rhs._threadPriorityDuringFrame;
_threadPriorityOutwithFrame = rhs._threadPriorityOutwithFrame;
_drawablePolicy = rhs._drawablePolicy;
_changeAutoUnRef = rhs._changeAutoUnRef;
_valueAutoUnRef = rhs._valueAutoUnRef;
_changeAnisotropy = rhs._changeAnisotropy;
_valueAnisotropy = rhs._valueAnisotropy;
_deleteRemovedSubgraphsInDatabaseThread = rhs._deleteRemovedSubgraphsInDatabaseThread;
_expiryDelay = rhs._expiryDelay;
_doPreCompile = rhs._doPreCompile;
_targetFrameRate = rhs._targetFrameRate;
_minimumTimeAvailableForGLCompileAndDeletePerFrame = rhs._minimumTimeAvailableForGLCompileAndDeletePerFrame;
_maximumNumOfObjectsToCompilePerFrame = rhs._maximumNumOfObjectsToCompilePerFrame;
}
DatabasePager::~DatabasePager()
{
cancel();
}
osg::ref_ptr<DatabasePager>& DatabasePager::prototype()
{
static osg::ref_ptr<DatabasePager> s_DatabasePager = new DatabasePager;
return s_DatabasePager;
}
DatabasePager* DatabasePager::create()
{
return DatabasePager::prototype().valid() ?
DatabasePager::prototype()->clone() :
new DatabasePager;
}
int DatabasePager::cancel()
{
int result = 0;

View File

@@ -98,15 +98,38 @@ CullVisitor::CullVisitor():
_currentReuseRenderLeafIndex(0),
_numberOfEncloseOverrideRenderBinDetails(0)
{
// _nearFarRatio = 0.000005f;
}
CullVisitor::CullVisitor(const CullVisitor& rhs):
NodeVisitor(rhs),
CullStack(rhs),
_currentStateGraph(NULL),
_currentRenderBin(NULL),
_computed_znear(FLT_MAX),
_computed_zfar(-FLT_MAX),
_currentReuseRenderLeafIndex(0),
_numberOfEncloseOverrideRenderBinDetails(0)
{
}
CullVisitor::~CullVisitor()
{
reset();
}
osg::ref_ptr<CullVisitor>& CullVisitor::prototype()
{
static osg::ref_ptr<CullVisitor> s_CullVisitor = new CullVisitor;
return s_CullVisitor;
}
CullVisitor* CullVisitor::create()
{
return CullVisitor::prototype().valid() ?
CullVisitor::prototype()->clone() :
new CullVisitor;
}
void CullVisitor::reset()
{

View File

@@ -217,7 +217,7 @@ void SceneView::setDefaults(unsigned int options)
_updateVisitor = new UpdateVisitor;
_cullVisitor = new CullVisitor;
_cullVisitor = CullVisitor::create();
_cullVisitor->setStateGraph(_rendergraph.get());
_cullVisitor->setRenderStage(_renderStage.get());
@@ -566,7 +566,7 @@ void SceneView::cull()
if (!_cullVisitor)
{
osg::notify(osg::INFO) << "Warning: no valid osgUtil::SceneView:: attached, creating a default CullVisitor automatically."<< std::endl;
_cullVisitor = new CullVisitor;
_cullVisitor = CullVisitor::create();
}
if (!_rendergraph)
{
@@ -613,11 +613,11 @@ void SceneView::cull()
else
{
if (!_cullVisitorLeft.valid()) _cullVisitorLeft = dynamic_cast<CullVisitor*>(_cullVisitor->cloneType());
if (!_cullVisitorLeft.valid()) _cullVisitorLeft = dynamic_cast<CullVisitor*>(_cullVisitor->clone());
if (!_rendergraphLeft.valid()) _rendergraphLeft = dynamic_cast<StateGraph*>(_rendergraph->cloneType());
if (!_renderStageLeft.valid()) _renderStageLeft = dynamic_cast<RenderStage*>(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL));
if (!_cullVisitorRight.valid()) _cullVisitorRight = dynamic_cast<CullVisitor*>(_cullVisitor->cloneType());
if (!_cullVisitorRight.valid()) _cullVisitorRight = dynamic_cast<CullVisitor*>(_cullVisitor->clone());
if (!_rendergraphRight.valid()) _rendergraphRight = dynamic_cast<StateGraph*>(_rendergraph->cloneType());
if (!_renderStageRight.valid()) _renderStageRight = dynamic_cast<RenderStage*>(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL));

View File

@@ -156,8 +156,8 @@ Renderer::Renderer(osg::Camera* camera):
_sceneView[0]->setDisplaySettings(ds);
_sceneView[1]->setDisplaySettings(ds);
_sceneView[0]->setCamera(_camera.get());
_sceneView[1]->setCamera(_camera.get());
_sceneView[0]->setCamera(_camera.get(), false);
_sceneView[1]->setCamera(_camera.get(), false);
_currentCull = 0;
_currentDraw = 0;

View File

@@ -26,7 +26,7 @@ Scene::Scene():
_updateVisitor = new osgUtil::UpdateVisitor;
_updateVisitor->setFrameStamp(_frameStamp.get());
setDatabasePager(new osgDB::DatabasePager);
setDatabasePager(osgDB::DatabasePager::create());
}
Scene::~Scene()