]> git.mxchange.org Git - flightgear.git/blob - src/Viewer/renderer.hxx
Use names to identify deferred buffers in camera group
[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
44 class FGRenderer {
45
46 public:
47
48     FGRenderer();
49     ~FGRenderer();
50
51     void splashinit();
52     void init();
53
54     void setupView();
55
56     void resize(int width, int height );
57
58     void update();
59   
60     /** Just pick into the scene and return the pick callbacks on the way ...
61      */
62     bool pick( std::vector<SGSceneryPick>& pickList,
63                const osgGA::GUIEventAdapter* ea );
64
65     /** Get and set the OSG Viewer object, if any.
66      */
67     osgViewer::Viewer* getViewer() { return viewer.get(); }
68     const osgViewer::Viewer* getViewer() const { return viewer.get(); }
69     void setViewer(osgViewer::Viewer* viewer);
70     /** Get and set the manipulator object, if any.
71      */
72     flightgear::FGEventHandler* getEventHandler() { return eventHandler.get(); }
73     const flightgear::FGEventHandler* getEventHandler() const { return eventHandler.get(); }
74     void setEventHandler(flightgear::FGEventHandler* manipulator);
75
76     /** Add a top level camera.
77      */
78     void addCamera(osg::Camera* camera, bool useSceneData);
79
80     void removeCamera(osg::Camera* camera);
81   
82     /** Add a camera to the group. The camera is added to the viewer
83      * as a slave. See osgViewer::Viewer::addSlave.
84      * @param flags properties of the camera; see CameraGroup::Flags
85      * @param projection slave projection matrix
86      * @param view slave view matrix
87      * @param useMasterSceneData whether the camera displays the
88      * viewer's scene data.
89      * @return a CameraInfo object for the camera.
90      */
91         flightgear::CameraInfo* buildRenderingPipeline(flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
92                                    const osg::Matrix& view,
93                                    const osg::Matrix& projection,
94                                                                    osg::GraphicsContext* gc,
95                                    bool useMasterSceneData);
96
97         /**
98          */
99         flightgear::CameraInfo* buildClassicalPipeline(flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
100                                    const osg::Matrix& view,
101                                    const osg::Matrix& projection,
102                                    bool useMasterSceneData);
103
104         /**
105          */
106         flightgear::CameraInfo* buildDeferredPipeline(flightgear::CameraGroup* cgroup, unsigned flags, osg::Camera* camera,
107                                    const osg::Matrix& view, const osg::Matrix& projection, osg::GraphicsContext* gc);
108
109     void updateShadowCamera(const flightgear::CameraInfo* info, const osg::Vec3d& position);
110     void updateShadowMapSize(int mapSize);
111     void enableShadows(bool enabled);
112     void updateCascadeFar(int index, float far_m);
113     void updateCascadeNumber(size_t num);
114
115     SGSky* getSky() const { return _sky; }
116
117         void setPlanes( double zNear, double zFar );
118     
119     /**
120      * inform the renderer when the global (2D) panel is changed
121      */
122     void panelChanged();
123 protected:
124     osg::ref_ptr<osgViewer::Viewer> viewer;
125     osg::ref_ptr<flightgear::FGEventHandler> eventHandler;
126     SGPropertyNode_ptr _scenery_loaded,_scenery_override;
127     SGPropertyNode_ptr _skyblend, _splash_alpha;
128     SGPropertyNode_ptr _point_sprites, _enhanced_lighting, _distance_attenuation;
129     SGPropertyNode_ptr _textures;
130     SGPropertyNode_ptr _cloud_status, _visibility_m; 
131     SGPropertyNode_ptr _xsize, _ysize;
132     SGPropertyNode_ptr _panel_hotspots, _sim_delta_sec, _horizon_effect, _altitude_ft;
133     SGPropertyNode_ptr _virtual_cockpit;
134     SGTimeStamp _splash_time;
135     SGSky* _sky;
136     bool _classicalRenderer;
137     int _shadowMapSize;
138     size_t _numCascades;
139     float _cascadeFar[4];
140     bool _useColorForDepth;
141
142     osg::Camera* buildDeferredGeometryCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc );
143     osg::Camera* buildDeferredShadowCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc );
144     osg::Camera* buildDeferredLightingCamera( flightgear::CameraInfo* info, osg::GraphicsContext* gc );
145     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);
146     osg::Vec3 getSunDirection() const;
147     osg::ref_ptr<osg::Uniform> _ambientFactor;
148     osg::ref_ptr<osg::Uniform> _sunDiffuse;
149     osg::ref_ptr<osg::Uniform> _sunSpecular;
150     osg::ref_ptr<osg::Uniform> _sunDirection;
151     osg::ref_ptr<osg::Uniform> _planes;
152     osg::ref_ptr<osg::Uniform> _fogColor;
153     osg::ref_ptr<osg::Uniform> _fogDensity;
154     osg::ref_ptr<osg::Uniform> _shadowNumber;
155     osg::ref_ptr<osg::Uniform> _shadowDistances;
156     osg::ref_ptr<osg::Uniform> _depthInColor;
157 };
158
159 bool fgDumpSceneGraphToFile(const char* filename);
160 bool fgDumpTerrainBranchToFile(const char* filename);
161
162 namespace flightgear
163 {
164 bool printVisibleSceneInfo(FGRenderer* renderer);
165 }
166
167 #endif