diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index f8291b767..071a2540d 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -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& 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); diff --git a/include/osgUtil/CullVisitor b/include/osgUtil/CullVisitor index cf1c4eb67..c0d526fc1 100644 --- a/include/osgUtil/CullVisitor +++ b/include/osgUtil/CullVisitor @@ -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& 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; } diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index f5e49540e..7ea949c05 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -115,11 +115,62 @@ DatabasePager::DatabasePager() //osgDB::Registry::instance()->setUseObjectCacheHint(true); } +DatabasePager::DatabasePager(const DatabasePager& rhs) +{ + //osg::notify(osg::INFO)<<"Constructing DatabasePager(const DatabasePager& )"<& DatabasePager::prototype() +{ + static osg::ref_ptr 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; diff --git a/src/osgUtil/CullVisitor.cpp b/src/osgUtil/CullVisitor.cpp index 29dbfc0a2..3671702f2 100644 --- a/src/osgUtil/CullVisitor.cpp +++ b/src/osgUtil/CullVisitor.cpp @@ -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::prototype() +{ + static osg::ref_ptr s_CullVisitor = new CullVisitor; + return s_CullVisitor; +} + +CullVisitor* CullVisitor::create() +{ + return CullVisitor::prototype().valid() ? + CullVisitor::prototype()->clone() : + new CullVisitor; +} + void CullVisitor::reset() { diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index b75024b6f..ec13abd30 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -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->cloneType()); + if (!_cullVisitorLeft.valid()) _cullVisitorLeft = dynamic_cast(_cullVisitor->clone()); if (!_rendergraphLeft.valid()) _rendergraphLeft = dynamic_cast(_rendergraph->cloneType()); if (!_renderStageLeft.valid()) _renderStageLeft = dynamic_cast(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL)); - if (!_cullVisitorRight.valid()) _cullVisitorRight = dynamic_cast(_cullVisitor->cloneType()); + if (!_cullVisitorRight.valid()) _cullVisitorRight = dynamic_cast(_cullVisitor->clone()); if (!_rendergraphRight.valid()) _rendergraphRight = dynamic_cast(_rendergraph->cloneType()); if (!_renderStageRight.valid()) _renderStageRight = dynamic_cast(_renderStage->clone(osg::CopyOp::DEEP_COPY_ALL)); diff --git a/src/osgViewer/Renderer.cpp b/src/osgViewer/Renderer.cpp index 717dddaf4..5169fdb04 100644 --- a/src/osgViewer/Renderer.cpp +++ b/src/osgViewer/Renderer.cpp @@ -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; diff --git a/src/osgViewer/Scene.cpp b/src/osgViewer/Scene.cpp index d82c428e3..289bc78a4 100644 --- a/src/osgViewer/Scene.cpp +++ b/src/osgViewer/Scene.cpp @@ -26,7 +26,7 @@ Scene::Scene(): _updateVisitor = new osgUtil::UpdateVisitor; _updateVisitor->setFrameStamp(_frameStamp.get()); - setDatabasePager(new osgDB::DatabasePager); + setDatabasePager(osgDB::DatabasePager::create()); } Scene::~Scene()