]> git.mxchange.org Git - flightgear.git/blobdiff - src/Viewer/renderer.cxx
commradio: improvements for atis speech
[flightgear.git] / src / Viewer / renderer.cxx
index 944d598b56c488e573c8c879df948a690132bc49..9728f0f72ac0757c255a8d6ac75e5d3b2efea667 100644 (file)
@@ -401,7 +401,10 @@ FGRenderer::FGRenderer() :
     _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;
@@ -1389,59 +1392,29 @@ CameraInfo* FGRenderer::buildCameraFromRenderingPipeline(FGRenderingPipeline* rp
     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);
@@ -1457,17 +1430,41 @@ FGRenderer::setupView( void )
     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
@@ -1478,7 +1475,7 @@ FGRenderer::setupView( void )
     // 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
@@ -1488,7 +1485,7 @@ FGRenderer::setupView( void )
     _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);
@@ -1498,20 +1495,22 @@ FGRenderer::setupView( void )
     
     // 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);
 
@@ -1553,10 +1552,11 @@ FGRenderer::setupView( void )
     // 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();