]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/renderer.cxx
Vivian Meazza:
[flightgear.git] / src / Main / renderer.cxx
index afc92a537d90e462cfe26b71ef980e1c52327513..0e5ecb3e41ffe1f474591a01ee74ec76b300585f 100644 (file)
 #include <simgear/screen/jpgfactory.hxx>
 #endif
 
-#ifdef FG_USE_CLOUDS_3D
-#  include <simgear/scene/sky/clouds3d/SkySceneLoader.hpp>
-#  include <simgear/scene/sky/clouds3d/SkyUtil.hpp>
-#endif
 #include <simgear/environment/visual_enviro.hxx>
 
+#include <simgear/scene/model/shadowvolume.hxx>
+
 #include <Scenery/tileentry.hxx>
 #include <Time/light.hxx>
 #include <Time/light.hxx>
@@ -105,11 +103,6 @@ static GLfloat ground_exp2_punch_through;
 // Sky structures
 SGSky *thesky;
 
-#ifdef FG_USE_CLOUDS_3D
-  SkySceneLoader *sgClouds3d;
-  bool _bcloud_orig = true;
-#endif
-
 // hack
 sgMat4 copy_of_ssgOpenGLAxisSwapMatrix =
 {
@@ -124,6 +117,8 @@ ssgSimpleState *default_state;
 ssgSimpleState *hud_and_panel;
 ssgSimpleState *menus;
 
+SGShadowVolume *shadows;
+
 FGRenderer::FGRenderer()
 {
 #ifdef FG_JPEG_SERVER
@@ -179,6 +174,11 @@ FGRenderer::build_states( void ) {
     menus->disable( GL_CULL_FACE );
     menus->disable( GL_TEXTURE_2D );
     menus->enable( GL_BLEND );
+
+    shadows = new SGShadowVolume( globals->get_scenery()->get_scene_graph() );
+    shadows->init( fgGetNode("/sim/rendering", true) );
+    shadows->addOccluder( globals->get_scenery()->get_aircraft_branch(), SGShadowVolume::occluderTypeAircraft );
+
 }
 
 
@@ -244,7 +244,13 @@ FGRenderer::update( bool refresh_camera_settings ) {
         SGAnimation::set_sim_time_sec( 0.0 );
         return;
     }
+//    return; 
 
+       // TODO:TEST only, don't commit that !!
+//     sgFXperFrameInit();
+
+    extern void sgShaderFrameInit(double delta_time_sec);
+    sgShaderFrameInit(delta_time_sec);
 
     bool draw_otw = fgGetBool("/sim/rendering/draw-otw");
     bool skyblend = fgGetBool("/sim/rendering/skyblend");
@@ -314,7 +320,8 @@ FGRenderer::update( bool refresh_camera_settings ) {
     // calculate our current position in cartesian space
     Point3D cntr = globals->get_scenery()->get_next_center();
     globals->get_scenery()->set_center(cntr);
-    current__view->set_scenery_center(cntr);
+    // Force update of center dependent values ...
+    current__view->set_dirty();
 
     if ( refresh_camera_settings ) {
         // update view port
@@ -327,27 +334,6 @@ FGRenderer::update( bool refresh_camera_settings ) {
         ssgSetCamera( (sgVec4 *)current__view->get_VIEW() );
     }
 
-    if ( fgGetBool("/sim/rendering/clouds3d") ) {
-        glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
-        cloud3d_imposter_state->force();
-        glDisable( GL_FOG );
-        glColor4f( 1.0, 1.0, 1.0, 1.0 );
-        glEnable(GL_DEPTH_TEST);
-        glEnable(GL_BLEND);
-        glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
-
-#ifdef FG_USE_CLOUDS_3D
-        if ( _bcloud_orig ) {
-            Point3D c = globals->get_scenery()->get_center();
-            sgClouds3d->Set_Cloud_Orig( &c );
-            _bcloud_orig = false;
-        }
-        sgClouds3d->Update( current__view->get_absolute_view_pos() );
-#endif
-        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
-        glDisable(GL_DEPTH_TEST);
-    }
-
     clear_mask = GL_DEPTH_BUFFER_BIT;
     if ( fgGetBool("/sim/rendering/wireframe") ) {
         clear_mask |= GL_COLOR_BUFFER_BIT;
@@ -404,7 +390,7 @@ FGRenderer::update( bool refresh_camera_settings ) {
         */
 
         static SGSkyColor scolor;
-        FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
+//        FGLight *l = (FGLight *)(globals->get_subsystem("lighting"));
 
         scolor.sky_color   = l->sky_color();
         scolor.fog_color   = l->adj_fog_color();
@@ -471,6 +457,14 @@ FGRenderer::update( bool refresh_camera_settings ) {
         sstate.moon_dist = 40000.0 * moon_horiz_eff;
 
         thesky->reposition( sstate, delta_time_sec );
+
+        shadows->setupShadows( 
+          current__view->getLongitude_deg(),
+          current__view->getLatitude_deg(),
+          globals->get_time_params()->getGst(),
+          globals->get_ephem()->getSunRightAscension(),
+          globals->get_ephem()->getSunDeclination(),
+          l->get_sun_angle());
     }
 
     glEnable( GL_DEPTH_TEST );
@@ -502,9 +496,9 @@ FGRenderer::update( bool refresh_camera_settings ) {
 
     double agl =
         current_aircraft.fdm_state->get_Altitude() * SG_FEET_TO_METER
-        - globals->get_scenery()->get_cur_elev();
+        - cur_fdm_state->get_Runway_altitude_m();
 
-    if ( agl > 50.0 ) {
+    if ( agl > 10.0 ) {
         scene_nearplane = 10.0f;
         scene_farplane = 120000.0f;
     } else {
@@ -679,32 +673,6 @@ FGRenderer::update( bool refresh_camera_settings ) {
         ssgCullAndDraw( globals->get_scenery()->get_gnd_lights_root() );
     }
 
-    if ( draw_otw && fgGetBool("/sim/rendering/clouds3d") ) {
-        glDisable( GL_FOG );
-        glDisable( GL_LIGHTING );
-        // cout << "drawing new clouds" << endl;
-
-        glEnable(GL_DEPTH_TEST);
-        glEnable(GL_BLEND);
-        glBlendFunc( GL_ONE, GL_ONE_MINUS_SRC_ALPHA ) ;
-
-        /*
-        glEnable( GL_TEXTURE_2D );
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-        */
-
-#ifdef FG_USE_CLOUDS_3D
-        sgClouds3d->Draw((sgVec4 *)current__view->get_VIEW());
-#endif
-        glEnable( GL_FOG );
-        glEnable( GL_LIGHTING );
-        glEnable( GL_DEPTH_TEST );
-        glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ) ;
-    }
-
     sgEnviro.drawLightning();
 
     if ( draw_otw && draw_clouds ) {
@@ -731,26 +699,35 @@ FGRenderer::update( bool refresh_camera_settings ) {
         fgGetDouble("/environment/metar/rain-norm", 0.0),
         fgGetDouble("/environment/metar/snow-norm", 0.0),
         fgGetDouble("/environment/metar/hail-norm", 0.0),
-        fgGetDouble("/orientation/pitch-deg", 0.0),
-        fgGetDouble("/orientation/roll-deg", 0.0),
+        current__view->getPitch_deg() - current__view->getPitchOffset_deg(),
+        current__view->getRoll_deg() + current__view->getRollOffset_deg(),
+        - current__view->getHeadingOffset_deg(),
         fgGetDouble("/velocities/airspeed-kt", 0.0));
 
+    // compute shadows and project them on screen
+    bool is_internal = globals->get_current_view()->getInternal();
+    // draw before ac because ac internal rendering clear the depth buffer
+
+       globals->get_aircraft_model()->select( true );
+    if( is_internal )
+        shadows->endOfFrame();
+
     if ( draw_otw ) {
         FGTileMgr::set_tile_filter( false );
         sgSetModelFilter( false );
         globals->get_aircraft_model()->select( true );
         globals->get_model_mgr()->draw();
         globals->get_aircraft_model()->draw();
-        // If the view is internal, the previous line draw the 
-        //  cockpit with modified near/far clip planes and deselect
-        //  the aircraft in the global scenegraph
-        // Otherwise, it just enables the aircraft: The scenegraph
-        //  must be drawn again to see the plane.
-        ssgCullAndDraw( globals->get_scenery()->get_scene_graph() );
+
         FGTileMgr::set_tile_filter( true );
         sgSetModelFilter( true );
         globals->get_aircraft_model()->select( true );
     }
+       // in 'external' view the ac can be culled, so shadows have not been draw in the
+       // posttrav callback, this would be a rare case if the getInternal was acting
+       // as expected (ie in internal view, getExternal returns false)
+       if( !is_internal )
+               shadows->endOfFrame();
 
     // display HUD && Panel
     glDisable( GL_FOG );
@@ -826,10 +803,6 @@ FGRenderer::resize( int width, int height ) {
       //      << ", " << viewmgr->get_current_view()->get_v_fov() << ")"
       //      << endl;
 
-#ifdef FG_USE_CLOUDS_3D
-      sgClouds3d->Resize( viewmgr->get_current_view()->get_h_fov(),
-                          viewmgr->get_current_view()->get_v_fov() );
-#endif
     }
 
     fgHUDReshape();