Added SceneView::Options enum enetries APPLY_GLOBAL_DEFAULTS and CLEAR_GLOBAL_STATESET to control whether a _globalStateSet->clear() and _globalStateSet->setGlobalDefaults() should be called.

osgViewer::Renderer doesn't use these enum settings so now no longer has a calls StateSet::clear() or StateSet::setGlobalDefaults() on the osg::Camera's StateSet.  Previously these were being
called and breaking the ability to attached state to Camera's StateSet.
This commit is contained in:
Robert Osfield
2013-07-02 09:27:14 +00:00
parent 0abbef71e1
commit d3c2896651
2 changed files with 25 additions and 13 deletions

View File

@@ -50,8 +50,14 @@ class OSGUTIL_EXPORT SceneView : public osg::Object, public osg::CullSettings
HEADLIGHT = 0x1,
SKY_LIGHT = 0x2,
COMPILE_GLOBJECTS_AT_INIT = 0x4,
APPLY_GLOBAL_DEFAULTS = 0x8,
CLEAR_GLOBAL_STATESET = 0x16,
STANDARD_SETTINGS = HEADLIGHT |
COMPILE_GLOBJECTS_AT_INIT
COMPILE_GLOBJECTS_AT_INIT |
APPLY_GLOBAL_DEFAULTS |
APPLY_GLOBAL_DEFAULTS |
CLEAR_GLOBAL_STATESET
};
/* Set defaults. */

View File

@@ -207,7 +207,9 @@ void SceneView::setDefaults(unsigned int options)
_camera->getViewMatrix().makeIdentity();
if (!_globalStateSet) _globalStateSet = new osg::StateSet;
else _globalStateSet->clear();
// clear the global StateSet (main Camera's StateSet) if required
if ((options & CLEAR_GLOBAL_STATESET)) _globalStateSet->clear();
if ((options & HEADLIGHT) || (options & SKY_LIGHT))
{
@@ -270,16 +272,20 @@ void SceneView::setDefaults(unsigned int options)
_cullVisitor->setStateGraph(_stateGraph.get());
_cullVisitor->setRenderStage(_renderStage.get());
_globalStateSet->setGlobalDefaults();
// apply defaults on the global StateSet (main Camera's StateSet) if required
if ((options&APPLY_GLOBAL_DEFAULTS))
{
_globalStateSet->setGlobalDefaults();
#if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
// set up an texture environment by default to speed up blending operations.
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::MODULATE);
_globalStateSet->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON);
#endif
#if defined(OSG_GL_FIXED_FUNCTION_AVAILABLE)
// set up an texture environment by default to speed up blending operations.
osg::TexEnv* texenv = new osg::TexEnv;
texenv->setMode(osg::TexEnv::MODULATE);
_globalStateSet->setTextureAttributeAndModes(0,texenv, osg::StateAttribute::ON);
#endif
_camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f));
_camera->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f));
}
}
void SceneView::setCamera(osg::Camera* camera, bool assumeOwnershipOfCamera)
@@ -458,7 +464,7 @@ osg::Matrixd SceneView::computeRightEyeProjectionImplementation(const osg::Matri
osg::Matrixd SceneView::computeRightEyeViewImplementation(const osg::Matrixd& view) const
{
if (!_displaySettings) return view;
double sd = _displaySettings->getScreenDistance();
double fusionDistance = sd;
switch(_fusionDistanceMode)
@@ -543,7 +549,7 @@ void SceneView::computeRightEyeViewport(const osg::Viewport *viewport)
(*_viewportRight) = *viewport;
return;
}
switch(_displaySettings->getStereoMode())
{
case(osg::DisplaySettings::HORIZONTAL_SPLIT):
@@ -1371,7 +1377,7 @@ void SceneView::draw()
}
_renderStage->setColorMask(cmask);
}
// bog standard draw.
_renderStage->drawPreRenderStages(_renderInfo,previous);
_renderStage->draw(_renderInfo,previous);