From e7d7c1dcc2262c83e8e4bf8d761964a4922015b8 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 2 Jul 2007 13:17:47 +0000 Subject: [PATCH] Changed the way that computeNearFar is computed to avoid inconsistencies when in stereo mode --- include/osgUtil/SceneView | 4 ++-- src/osgUtil/SceneView.cpp | 21 ++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index 87b901243..1c89f9a36 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -471,8 +471,8 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings virtual ~SceneView(); - /** Do cull traversal of attached scene graph using Cull NodeVisitor.*/ - virtual void cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage); + /** Do cull traversal of attached scene graph using Cull NodeVisitor. Return true if computeNearFar has been done during the cull traversal.*/ + virtual bool cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage); const osg::Matrix computeMVPW() const; diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 3ee740339..edb29e2dd 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -572,8 +572,6 @@ void SceneView::cull() _renderStage = new RenderStage; } - bool computeNearFar = (_cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) && getSceneData()!=0; - if (_displaySettings.valid() && _displaySettings->getStereo()) { @@ -581,7 +579,7 @@ void SceneView::cull() { // set up the left eye. _cullVisitor->setTraversalMask(_cullMaskLeft); - cullStage(computeLeftEyeProjection(getProjectionMatrix()),computeLeftEyeView(getViewMatrix()),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + bool computeNearFar = cullStage(computeLeftEyeProjection(getProjectionMatrix()),computeLeftEyeView(getViewMatrix()),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); if (computeNearFar) { @@ -595,7 +593,7 @@ void SceneView::cull() { // set up the right eye. _cullVisitor->setTraversalMask(_cullMaskRight); - cullStage(computeRightEyeProjection(getProjectionMatrix()),computeRightEyeView(getViewMatrix()),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + bool computeNearFar = cullStage(computeRightEyeProjection(getProjectionMatrix()),computeRightEyeView(getViewMatrix()),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); if (computeNearFar) { @@ -619,14 +617,14 @@ void SceneView::cull() _cullVisitorLeft->setDatabaseRequestHandler(_cullVisitor->getDatabaseRequestHandler()); _cullVisitorLeft->setClampProjectionMatrixCallback(_cullVisitor->getClampProjectionMatrixCallback()); _cullVisitorLeft->setTraversalMask(_cullMaskLeft); - cullStage(computeLeftEyeProjection(getProjectionMatrix()),computeLeftEyeView(getViewMatrix()),_cullVisitorLeft.get(),_rendergraphLeft.get(),_renderStageLeft.get()); + bool computeNearFar = cullStage(computeLeftEyeProjection(getProjectionMatrix()),computeLeftEyeView(getViewMatrix()),_cullVisitorLeft.get(),_rendergraphLeft.get(),_renderStageLeft.get()); // set up the right eye. _cullVisitorRight->setDatabaseRequestHandler(_cullVisitor->getDatabaseRequestHandler()); _cullVisitorRight->setClampProjectionMatrixCallback(_cullVisitor->getClampProjectionMatrixCallback()); _cullVisitorRight->setTraversalMask(_cullMaskRight); - cullStage(computeRightEyeProjection(getProjectionMatrix()),computeRightEyeView(getViewMatrix()),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get()); + computeNearFar = cullStage(computeRightEyeProjection(getProjectionMatrix()),computeRightEyeView(getViewMatrix()),_cullVisitorRight.get(),_rendergraphRight.get(),_renderStageRight.get()); if (computeNearFar) { @@ -642,7 +640,7 @@ void SceneView::cull() { _cullVisitor->setTraversalMask(_cullMask); - cullStage(getProjectionMatrix(),getViewMatrix(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); + bool computeNearFar = cullStage(getProjectionMatrix(),getViewMatrix(),_cullVisitor.get(),_rendergraph.get(),_renderStage.get()); if (computeNearFar) { @@ -655,10 +653,10 @@ void SceneView::cull() } -void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage) +bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& modelview,osgUtil::CullVisitor* cullVisitor, osgUtil::StateGraph* rendergraph, osgUtil::RenderStage* renderStage) { - if (!_camera || !getViewport()) return; + if (!_camera || !getViewport()) return false; osg::ref_ptr proj = new osg::RefMatrix(projection); osg::ref_ptr mv = new osg::RefMatrix(modelview); @@ -722,6 +720,7 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod cullVisitor->inheritCullSettings(*this); + cullVisitor->setClearNode(NULL); // reset earth sky on each frame. cullVisitor->setStateGraph(rendergraph); @@ -813,6 +812,10 @@ void SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod // set the number of dynamic objects in the scene. _dynamicObjectCount += renderStage->computeNumberOfDynamicRenderLeaves(); + + + bool computeNearFar = (cullVisitor->getComputeNearFarMode()!=osgUtil::CullVisitor::DO_NOT_COMPUTE_NEAR_FAR) && getSceneData()!=0; + return computeNearFar; } void SceneView::releaseAllGLObjects()