]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/renderer.cxx
Merge branch 'merge-requests/1555' into next
[flightgear.git] / src / Main / renderer.cxx
index 72f7b4dadb2442ed61061fdf64d15704dd9d7e9b..48b22841cef5411dbed1612966f38604ab51eda4 100644 (file)
@@ -93,6 +93,7 @@
 #include <GUI/new_gui.hxx>
 #include <Instrumentation/HUD/HUD.hxx>
 #include <Environment/precipitation_mgr.hxx>
+#include <Environment/environment_mgr.hxx>
 
 #include "splash.hxx"
 #include "renderer.hxx"
@@ -374,9 +375,6 @@ public:
 
 bool FGScenerySwitchCallback::scenery_enabled = false;
 
-// Sky structures
-SGSky *thesky;
-
 static osg::ref_ptr<osg::FrameStamp> mFrameStamp = new osg::FrameStamp;
 static osg::ref_ptr<SGUpdateVisitor> mUpdateVisitor= new SGUpdateVisitor;
 
@@ -384,10 +382,18 @@ static osg::ref_ptr<osg::Group> mRealRoot = new osg::Group;
 
 static osg::ref_ptr<osg::Group> mRoot = new osg::Group;
 
-FGRenderer::FGRenderer()
+#ifdef FG_JPEG_SERVER
+static void updateRenderer()
+{
+    globals->get_renderer()->update();
+}
+#endif
+
+FGRenderer::FGRenderer() :
+    _sky(NULL)
 {
 #ifdef FG_JPEG_SERVER
-   jpgRenderFrame = FGRenderer::update;
+   jpgRenderFrame = updateRenderer;
 #endif
    eventHandler = new FGEventHandler;
 }
@@ -397,6 +403,7 @@ FGRenderer::~FGRenderer()
 #ifdef FG_JPEG_SERVER
    jpgRenderFrame = NULL;
 #endif
+    delete _sky;
 }
 
 // Initialize various GL/view parameters
@@ -404,7 +411,7 @@ FGRenderer::~FGRenderer()
 // critical parts of the scene graph in addition to the splash screen.
 void
 FGRenderer::splashinit( void ) {
-    osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
+    osgViewer::Viewer* viewer = getViewer();
     mRealRoot = dynamic_cast<osg::Group*>(viewer->getSceneData());
     mRealRoot->addChild(fgCreateSplashNode());
     mFrameStamp = viewer->getFrameStamp();
@@ -440,6 +447,27 @@ FGRenderer::init( void )
 
     _cloud_status = fgGetNode("/environment/clouds/status", true);
     _visibility_m = fgGetNode("/environment/visibility-m", true);
+    
+    bool use_point_sprites = _point_sprites->getBoolValue();
+    bool enhanced_lighting = _enhanced_lighting->getBoolValue();
+    bool distance_attenuation = _distance_attenuation->getBoolValue();
+
+    SGConfigureDirectionalLights( use_point_sprites, enhanced_lighting,
+                                  distance_attenuation );
+    
+// create sky, but can't build until setupView, since we depend
+// on other subsystems to be inited, eg Ephemeris    
+    _sky = new SGSky;
+    
+    SGPath texture_path(globals->get_fg_root());
+    texture_path.append("Textures");
+    texture_path.append("Sky");
+    for (int i = 0; i < FGEnvironmentMgr::MAX_CLOUD_LAYERS; i++) {
+        SGCloudLayer * layer = new SGCloudLayer(texture_path.str());
+        _sky->add_cloud_layer(layer);
+    }
+    
+    _sky->texture_path( texture_path.str() );
 }
 
 void
@@ -458,6 +486,17 @@ FGRenderer::setupView( void )
     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
+    _sky->build( 80000.0, 80000.0,
+                  463.3, 361.8,
+                  *globals->get_ephem(),
+                  fgGetNode("/environment", true));
+    
     viewer->getCamera()
         ->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
     
@@ -533,15 +572,17 @@ FGRenderer::setupView( void )
     sunLight->setUpdateCallback(new FGLightSourceUpdateCallback(true));
     sunLight->setReferenceFrame(osg::LightSource::RELATIVE_RF);
     sunLight->setLocalStateSetModes(osg::StateAttribute::ON);
+    
     // Hang a StateSet above the sky subgraph in order to turn off
     // light 0
     Group* skyGroup = new Group;
     StateSet* skySS = skyGroup->getOrCreateStateSet();
     skySS->setMode(GL_LIGHT0, StateAttribute::OFF);
-    skyGroup->addChild(thesky->getPreRoot());
+    skyGroup->addChild(_sky->getPreRoot());
     sunLight->addChild(skyGroup);
     mRoot->addChild(sceneGroup);
     mRoot->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);
@@ -580,7 +621,7 @@ 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.
-    mRealRoot->addChild(thesky->getCloudRoot());
+    mRealRoot->addChild(_sky->getCloudRoot());
     mRealRoot->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.
@@ -588,15 +629,9 @@ FGRenderer::setupView( void )
     stateSet->setAttributeAndModes(new osg::Program, osg::StateAttribute::ON);
 }
 
-void
-FGRenderer::update()
-{
-    globals->get_renderer()->update(true);
-}
-
 // Update all Visuals (redraws anything graphics related)
 void
-FGRenderer::update( bool refresh_camera_settings ) {
+FGRenderer::update( ) {
     if (!(_scenery_loaded->getBoolValue() || 
            _scenery_override->getBoolValue()))
     {
@@ -619,21 +654,24 @@ FGRenderer::update( bool refresh_camera_settings ) {
         _splash_alpha->setDoubleValue(sAlpha);
     }
 
-    bool skyblend = _skyblend->getBoolValue();
-    bool use_point_sprites = _point_sprites->getBoolValue();
-    bool enhanced_lighting = _enhanced_lighting->getBoolValue();
-    bool distance_attenuation = _distance_attenuation->getBoolValue();
-
-    // OSGFIXME
-    SGConfigureDirectionalLights( use_point_sprites, enhanced_lighting,
-                                  distance_attenuation );
+#if 0 // OSGFIXME
+    // OSGFIXME: features no longer available or no longer run-time configurable
+    {
+        bool use_point_sprites = _point_sprites->getBoolValue();
+        bool enhanced_lighting = _enhanced_lighting->getBoolValue();
+        bool distance_attenuation = _distance_attenuation->getBoolValue();
+    
+        SGConfigureDirectionalLights( use_point_sprites, enhanced_lighting,
+                                      distance_attenuation );
+    }
+#endif
 
     FGLight *l = static_cast<FGLight*>(globals->get_subsystem("lighting"));
 
     // update fog params
     double actual_visibility;
     if (_cloud_status->getBoolValue()) {
-        actual_visibility = thesky->get_visibility();
+        actual_visibility = _sky->get_visibility();
     } else {
         actual_visibility = _visibility_m->getDoubleValue();
     }
@@ -645,14 +683,10 @@ FGRenderer::update( bool refresh_camera_settings ) {
     FGViewer *current__view = globals->get_current_view();
     // Force update of center dependent values ...
     current__view->set_dirty();
-
-    if ( refresh_camera_settings ) {
-        // update view port
-        resize( _xsize->getIntValue(),
-                _ysize->getIntValue() );
-    }
+  
     osg::Camera *camera = viewer->getCamera();
 
+    bool skyblend = _skyblend->getBoolValue();
     if ( skyblend ) {
        
         if ( _textures->getBoolValue() ) {
@@ -666,10 +700,10 @@ FGRenderer::update( bool refresh_camera_settings ) {
 
     // update fog params if visibility has changed
     double visibility_meters = _visibility_m->getDoubleValue();
-    thesky->set_visibility(visibility_meters);
+    _sky->set_visibility(visibility_meters);
 
     double altitude_m = _altitude_ft->getDoubleValue() * SG_FEET_TO_METER;
-    thesky->modify_vis( altitude_m, 0.0 /* time factor, now unused */);
+    _sky->modify_vis( altitude_m, 0.0 /* time factor, now unused */);
 
     // update the sky dome
     if ( skyblend ) {
@@ -713,8 +747,8 @@ FGRenderer::update( bool refresh_camera_settings ) {
         scolor.moon_angle  = l->get_moon_angle();
   
         double delta_time_sec = _sim_delta_sec->getDoubleValue();
-        thesky->reposition( sstate, *globals->get_ephem(), delta_time_sec );
-        thesky->repaint( scolor, *globals->get_ephem() );
+        _sky->reposition( sstate, *globals->get_ephem(), delta_time_sec );
+        _sky->repaint( scolor, *globals->get_ephem() );
 
             //OSGFIXME
 //         shadows->setupShadows(
@@ -766,41 +800,15 @@ FGRenderer::update( bool refresh_camera_settings ) {
     CameraGroup::getDefault()->setCameraCullMasks(cullMask);
 }
 
-
-
-// options.cxx needs to see this for toggle_panel()
-// Handle new window size or exposure
 void
-FGRenderer::resize( int width, int height ) {
-
-// the following breaks aspect-ratio of the main 3D scenery window when 2D panels are moved
-// in y direction - causing issues for aircraft with 2D panels (/sim/virtual_cockpit=false).
-// Disabling for now. Seems this useful for the pre-OSG time only.
-//    if ( (!_virtual_cockpit->getBoolValue())
-//         && fgPanelVisible() && idle_state == 1000 ) {
-//        view_h = (int)(height * (globals->get_current_panel()->getViewHeight() -
-//                             globals->get_current_panel()->getYOffset()) / 768.0);
-//    }
-
+FGRenderer::resize( int width, int height )
+{
     int curWidth = _xsize->getIntValue(),
         curHeight = _ysize->getIntValue();
-
-    if ((width == curWidth) && (height == curHeight)) {
-      return;
-    }
-
-    SG_LOG(SG_GENERAL, SG_INFO, "renderer resized to " << width << "," << height);
-
-    _xsize->setIntValue(width);
-    _ysize->setIntValue(height);
-    double aspect = height / (double) width;
-
-    // for all views
-    FGViewMgr *viewmgr = globals->get_viewmgr();
-    if (viewmgr) {
-        for ( int i = 0; i < viewmgr->size(); ++i ) {
-            viewmgr->get_view(i)->set_aspect_ratio(aspect);
-        }
+    if ((curHeight != height) || (curWidth != width)) {
+    // must guard setting these, or PLIB-PUI fails with too many live interfaces
+        _xsize->setIntValue(width);
+        _ysize->setIntValue(height);
     }
 }