]> git.mxchange.org Git - flightgear.git/blob - src/Viewer/renderer.hxx
Reset: listener cleanup
[flightgear.git] / src / Viewer / renderer.hxx
1
2 #ifndef __FG_RENDERER_HXX
3 #define __FG_RENDERER_HXX 1
4
5 #include <simgear/scene/util/SGPickCallback.hxx>
6 #include <simgear/props/props.hxx>
7 #include <simgear/timing/timestamp.hxx>
8
9 #include <osg/ref_ptr>
10 #include <osg/Matrix>
11 #include <osg/Vec3>
12
13 #include "renderingpipeline.hxx"
14
15 namespace osg
16 {
17 class Camera;
18 class Group;
19 class GraphicsContext;
20 }
21
22 namespace osgGA
23 {
24 class GUIEventAdapter;
25 }
26
27 namespace osgShadow
28 {
29 class ShadowedScene;
30 }
31
32 namespace osgViewer
33 {
34 class Viewer;
35 }
36
37 namespace flightgear
38 {
39 class FGEventHandler;
40 struct CameraInfo;
41 class CameraGroup;
42 }
43
44 class SGSky;
45
46 class FGRenderer {
47
48 public:
49
50     FGRenderer();
51     ~FGRenderer();
52
53     void splashinit();
54     void init();
55
56     void setupView();
57
58     void resize(int width, int height );
59
60     void update();
61   
62     /** Just pick into the scene and return the pick callbacks on the way ...
63      */
64     bool pick( std::vector<SGSceneryPick>& pickList, const osg::Vec2& windowPos);
65
66     /** Get and set the OSG Viewer object, if any.
67      */
68     osgViewer::Viewer* getViewer() { return viewer.get(); }
69     const osgViewer::Viewer* getViewer() const { return viewer.get(); }
70     void setViewer(osgViewer::Viewer* viewer);
71     /** Get and set the manipulator object, if any.
72      */
73     flightgear::FGEventHandler* getEventHandler() { return eventHandler.get(); }
74     const flightgear::FGEventHandler* getEventHandler() const { return eventHandler.get(); }
75     void setEventHandler(flightgear::FGEventHandler* manipulator);
76
77     /** Add a top level camera.
78      */
79     void addCamera(osg::Camera* camera, bool useSceneData);
80
81     void removeCamera(osg::Camera* camera);
82   
83     /** Add a camera to the group. The camera is added to the viewer
84      * as a slave. See osgViewer::Viewer::addSlave.
85      * @param flags properties of the camera; see CameraGroup::Flags
86      * @param projection slave projection matrix
87      * @param view slave view matrix
88      * @param useMasterSceneData whether the camera displays the
89      * viewer's scene data.
90      * @return a CameraInfo object for the camera.
91      */
92         flightgear::CameraInfo* buildRenderingPipeline(flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
93                                    const osg::Matrix& view,
94                                    const osg::Matrix& projection,
95                                                                    osg::GraphicsContext* gc,
96                                    bool useMasterSceneData);
97
98         /**
99          */
100         flightgear::CameraInfo* buildClassicalPipeline(flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
101                                    const osg::Matrix& view,
102                                    const osg::Matrix& projection,
103                                    bool useMasterSceneData);
104
105         /**
106          */
107         flightgear::CameraInfo* buildDeferredPipeline(flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
108                                    const osg::Matrix& view, const osg::Matrix& projection, osg::GraphicsContext* gc);
109
110     void updateShadowCamera(const flightgear::CameraInfo* info, const osg::Vec3d& position);
111     void updateShadowMapSize(int mapSize);
112     void enableShadows(bool enabled);
113     void updateCascadeFar(int index, float far_m);
114     void updateCascadeNumber(size_t num);
115
116     SGSky* getSky() const { return _sky; }
117
118         void setPlanes( double zNear, double zFar );
119
120 protected:
121     osg::ref_ptr<osgViewer::Viewer> viewer;
122     osg::ref_ptr<flightgear::FGEventHandler> eventHandler;
123     SGPropertyNode_ptr _scenery_loaded, _position_finalized;
124     
125     SGPropertyNode_ptr _skyblend, _splash_alpha;
126     SGPropertyNode_ptr _point_sprites, _enhanced_lighting, _distance_attenuation;
127     SGPropertyNode_ptr _textures;
128     SGPropertyNode_ptr _cloud_status, _visibility_m; 
129     SGPropertyNode_ptr _xsize, _ysize;
130     SGPropertyNode_ptr _panel_hotspots, _sim_delta_sec, _horizon_effect, _altitude_ft;
131     SGPropertyNode_ptr _virtual_cockpit;
132     SGTimeStamp _splash_time;
133     SGSky* _sky;
134     bool _classicalRenderer;
135     std::string _renderer;
136     int _shadowMapSize;
137     size_t _numCascades;
138     float _cascadeFar[4];
139     bool _useColorForDepth;
140
141     typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec;
142     SGPropertyChangeListenerVec _listeners;
143     
144     flightgear::CameraInfo* buildCameraFromRenderingPipeline(FGRenderingPipeline* rpipe, flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
145                                         const osg::Matrix& view, const osg::Matrix& projection, osg::GraphicsContext* gc);
146
147     void buildBuffers(FGRenderingPipeline* rpipe, flightgear::CameraInfo* info);
148     void buildStage(flightgear::CameraInfo* info, FGRenderingPipeline::Stage* stage, flightgear::CameraGroup* cgroup, osg::Camera* mainCamera, const osg::Matrix& view, const osg::Matrix& projection, osg::GraphicsContext* gc);
149     osg::Node* buildPass(flightgear::CameraInfo* info, FGRenderingPipeline::Pass* pass);
150     osg::Node* buildLightingSkyCloudsPass(FGRenderingPipeline::Pass* pass);
151     osg::Node* buildLightingLightsPass(flightgear::CameraInfo* info, FGRenderingPipeline::Pass* pass);
152
153     osg::Camera* buildDeferredGeometryCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc, const std::string& name, const FGRenderingPipeline::AttachmentList& attachments );
154     osg::Camera* buildDeferredShadowCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc, const std::string& name, const FGRenderingPipeline::AttachmentList& attachments );
155     osg::Camera* buildDeferredLightingCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc, const FGRenderingPipeline::Stage* stage );
156     osg::Camera* buildDeferredFullscreenCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc, const FGRenderingPipeline::Stage* stage );
157     osg::Camera* buildDeferredFullscreenCamera( flightgear::CameraInfo* info, const FGRenderingPipeline::Pass* pass );
158     void buildDeferredDisplayCamera( osg::Camera* camera, flightgear::CameraInfo* info, const FGRenderingPipeline::Stage* stage, osg::GraphicsContext* gc );
159
160     void updateShadowCascade(const flightgear::CameraInfo* info, osg::Camera* camera, osg::Group* grp, int idx, double left, double right, double bottom, double top, double zNear, double f1, double f2);
161     osg::Vec3 getSunDirection() const;
162     osg::ref_ptr<osg::Uniform> _ambientFactor;
163     osg::ref_ptr<osg::Uniform> _sunDiffuse;
164     osg::ref_ptr<osg::Uniform> _sunSpecular;
165     osg::ref_ptr<osg::Uniform> _sunDirection;
166     osg::ref_ptr<osg::Uniform> _planes;
167     osg::ref_ptr<osg::Uniform> _fogColor;
168     osg::ref_ptr<osg::Uniform> _fogDensity;
169     osg::ref_ptr<osg::Uniform> _shadowNumber;
170     osg::ref_ptr<osg::Uniform> _shadowDistances;
171     osg::ref_ptr<osg::Uniform> _depthInColor;
172
173     osg::ref_ptr<FGRenderingPipeline> _pipeline;
174     
175     void addChangeListener(SGPropertyChangeListener* l, const char* path);
176 };
177
178 bool fgDumpSceneGraphToFile(const char* filename);
179 bool fgDumpTerrainBranchToFile(const char* filename);
180
181 namespace flightgear
182 {
183 bool printVisibleSceneInfo(FGRenderer* renderer);
184 }
185
186 #endif