| 1 | #ifndef __FG_RENDERER_HXX |
| 2 | #define __FG_RENDERER_HXX 1 |
| 3 | |
| 4 | #include <simgear/scene/util/SGPickCallback.hxx> |
| 5 | #include <simgear/props/props.hxx> |
| 6 | #include <simgear/timing/timestamp.hxx> |
| 7 | |
| 8 | #include <osg/ref_ptr> |
| 9 | #include <osg/Matrix> |
| 10 | #include <osg/Vec2> |
| 11 | #include <osg/Vec3> |
| 12 | |
| 13 | #include <osgViewer/CompositeViewer> |
| 14 | |
| 15 | |
| 16 | namespace osg |
| 17 | { |
| 18 | class Camera; |
| 19 | class Group; |
| 20 | class GraphicsContext; |
| 21 | class FrameStamp; |
| 22 | } |
| 23 | |
| 24 | namespace osgGA |
| 25 | { |
| 26 | class GUIEventAdapter; |
| 27 | } |
| 28 | |
| 29 | namespace osgViewer |
| 30 | { |
| 31 | class Viewer; |
| 32 | } |
| 33 | |
| 34 | namespace flightgear |
| 35 | { |
| 36 | class FGEventHandler; |
| 37 | class CameraGroup; |
| 38 | class PUICamera; |
| 39 | } |
| 40 | |
| 41 | class SGSky; |
| 42 | class SGUpdateVisitor; |
| 43 | class SplashScreen; |
| 44 | class QQuickDrawable; |
| 45 | |
| 46 | typedef std::vector<SGSceneryPick> PickList; |
| 47 | |
| 48 | class FGRenderer { |
| 49 | |
| 50 | public: |
| 51 | |
| 52 | FGRenderer(); |
| 53 | FGRenderer(osg::ref_ptr<osgViewer::CompositeViewer> composite_viewer); |
| 54 | ~FGRenderer(); |
| 55 | |
| 56 | void preinit(); |
| 57 | void init(); |
| 58 | |
| 59 | void setupView(); |
| 60 | |
| 61 | void resize(int width, int height); |
| 62 | void resize(int width, int height, int x, int y); |
| 63 | |
| 64 | void update(); |
| 65 | |
| 66 | /** Just pick into the scene and return the pick callbacks on the way ... |
| 67 | */ |
| 68 | PickList pick(const osg::Vec2& windowPos); |
| 69 | |
| 70 | /* Returns either composite_viewer or viewer. */ |
| 71 | osgViewer::ViewerBase* getViewerBase(); |
| 72 | |
| 73 | /** For handling reset. */ |
| 74 | osg::ref_ptr<osgViewer::CompositeViewer> getCompositeViewer(); |
| 75 | |
| 76 | /** Get and set the OSG Viewer object, if any. |
| 77 | */ |
| 78 | osgViewer::View* getView(); |
| 79 | const osgViewer::View* getView() const; |
| 80 | void setView(osgViewer::View* view); |
| 81 | |
| 82 | /** Calls osgViewer::CompositeViewer::getFrameStamp() if we are using |
| 83 | composite viewer, otherwise osgViewer::Viewer::getFrameStamp(). */ |
| 84 | osg::FrameStamp* getFrameStamp(); |
| 85 | |
| 86 | /** Get and set the manipulator object, if any. |
| 87 | */ |
| 88 | flightgear::FGEventHandler* getEventHandler() { return eventHandler.get(); } |
| 89 | const flightgear::FGEventHandler* getEventHandler() const { return eventHandler.get(); } |
| 90 | void setEventHandler(flightgear::FGEventHandler* manipulator); |
| 91 | |
| 92 | /** Add a top level camera. |
| 93 | */ |
| 94 | void addCamera(osg::Camera* camera, bool useSceneData); |
| 95 | |
| 96 | void removeCamera(osg::Camera* camera); |
| 97 | |
| 98 | SGSky* getSky() const { return _sky; } |
| 99 | |
| 100 | void setPlanes( double zNear, double zFar ); |
| 101 | |
| 102 | SplashScreen* getSplash(); |
| 103 | |
| 104 | protected: |
| 105 | int composite_viewer_enabled = -1; |
| 106 | osg::ref_ptr<osgViewer::Viewer> viewer; |
| 107 | osg::ref_ptr<osgViewer::CompositeViewer> composite_viewer; |
| 108 | osg::ref_ptr<flightgear::FGEventHandler> eventHandler; |
| 109 | |
| 110 | osg::ref_ptr<osg::FrameStamp> _frameStamp; |
| 111 | osg::ref_ptr<SGUpdateVisitor> _updateVisitor; |
| 112 | osg::ref_ptr<osg::Group> _viewerSceneRoot; |
| 113 | osg::ref_ptr<osg::Group> _root; |
| 114 | |
| 115 | SGPropertyNode_ptr _scenery_loaded, _position_finalized; |
| 116 | |
| 117 | SGPropertyNode_ptr _splash_alpha; |
| 118 | SGPropertyNode_ptr _splashHiddenSignal; |
| 119 | SGPropertyNode_ptr _enhanced_lighting; |
| 120 | SGPropertyNode_ptr _textures; |
| 121 | SGPropertyNode_ptr _cloud_status, _visibility_m; |
| 122 | SGPropertyNode_ptr _xsize, _ysize; |
| 123 | SGPropertyNode_ptr _xpos, _ypos; |
| 124 | SGPropertyNode_ptr _panel_hotspots, _sim_delta_sec, _horizon_effect, _altitude_ft; |
| 125 | SGPropertyNode_ptr _virtual_cockpit; |
| 126 | SGTimeStamp _splash_time; |
| 127 | SGSky* _sky; |
| 128 | int MaximumTextureSize; |
| 129 | |
| 130 | typedef std::vector<SGPropertyChangeListener*> SGPropertyChangeListenerVec; |
| 131 | SGPropertyChangeListenerVec _listeners; |
| 132 | |
| 133 | void addChangeListener(SGPropertyChangeListener* l, const char* path); |
| 134 | |
| 135 | void updateSky(); |
| 136 | |
| 137 | void setupRoot(); |
| 138 | |
| 139 | osg::ref_ptr<SplashScreen> _splash; |
| 140 | QQuickDrawable* _quickDrawable = nullptr; |
| 141 | flightgear::PUICamera* _puiCamera = nullptr; |
| 142 | }; |
| 143 | |
| 144 | bool fgDumpSceneGraphToFile(const char* filename); |
| 145 | bool fgDumpTerrainBranchToFile(const char* filename); |
| 146 | |
| 147 | namespace flightgear |
| 148 | { |
| 149 | bool printVisibleSceneInfo(FGRenderer* renderer); |
| 150 | } |
| 151 | |
| 152 | #endif |