From f795770fed870b982e9082e55723ce501612e470 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 21 Jan 2010 10:24:48 +0000 Subject: [PATCH] Added support for passing on slave Camera's StateSet's to the rendering backend. --- include/osgUtil/SceneView | 6 ++++++ src/osgUtil/SceneView.cpp | 2 ++ src/osgViewer/Renderer.cpp | 44 ++++++++++++++++++++++++++++++++------ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/include/osgUtil/SceneView b/include/osgUtil/SceneView index acb3af417..300931a1f 100644 --- a/include/osgUtil/SceneView +++ b/include/osgUtil/SceneView @@ -131,6 +131,10 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings osg::StateSet* getGlobalStateSet() { return _globalStateSet.get(); } const osg::StateSet* getGlobalStateSet() const { return _globalStateSet.get(); } + void setSecondaryStateSet(osg::StateSet* state) { _secondaryStateSet = state; } + osg::StateSet* getSecondaryStateSet() { return _secondaryStateSet.get(); } + const osg::StateSet* getSecondaryStateSet() const { return _secondaryStateSet.get(); } + void setLocalStateSet(osg::StateSet* state) { _localStateSet = state; } osg::StateSet* getLocalStateSet() { return _localStateSet.get(); } const osg::StateSet* getLocalStateSet() const { return _localStateSet.get(); } @@ -523,6 +527,8 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings osg::ref_ptr _light; osg::ref_ptr _displaySettings; + osg::ref_ptr _secondaryStateSet; + FusionDistanceMode _fusionDistanceMode; float _fusionDistanceValue; diff --git a/src/osgUtil/SceneView.cpp b/src/osgUtil/SceneView.cpp index 01f3e7c68..467a18ec1 100644 --- a/src/osgUtil/SceneView.cpp +++ b/src/osgUtil/SceneView.cpp @@ -960,6 +960,7 @@ bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod #endif if (_globalStateSet.valid()) cullVisitor->pushStateSet(_globalStateSet.get()); + if (_secondaryStateSet.valid()) cullVisitor->pushStateSet(_secondaryStateSet.get()); if (_localStateSet.valid()) cullVisitor->pushStateSet(_localStateSet.get()); @@ -982,6 +983,7 @@ bool SceneView::cullStage(const osg::Matrixd& projection,const osg::Matrixd& mod cullVisitor->popViewport(); if (_localStateSet.valid()) cullVisitor->popStateSet(); + if (_secondaryStateSet.valid()) cullVisitor->popStateSet(); if (_globalStateSet.valid()) cullVisitor->popStateSet(); diff --git a/src/osgViewer/Renderer.cpp b/src/osgViewer/Renderer.cpp index b29025913..b8aed3295 100644 --- a/src/osgViewer/Renderer.cpp +++ b/src/osgViewer/Renderer.cpp @@ -178,9 +178,20 @@ Renderer::Renderer(osg::Camera* camera): _sceneView[0] = new osgUtil::SceneView; _sceneView[1] = new osgUtil::SceneView; - osg::Camera* masterCamera = _camera->getView() ? _camera->getView()->getCamera() : camera; - osg::StateSet* stateset = masterCamera->getOrCreateStateSet(); + + osg::StateSet* global_stateset = 0; + osg::StateSet* secondary_stateset = 0; + if (_camera != masterCamera) + { + global_stateset = masterCamera->getOrCreateStateSet(); + secondary_stateset = _camera->getStateSet(); + } + else + { + global_stateset = _camera->getOrCreateStateSet(); + } + osgViewer::View* view = dynamic_cast(_camera->getView()); osg::DisplaySettings* ds = _camera->getDisplaySettings() ? _camera->getDisplaySettings() : @@ -197,8 +208,11 @@ Renderer::Renderer(osg::Camera* camera): } } - _sceneView[0]->setGlobalStateSet(stateset); - _sceneView[1]->setGlobalStateSet(stateset); + _sceneView[0]->setGlobalStateSet(global_stateset); + _sceneView[0]->setSecondaryStateSet(secondary_stateset); + + _sceneView[1]->setGlobalStateSet(global_stateset); + _sceneView[1]->setSecondaryStateSet(secondary_stateset); _sceneView[0]->setDefaults(sceneViewOptions); _sceneView[1]->setDefaults(sceneViewOptions); @@ -234,11 +248,27 @@ void Renderer::setGraphicsThreadDoesCull(bool flag) void Renderer::updateSceneView(osgUtil::SceneView* sceneView) { osg::Camera* masterCamera = _camera->getView() ? _camera->getView()->getCamera() : _camera.get(); - osg::StateSet* stateset = masterCamera->getOrCreateStateSet(); - if (sceneView->getGlobalStateSet()!=stateset) + osg::StateSet* global_stateset = 0; + osg::StateSet* secondary_stateset = 0; + if (_camera != masterCamera) { - sceneView->setGlobalStateSet(stateset); + global_stateset = masterCamera->getOrCreateStateSet(); + secondary_stateset = _camera->getStateSet(); + } + else + { + global_stateset = _camera->getOrCreateStateSet(); + } + + if (sceneView->getGlobalStateSet()!=global_stateset) + { + sceneView->setGlobalStateSet(global_stateset); + } + + if (sceneView->getSecondaryStateSet()!=secondary_stateset) + { + sceneView->setSecondaryStateSet(secondary_stateset); } osg::GraphicsContext* context = _camera->getGraphicsContext();