]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/renderer.cxx
Make sure 'make dist' keeps working.
[flightgear.git] / src / Main / renderer.cxx
index 3d5cc51a56d2b4cf9037e37d92c583d3cdb26880..368dba6429f914682813d34b50558b620045f257 100644 (file)
@@ -18,9 +18,6 @@
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
-//
-// $Id$
-
 
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 
 #include <simgear/compiler.h>
 
-#ifdef HAVE_WINDOWS_H
-#  include <windows.h>
-#endif
-
 #include <osg/ref_ptr>
 #include <osg/AlphaFunc>
 #include <osg/BlendFunc>
@@ -66,8 +59,6 @@
 #include <simgear/screen/extensions.hxx>
 #include <simgear/scene/material/matlib.hxx>
 #include <simgear/scene/model/animation.hxx>
-#include <simgear/scene/model/model.hxx>
-#include <simgear/scene/model/modellib.hxx>
 #include <simgear/scene/model/placement.hxx>
 #include <simgear/scene/util/SGUpdateVisitor.hxx>
 #include <simgear/scene/util/RenderConstants.hxx>
@@ -83,7 +74,6 @@
 
 #include <simgear/environment/visual_enviro.hxx>
 
-#include <Scenery/tileentry.hxx>
 #include <Time/light.hxx>
 #include <Time/light.hxx>
 #include <Aircraft/aircraft.hxx>
@@ -165,11 +155,9 @@ public:
   {
     if (!fgOSIsMainContext(state.getGraphicsContext()))
       return;
-
-    state.pushStateSet(getStateSet());
-    state.apply();
     state.setActiveTextureUnit(0);
     state.setClientActiveTextureUnit(0);
+
     state.disableAllVertexArrays();
 
     glPushAttrib(GL_ALL_ATTRIB_BITS);
@@ -179,11 +167,6 @@ public:
 
     glPopClientAttrib();
     glPopAttrib();
-
-    state.popStateSet();
-    state.dirtyAllModes();
-    state.dirtyAllAttributes();
-    state.dirtyAllVertexArrays();
   }
 
   virtual osg::Object* cloneType() const { return new SGPuDrawable; }
@@ -215,12 +198,8 @@ public:
   { drawImplementation(*renderInfo.getState()); }
   void drawImplementation(osg::State& state) const
   {
-//     std::cout << state.getGraphicsContext() << std::endl;
     if (!fgOSIsMainContext(state.getGraphicsContext()))
       return;
-
-    state.pushStateSet(getStateSet());
-    state.apply();
     state.setActiveTextureUnit(0);
     state.setClientActiveTextureUnit(0);
     state.disableAllVertexArrays();
@@ -244,10 +223,6 @@ public:
     glPopClientAttrib();
     glPopAttrib();
 
-    state.popStateSet();
-    state.dirtyAllModes();
-    state.dirtyAllAttributes();
-    state.dirtyAllVertexArrays();
   }
 
   virtual osg::Object* cloneType() const { return new SGHUDAndPanelDrawable; }
@@ -387,9 +362,6 @@ public:
 // Sky structures
 SGSky *thesky;
 
-// Precipitations
-FGPrecipitationMgr *fgPrecipitationMgr;
-
 static osg::ref_ptr<osg::FrameStamp> mFrameStamp = new osg::FrameStamp;
 static osg::ref_ptr<SGUpdateVisitor> mUpdateVisitor= new SGUpdateVisitor;
 
@@ -434,12 +406,41 @@ FGRenderer::splashinit( void ) {
 #endif
 }
 
+namespace
+{
+// Create a slave camera that will be used to render a fixed GUI-like
+// element.
+osg::Camera*
+makeSlaveCamera(osg::Camera::RenderOrder renderOrder, int orderNum)
+{
+    using namespace osg;
+    Camera* camera = new osg::Camera;
+    GraphicsContext *gc = fgOSGetMainContext();
+    
+    camera->setRenderOrder(renderOrder, orderNum);
+    camera->setClearMask(0);
+    camera->setInheritanceMask(CullSettings::ALL_VARIABLES
+                               & ~(CullSettings::COMPUTE_NEAR_FAR_MODE
+                                   | CullSettings::CULLING_MODE));
+    camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
+    camera->setCullingMode(osg::CullSettings::NO_CULLING);
+    camera->setGraphicsContext(gc);
+    // Establish an initial viewport. This may be altered,
+    // particularly when drawing a 2d panel.
+    const GraphicsContext::Traits *traits = gc->getTraits();
+    camera->setViewport(new Viewport(0, 0, traits->width, traits->height));
+    camera->setProjectionResizePolicy(Camera::FIXED);
+    camera->setReferenceFrame(Transform::ABSOLUTE_RF);
+    camera->setAllowEventFocus(false);
+    globals->get_renderer()->getViewer()->addSlave(camera, false);
+    return camera;
+}
+
+}
+
 void
-FGRenderer::init( void ) {
-    // The viewer can call this before the graphics context is current
-    // in the main thread; indeed, in a multithreaded setup it might
-    // never be current in the main thread.
-    fgMakeCurrent();
+FGRenderer::init( void )
+{
     osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
     osg::initNotifyLevel();
 
@@ -505,11 +506,6 @@ FGRenderer::init( void ) {
     stateSet->setMode(GL_BLEND, osg::StateAttribute::ON);
     stateSet->setMode(GL_DEPTH_TEST, osg::StateAttribute::ON);
 
-
-       // Add Precipitation object
-       sceneGroup->addChild( fgPrecipitationMgr->getObject() );
-
-
     // need to update the light on every frame
     osg::LightSource* lightSource = new osg::LightSource;
     lightSource->setUpdateCallback(new FGLightSourceUpdateCallback);
@@ -545,15 +541,8 @@ FGRenderer::init( void ) {
     stateSet->setUpdateCallback(new FGFogEnableUpdateCallback);
 
     // plug in the GUI
-    osg::Camera* guiCamera = new osg::Camera;
-    guiCamera->setRenderOrder(osg::Camera::POST_RENDER, 100);
-    guiCamera->setClearMask(0);
-    GLbitfield inheritanceMask = osg::CullSettings::ALL_VARIABLES;
-    inheritanceMask &= ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE;
-    inheritanceMask &= ~osg::CullSettings::CULLING_MODE;
-    guiCamera->setInheritanceMask(inheritanceMask);
-    guiCamera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
-    guiCamera->setCullingMode(osg::CullSettings::NO_CULLING);
+    osg::Camera* guiCamera = makeSlaveCamera(osg::Camera::POST_RENDER, 100);
+    guiCamera->setName("GUI");
     osg::Geode* geode = new osg::Geode;
     geode->addDrawable(new SGPuDrawable);
     geode->addDrawable(new SGHUDAndPanelDrawable);
@@ -567,7 +556,6 @@ FGRenderer::init( void ) {
 
     mRealRoot->addChild(viewPartition.get());
     mRealRoot->addChild(FGCreateRedoutNode());
-    mRealRoot->addChild(guiCamera);
 }
 
 
@@ -788,20 +776,6 @@ FGRenderer::update( bool refresh_camera_settings ) {
 //         fgGetDouble("/velocities/airspeed-kt", 0.0)
 //                        * cos( fgGetDouble("/orientation/pitch-deg", 0.0)
 //                                * SGD_DEGREES_TO_RADIANS);
-       // TODO:find the real view speed, not the AC one
-//     sgEnviro.drawPrecipitation(
-//         fgGetDouble("/environment/metar/rain-norm", 0.0),
-//         fgGetDouble("/environment/metar/snow-norm", 0.0),
-//         fgGetDouble("/environment/metar/hail-norm", 0.0),
-//         current__view->getPitch_deg() + current__view->getPitchOffset_deg(),
-//         current__view->getRoll_deg() + current__view->getRollOffset_deg(),
-//         - current__view->getHeadingOffset_deg(),
-//                current_view_origin_airspeed_horiz_kt
-//                );
-
-       // Update precipitation informations...
-       fgPrecipitationMgr->update();
-
 
     // OSGFIXME
 //     if( is_internal )
@@ -855,8 +829,6 @@ FGRenderer::resize( int width, int height ) {
     if (height != lastheight)
         fgSetInt("/sim/startup/ysize", lastheight = height);
 
-    guiInitMouse(width, height);
-
     // for all views
     FGViewMgr *viewmgr = globals->get_viewmgr();
     if (viewmgr) {