]> git.mxchange.org Git - flightgear.git/blob - src/Viewer/renderer.hxx
Begin to implement configurable rendering pipeline
[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 namespace osg
14 {
15 class Camera;
16 class Group;
17 class GraphicsContext;
18 }
19
20 namespace osgGA
21 {
22 class GUIEventAdapter;
23 }
24
25 namespace osgShadow
26 {
27 class ShadowedScene;
28 }
29
30 namespace osgViewer
31 {
32 class Viewer;
33 }
34
35 namespace flightgear
36 {
37 class FGEventHandler;
38 struct CameraInfo;
39 class CameraGroup;
40 }
41
42 class SGSky;
43 class FGRenderingPipeline;
44
45 class FGRenderer {
46
47 public:
48
49     FGRenderer();
50     ~FGRenderer();
51
52     void splashinit();
53     void init();
54
55     void setupView();
56
57     void resize(int width, int height );
58
59     void update();
60   
61     /** Just pick into the scene and return the pick callbacks on the way ...
62      */
63     bool pick( std::vector<SGSceneryPick>& pickList,
64                const osgGA::GUIEventAdapter* ea );
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         /**
111          */
112         flightgear::CameraInfo* buildDefaultDeferredPipeline(flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
113                                    const osg::Matrix& view, const osg::Matrix& projection, osg::GraphicsContext* gc);
114
115     void updateShadowCamera(const flightgear::CameraInfo* info, const osg::Vec3d& position);
116     void updateShadowMapSize(int mapSize);
117     void enableShadows(bool enabled);
118     void updateCascadeFar(int index, float far_m);
119     void updateCascadeNumber(size_t num);
120
121     SGSky* getSky() const { return _sky; }
122
123         void setPlanes( double zNear, double zFar );
124     
125     /**
126      * inform the renderer when the global (2D) panel is changed
127      */
128     void panelChanged();
129 protected:
130     osg::ref_ptr<osgViewer::Viewer> viewer;
131     osg::ref_ptr<flightgear::FGEventHandler> eventHandler;
132     SGPropertyNode_ptr _scenery_loaded,_scenery_override;
133     SGPropertyNode_ptr _skyblend, _splash_alpha;
134     SGPropertyNode_ptr _point_sprites, _enhanced_lighting, _distance_attenuation;
135     SGPropertyNode_ptr _textures;
136     SGPropertyNode_ptr _cloud_status, _visibility_m; 
137     SGPropertyNode_ptr _xsize, _ysize;
138     SGPropertyNode_ptr _panel_hotspots, _sim_delta_sec, _horizon_effect, _altitude_ft;
139     SGPropertyNode_ptr _virtual_cockpit;
140     SGTimeStamp _splash_time;
141     SGSky* _sky;
142     bool _classicalRenderer;
143     std::string _renderer;
144     int _shadowMapSize;
145     size_t _numCascades;
146     float _cascadeFar[4];
147     bool _useColorForDepth;
148
149     osg::Camera* buildDeferredGeometryCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc );
150     osg::Camera* buildDeferredShadowCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc );
151     osg::Camera* buildDeferredLightingCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc );
152     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);
153     osg::Vec3 getSunDirection() const;
154     osg::ref_ptr<osg::Uniform> _ambientFactor;
155     osg::ref_ptr<osg::Uniform> _sunDiffuse;
156     osg::ref_ptr<osg::Uniform> _sunSpecular;
157     osg::ref_ptr<osg::Uniform> _sunDirection;
158     osg::ref_ptr<osg::Uniform> _planes;
159     osg::ref_ptr<osg::Uniform> _fogColor;
160     osg::ref_ptr<osg::Uniform> _fogDensity;
161     osg::ref_ptr<osg::Uniform> _shadowNumber;
162     osg::ref_ptr<osg::Uniform> _shadowDistances;
163     osg::ref_ptr<osg::Uniform> _depthInColor;
164
165     osg::ref_ptr<FGRenderingPipeline> _pipeline;
166 };
167
168 bool fgDumpSceneGraphToFile(const char* filename);
169 bool fgDumpTerrainBranchToFile(const char* filename);
170
171 namespace flightgear
172 {
173 bool printVisibleSceneInfo(FGRenderer* renderer);
174 }
175
176 #endif