]> git.mxchange.org Git - flightgear.git/blobdiff - src/Viewer/renderer.cxx
toggle fullscreen: also adapt GUI plane when resizing
[flightgear.git] / src / Viewer / renderer.cxx
index 9d64ddc523495987283918507799751b1ae4ce61..8745d4189de38d4dd804df2d28c5661dd10df7c9 100644 (file)
@@ -74,6 +74,7 @@
 #include <simgear/scene/model/animation.hxx>
 #include <simgear/scene/model/placement.hxx>
 #include <simgear/scene/sky/sky.hxx>
+#include <simgear/scene/util/DeletionManager.hxx>
 #include <simgear/scene/util/SGUpdateVisitor.hxx>
 #include <simgear/scene/util/RenderConstants.hxx>
 #include <simgear/scene/util/SGSceneUserData.hxx>
 #include "CameraGroup.hxx"
 #include "FGEventHandler.hxx"
 
+#include <plib/pu.h>
+
 using namespace osg;
 using namespace simgear;
 using namespace flightgear;
@@ -513,7 +516,6 @@ FGRenderer::init( void )
     if (!_classicalRenderer)
         _pipeline = makeRenderingPipeline(_renderer, 0);
     _scenery_loaded   = fgGetNode("/sim/sceneryloaded", true);
-    _scenery_override = fgGetNode("/sim/sceneryloaded-override", true);
     _panel_hotspots   = fgGetNode("/sim/panel-hotspots", true);
     _virtual_cockpit  = fgGetNode("/sim/virtual-cockpit", true);
 
@@ -576,6 +578,7 @@ FGRenderer::init( void )
 
     if (!_classicalRenderer) {
         eventHandler->setChangeStatsCameraRenderOrder( true );
+        _sky->set_minimum_sky_visibility( 0.0 ); // A black sky appears for below that
     }
 }
 
@@ -1141,12 +1144,14 @@ FGRenderer::buildDeferredFullscreenCamera( flightgear::CameraInfo* info, const F
     ss->addUniform( _shadowDistances );
     ss->addUniform( _fogColor );
     ss->addUniform( _fogDensity );
-    ss->addUniform( _planes );
 
     osg::Geometry* g = osg::createTexturedQuadGeometry( osg::Vec3(-1.,-1.,0.), osg::Vec3(2.,0.,0.), osg::Vec3(0.,2.,0.) );
     g->setUseDisplayList(false);
     simgear::EffectGeode* eg = new simgear::EffectGeode;
-    simgear::Effect* effect = simgear::makeEffect(pass->effect, true);
+    osg::ref_ptr<SGReaderWriterOptions> opt;
+    opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
+    opt->setPropertyNode(globals->get_props());
+    simgear::Effect* effect = simgear::makeEffect(pass->effect, true, opt.get());
     if (effect) {
         eg->setEffect( effect );
     }
@@ -1187,18 +1192,21 @@ FGRenderer::buildDeferredFullscreenCamera( flightgear::CameraInfo* info, osg::Gr
 }
 
 void
-FGRenderer::buildDeferredDisplayCamera( osg::Camera* camera, flightgear::CameraInfo* info, const std::string& name, osg::GraphicsContext* gc )
+FGRenderer::buildDeferredDisplayCamera( osg::Camera* camera, flightgear::CameraInfo* info, const FGRenderingPipeline::Stage* stage, osg::GraphicsContext* gc )
 {
     camera->setName( "DisplayC" );
-    camera->setCullCallback( new FGDeferredRenderingCameraCullCallback( name, info ) );
+    camera->setCullCallback( new FGDeferredRenderingCameraCullCallback( stage->name, info ) );
     camera->setReferenceFrame(Transform::ABSOLUTE_RF);
     camera->setAllowEventFocus(false);
     osg::Geometry* g = osg::createTexturedQuadGeometry( osg::Vec3(-1.,-1.,0.), osg::Vec3(2.,0.,0.), osg::Vec3(0.,2.,0.) );
     g->setUseDisplayList(false); //DEBUG
     simgear::EffectGeode* eg = new simgear::EffectGeode;
-    simgear::Effect* effect = simgear::makeEffect("Effects/display", true);
+    osg::ref_ptr<SGReaderWriterOptions> opt;
+    opt = SGReaderWriterOptions::fromPath(globals->get_fg_root());
+    opt->setPropertyNode(globals->get_props());
+    simgear::Effect* effect = simgear::makeEffect(stage->effect, true, opt.get());
     if (!effect) {
-        SG_LOG(SG_VIEW, SG_ALERT, "Effects/display not found");
+        SG_LOG(SG_VIEW, SG_ALERT, stage->effect + " not found");
         return;
     }
     eg->setEffect(effect);
@@ -1210,6 +1218,25 @@ FGRenderer::buildDeferredDisplayCamera( osg::Camera* camera, flightgear::CameraI
 
     osg::StateSet* ss = camera->getOrCreateStateSet();
     ss->addUniform( _depthInColor );
+    ss->addUniform( info->projInverse );
+    ss->addUniform( info->viewInverse );
+    ss->addUniform( info->view );
+    ss->addUniform( info->bufferSize );
+    ss->addUniform( info->worldPosCart );
+    ss->addUniform( info->worldPosGeod );
+    ss->addUniform( info->shadowMatrix[0] );
+    ss->addUniform( info->shadowMatrix[1] );
+    ss->addUniform( info->shadowMatrix[2] );
+    ss->addUniform( info->shadowMatrix[3] );
+    ss->addUniform( _ambientFactor );
+    ss->addUniform( _sunDiffuse );
+    ss->addUniform( _sunSpecular );
+    ss->addUniform( _sunDirection );
+    ss->addUniform( _planes );
+    ss->addUniform( _shadowNumber );
+    ss->addUniform( _shadowDistances );
+    ss->addUniform( _fogColor );
+    ss->addUniform( _fogDensity );
 }
 
 void
@@ -1236,7 +1263,7 @@ FGRenderer::buildStage(CameraInfo* info,
         camera = buildDeferredFullscreenCamera(info, gc, stage);
     else if (stage->type == "display") {
         camera = mainCamera;
-        buildDeferredDisplayCamera(camera, info, stage->name, gc);
+        buildDeferredDisplayCamera(camera, info, stage, gc);
     } else
         throw sg_exception("Stage type is not supported");
 
@@ -1255,6 +1282,8 @@ osg::Node*
 FGRenderer::buildLightingSkyCloudsPass(FGRenderingPipeline::Pass* pass)
 {
     Group* group = new Group;
+    StateSet* ss = group->getOrCreateStateSet();
+    ss->setAttributeAndModes( new osg::ColorMask( true, true, true, false ), osg::StateAttribute::ON );
     group->addChild( _sky->getPreRoot() );
     group->addChild( _sky->getCloudRoot() );
     return group;
@@ -1267,6 +1296,8 @@ FGRenderer::buildLightingLightsPass(CameraInfo* info, FGRenderingPipeline::Pass*
     StateSet* ss = lightCam->getOrCreateStateSet();
     ss->addUniform( _planes );
     ss->addUniform( info->bufferSize );
+    ss->addUniform( _fogColor );
+    ss->addUniform( _fogDensity );
     lightCam->setName( "LightCamera" );
     lightCam->setClearMask(0);
     lightCam->setAllowEventFocus(false);
@@ -1275,7 +1306,7 @@ FGRenderer::buildLightingLightsPass(CameraInfo* info, FGRenderingPipeline::Pass*
     lightCam->setViewMatrix(osg::Matrix::identity());
     lightCam->setProjectionMatrix(osg::Matrix::identity());
     lightCam->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
-    lightCam->setCullMask( simgear::MODELLIGHT_BIT | simgear::PANEL2D_BIT );
+    lightCam->setCullMask( simgear::MODELLIGHT_BIT | simgear::PANEL2D_BIT | simgear::PERMANENTLIGHT_BIT);
     lightCam->setInheritanceMask( osg::CullSettings::ALL_VARIABLES & ~osg::CullSettings::CULL_MASK );
     lightCam->addChild( mDeferredRealRoot.get() );
 
@@ -1349,20 +1380,20 @@ FGRenderer::setupView( void )
     osg::PolygonOffset::setUnitsMultiplier(1);
     osg::PolygonOffset::setFactorMultiplier(1);
 
-    // Go full screen if requested ...
-    if ( fgGetBool("/sim/startup/fullscreen") )
-        fgOSFullScreen();
-
 // 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));
+                  fgGetNode("/environment", true),
+                  opt.get());
     
     viewer->getCamera()
         ->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
@@ -1503,14 +1534,15 @@ FGRenderer::setupView( void )
     stateSet = mRealRoot->getOrCreateStateSet();
     stateSet->setAttributeAndModes(new osg::Program, osg::StateAttribute::ON);
 
-       mDeferredRealRoot->addChild( mRealRoot.get() );
+    mDeferredRealRoot->addChild( mRealRoot.get() );
+
+    DeletionManager::install(mRealRoot.get());
 }
-                                    
+
 // Update all Visuals (redraws anything graphics related)
 void
 FGRenderer::update( ) {
-    if (!(_scenery_loaded->getBoolValue() || 
-           _scenery_override->getBoolValue()))
+    if (!_scenery_loaded->getBoolValue())
     {
         _splash_alpha->setDoubleValue(1.0);
         return;