Added support for passing on slave Camera's StateSet's to the rendering backend.

This commit is contained in:
Robert Osfield 2010-01-21 10:24:48 +00:00
parent f1bd2eaf04
commit f795770fed
3 changed files with 45 additions and 7 deletions

View File

@ -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<osg::Light> _light;
osg::ref_ptr<osg::DisplaySettings> _displaySettings;
osg::ref_ptr<osg::StateSet> _secondaryStateSet;
FusionDistanceMode _fusionDistanceMode;
float _fusionDistanceValue;

View File

@ -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();

View File

@ -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<osgViewer::View*>(_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();