_root->setName("fakeRoot");
_updateVisitor = new SGUpdateVisitor;
- _root = new osg::Group;
+
+ // when Rembrandt is enabled, we use this group to access the whole
+ // scene. Since the only child is the _viewerSceneRoot, we could
+ // simply copy the reference, we don't need the additional group.
_deferredRealRoot = new osg::Group;
_numCascades = 4;
return info;
}
-void
-FGRenderer::setupView( void )
+void FGRenderer::setupRoot()
{
- osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
- osg::initNotifyLevel();
-
- // The number of polygon-offset "units" to place between layers. In
- // principle, one is supposed to be enough. In practice, I find that
- // my hardware/driver requires many more.
- osg::PolygonOffset::setUnitsMultiplier(1);
- osg::PolygonOffset::setFactorMultiplier(1);
-
-// build the sky
- // The sun and moon diameters are scaled down numbers of the
- // actual diameters. This was needed to fit both the sun and the
- // moon within the distance to the far clip plane.
- // Moon diameter: 3,476 kilometers
- // Sun diameter: 1,390,000 kilometers
- osg::ref_ptr<SGReaderWriterOptions> opt;
- opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
- opt->setPropertyNode(globals->get_props());
- _sky->build( 80000.0, 80000.0,
- 463.3, 361.8,
- *globals->get_ephem(),
- fgGetNode("/environment", true),
- opt.get());
-
- viewer->getCamera()
- ->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
-
osg::StateSet* stateSet = _root->getOrCreateStateSet();
-
+
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
stateSet->setAttribute(new osg::Depth(osg::Depth::LESS));
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
-
- stateSet->setAttribute(new osg::AlphaFunc(osg::AlphaFunc::GREATER, 0.01));
- stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::OFF);
+
stateSet->setAttribute(new osg::BlendFunc);
stateSet->setMode(GL_BLEND, osg::StateAttribute::OFF);
-
+
stateSet->setMode(GL_FOG, osg::StateAttribute::OFF);
// this will be set below
stateSet->setMode(GL_NORMALIZE, osg::StateAttribute::OFF);
-
+
osg::Material* material = new osg::Material;
stateSet->setAttribute(material);
stateSet->setTextureAttribute(0, new osg::TexEnv);
stateSet->setTextureMode(0, GL_TEXTURE_2D, osg::StateAttribute::OFF);
-
+
osg::Hint* hint = new osg::Hint(GL_FOG_HINT, GL_DONT_CARE);
hint->setUpdateCallback(new FGHintUpdateCallback("/sim/rendering/fog"));
stateSet->setAttribute(hint);
hint = new osg::Hint(GL_PERSPECTIVE_CORRECTION_HINT, GL_DONT_CARE);
hint->setUpdateCallback(new FGHintUpdateCallback("/sim/rendering/perspective-correction"));
stateSet->setAttribute(hint);
+}
+
+void
+FGRenderer::setupView( void )
+{
+ osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
+ osg::initNotifyLevel();
- osg::Group* sceneGroup = new osg::Group;
- sceneGroup->setName("rendererScene");
- sceneGroup->addChild(globals->get_scenery()->get_scene_graph());
- sceneGroup->setNodeMask(~simgear::BACKGROUND_BIT);
-
- //sceneGroup->addChild(thesky->getCloudRoot());
-
- stateSet = sceneGroup->getOrCreateStateSet();
- stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
+ // The number of polygon-offset "units" to place between layers. In
+ // principle, one is supposed to be enough. In practice, I find that
+ // my hardware/driver requires many more.
+ osg::PolygonOffset::setUnitsMultiplier(1);
+ osg::PolygonOffset::setFactorMultiplier(1);
+ setupRoot();
+
+// build the sky
+ // The sun and moon diameters are scaled down numbers of the
+ // actual diameters. This was needed to fit both the sun and the
+ // moon within the distance to the far clip plane.
+ // Moon diameter: 3,476 kilometers
+ // Sun diameter: 1,390,000 kilometers
+ osg::ref_ptr<SGReaderWriterOptions> opt;
+ opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
+ opt->setPropertyNode(globals->get_props());
+ _sky->build( 80000.0, 80000.0,
+ 463.3, 361.8,
+ *globals->get_ephem(),
+ fgGetNode("/environment", true),
+ opt.get());
+
+ viewer->getCamera()
+ ->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
+
+
// need to update the light on every frame
// OSG LightSource objects are rather confusing. OSG only supports
// the 10 lights specified by OpenGL itself; if more than one
// has the corresponding OpenGL light enabled: a LightSource will
// affect geometry anywhere in the scene graph that has its light
// number enabled in a state set.
- LightSource* lightSource = new LightSource;
+ osg::ref_ptr<LightSource> lightSource = new LightSource;
lightSource->setName("FGLightSource");
lightSource->getLight()->setDataVariance(Object::DYNAMIC);
// relative because of CameraView being just a clever transform node
_viewerSceneRoot->addChild(lightSource);
// we need a white diffuse light for the phase of the moon
- osg::LightSource* sunLight = new osg::LightSource;
+ osg::ref_ptr<LightSource> sunLight = new osg::LightSource;
sunLight->setName("sunLightSource");
sunLight->getLight()->setDataVariance(Object::DYNAMIC);
sunLight->getLight()->setLightNum(1);
// Hang a StateSet above the sky subgraph in order to turn off
// light 0
- Group* skyGroup = new Group;
- skyGroup->setName("rendererSkyParent");
+ Group* skyGroup = _sky->getPreRoot();
StateSet* skySS = skyGroup->getOrCreateStateSet();
skySS->setMode(GL_LIGHT0, StateAttribute::OFF);
- skyGroup->addChild(_sky->getPreRoot());
sunLight->addChild(skyGroup);
- _root->addChild(sceneGroup);
- if ( _classicalRenderer )
+ if ( _classicalRenderer ) {
_root->addChild(sunLight);
-
- // Clouds are added to the scene graph later
- stateSet = globals->get_scenery()->get_scene_graph()->getOrCreateStateSet();
- stateSet->setMode(GL_ALPHA_TEST, osg::StateAttribute::ON);
+ }
+
+ osg::Group* sceneGroup = globals->get_scenery()->get_scene_graph();
+ sceneGroup->setName("rendererScene");
+ sceneGroup->setNodeMask(~simgear::BACKGROUND_BIT);
+ _root->addChild(sceneGroup);
+
+ // setup state-set for main scenery (including models and aircraft)
+ osg::StateSet* stateSet = sceneGroup->getOrCreateStateSet();
stateSet->setMode(GL_LIGHTING, osg::StateAttribute::ON);
stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
// The clouds are attached directly to the scene graph root
// because, in theory, they don't want the same default state set
// as the rest of the scene. This may not be true in practice.
- if ( _classicalRenderer ) {
- _viewerSceneRoot->addChild(_sky->getCloudRoot());
- _viewerSceneRoot->addChild(FGCreateRedoutNode());
- }
+ if ( _classicalRenderer ) {
+ _viewerSceneRoot->addChild(_sky->getCloudRoot());
+ _viewerSceneRoot->addChild(FGCreateRedoutNode());
+ }
+
// Attach empty program to the scene root so that shader programs
// don't leak into state sets (effects) that shouldn't have one.
stateSet = _viewerSceneRoot->getOrCreateStateSet();