VR-Forces Development_Version Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtOsgRenderer.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2016 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
14 #include <vrvCore/DtRenderer.h>
15 
17 #include <vrvOsg/DtSceneRoot.h>
18 
19 #include <osgUtil/RenderBin>
20 #include <osgViewer/Viewer>
21 #include <vector>
22 #include <string>
23 
24 namespace osg
25 {
26  class Group;
27  class Node;
28  class Camera;
29 }
30 
31 namespace osgShadow
32 {
33  class ShadowedScene;
34 }
35 
36 namespace osgEarth
37 {
38  class MapNode;
39 }
40 
41 namespace makVrv
42 {
43  class DtStatsSet;
44  class DtChannel;
45  class DtOsgChannel;
46  class DtEffectManager;
47  class DtFontManager;
48  class DtOsgWindowManager;
49  class DtOsgProfilerOverlay;
50  class DtOsgPerformanceStatsOverlay;
51  class DtFastMatrixTransform;
52  class DtSceneGraph;
53  //class DtOsgLightingComponent;
54  class DtOsgGlobalShaderComponent;
55  class DtShadowSettingsObject;
56  class DtTaxiwaySignManager;
57  class DtRunwayMarkingManager;
58  class DtLightIndicatorManager;
59 
67  {
68  public:
69  friend class DtSceneGraph;
70  friend class DtOsgRendererCreator;
71  friend class DtSceneGraphTreeLogic;
72 
73  //Render bin definitions.
74  const static int SKY_RENDERBIN = -10;
75  const static int DEFAULT_RENDERBIN = 0;
76  const static int DEPTH_ONLY_RENDERBIN = 6;
77  const static int OCEAN_RENDERBIN = 7;
78  const static int LIGHTPOINT_RENDERBIN = 8;
79  const static int CLOUD_RENDERBIN = 9;
80  const static int DEFAULT_TRANSPARENT_RENDERBIN = 10;
81  const static int COCKPIT_RENDERBIN = 25;
82 
83  //Render bin names
84  static const std::string SkyBin;
85  static const std::string DepthOnlyBin;
86  static const std::string OceanBin;
87  static const std::string LightPointBin;
88  static const std::string CloudBin;
89  static const std::string CockpitBin;
90 
95  static DtOsgRenderer* findInstance(DtDe& de);
96 
98  virtual ~DtOsgRenderer();
99 
101  virtual void update();
102 
104  virtual void render();
105 
107  virtual bool viewExists() const;
108 
110  virtual void resetSceneGraph();
111 
114  virtual void removeChannelRoot(DtChannel* channel);
115 
117  virtual void addNodeToRoot(osg::Node* node, const DtSceneRoot& sr, bool createOnAccess=true );
118 
120  virtual void removeNodeFromRoot(osg::Node* node, const DtSceneRoot& sr);
121 
123  virtual void traverseRoot(osg::NodeVisitor& nv, const DtSceneRoot& sr);
124 
126  virtual void setSceneRootNodeMask(const DtSceneRoot& sr,
127  osg::Node::NodeMask nodemask);
128 
130  virtual osg::Node::NodeMask sceneRootNodeMask(const DtSceneRoot& sr);
131 
133  virtual osg::BoundingSphere sceneRootBound(const DtSceneRoot& sr);
134 
136  virtual osg::BoundingSphere sceneRootListBound(const DtSceneRootList& srList);
137 
139  virtual void addChannelToModelSetRoot( int modelSetId,
140  DtChannel* channel );
141 
143  virtual void removeChannelFromModelSetRoot( int modelSetId,
144  DtChannel* channel );
145 
147  virtual void addChannelToVisualizerRoot( int modelSetId,
148  int visualizerType, DtChannel* channel );
149 
151  virtual void removeChannelFromVisualizerRoot( int modelSetId,
152  int visualizerType, DtChannel* channel );
153 
155  virtual void setSceneDataToRenderRoot( osgViewer::View& view );
156 
158  virtual void addSceneToCamera(osg::Camera* camera);
159 
164  virtual void addSceneRootToNode(const DtSceneRoot& sr,
165  osg::Group* node, bool createOnAccess=true);
166 
171  virtual osg::Group* findSceneRootChildByName( const DtSceneRoot& parent,
172  const std::string& rootName );
173 
175  virtual bool matchesSceneRoot(const DtSceneRoot& sr, osg::Group* group );
176 
178  virtual void releaseResources()
179  {
180  releaseResources(0);
181  }
182 
184  virtual void releaseResources(osg::State* state);
185 
188  void setRootNode(osg::Group*,bool copyChildrenFromOldRoot);
189 
191  void resetRoot();
192 
195  void registerPagedLODs(osg::Node* node);
196 
199  void clearPagedLODs();
200 
202  virtual void setPerformanceStatsOverlayEnabled(bool show);
203 
205  virtual bool performanceStatsOverlayEnabled() const;
206 
208  virtual void setProfilerOverlayEnabled(bool show);
209 
211  virtual bool profilerOverlayEnabled() const;
212 
214  virtual void setWireframeRendering(bool enabled);
215 
217  virtual void setDdsFlip(bool flip);
218 
220  virtual bool wireframeRendering() const;
221 
223  virtual void setShadowState(bool enabled);
224 
226  virtual bool shadowsEnabled() const;
227 
229  void setTerrainScalingEnabled( bool enabled );
230 
232  void setTerrainScaleFactor( double scaleFactor );
233 
236  virtual bool makeContextCurrent();
237 
239  DtFontManager& fontManager();
240  const DtFontManager& fontManager() const;
241 
243  DtEffectManager& effectManager();
244  const DtEffectManager& effectManager() const;
245 
246  boost::signal< void ( int modelSet, int visualType ) > signal_visualizerRootAdded;
247  boost::signal< void ( DtChannel* ) > signal_channelRootAdded;
248 
250  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents);
251 
253  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents, const osg::Quat& orientation);
254 
256  void setChannelShadowState(DtOsgChannel* osgChannel, bool enable);
257 
259  bool getChannelShadowSettings(DtOsgChannel* osgChannel, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
260 
262  bool getChannelCloudShadowMap(DtOsgChannel* osgChannel, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix);
263 
265  bool getCameraCloudShadowMap(osg::Camera* camera, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix);
266 
268  osg::StateSet* sgRenderRootStateSet();
269 
270  public:
272  //@ {
273  static DtSceneRoot renderRoot();
274  static DtSceneRoot environmentRoot();
275  static DtSceneRoot terrainRoot();
276  static DtSceneRoot propRoot();
277  static DtSceneRoot modelSetRoot(int modelSet)
278  { return DtSceneRoot(modelSet); }
279  static DtSceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
280  { return DtSceneRoot(modelSet, visualizerType); }
281  static DtSceneRoot channelRoot(int modelSet, DtChannel* channel)
282  { return DtSceneRoot(modelSet, channel); }
283  //@ }
284 
285  protected:
286 
288  virtual void moveRootToShadowRoot( const DtSceneRoot& targetRoot,
289  osg::Group* shadowRoot, osg::Group* modelSetRoot );
290 
295  virtual osgViewer::ViewerBase& viewer();
296 
299  DtOsgRenderer(DtDe& de);
300 
303  osg::Group* sgRenderRoot();
304 
307  osg::Group* sgEnvironmentRoot();
308 
310  osg::Group* sgPropsRoot();
311 
313  osg::Group* sgTerrainRoot();
314 
316  osg::Group* sgScaledTerrainRoot();
317 
319  osg::Group* sgScaledPropsRoot();
320 
326  osg::Group* sgModelSetRoot( int modelSet );
327 
333  osg::Group* sgVisualizerRoot( int modelSet, int visualizerType,
334  bool createOnAccess=true );
335 
341  osg::Group* sgChannelRoot( int modelSet,
342  DtChannel* channel, bool createOnAccess=true );
343 
345  void slot_onViewCreated();
346 
349  void slot_onViewToBeDestroyed();
350 
352  void slot_onWireframeModeChanged(bool mode);
353 
355  void slot_onDdsFlipChanged(bool flip);
356 
358  virtual void slot_onProfilerOverlayOnChanged(bool mode);
359 
361  virtual void slot_onPerformanceStatsOverlayOnChanged(bool mode);
362 
364  void slot_onShadowStateChanged(bool shadowMode);
365 
367  void slot_onTerrainScalingEnabledChanged( bool enabled );
368 
370  void slot_onTerrainScaleFactorChanged( double scaleFactor );
371 
373  void slot_onCoordinateSystemChanged(const std::string& coordinateSystemType);
374 
376  void advanceTime();
377 
378  void updateSceneGraph();
379 
382  void clearEmptyWindows();
383 
386  virtual void removeShadows();
387 
389  virtual void createShadowRoots();
390 
394  virtual bool exportTerrainAndProps(const std::string&);
395 
396  virtual osg::Group* createModelSetRoot( int modelSet );
397  virtual osg::Group* createVisualizerRoot( int modelSet,
398  int visualizer );
399 
401  virtual osg::Group* createChannelRoot( int modelSet, DtChannel* );
402 
403  virtual osgShadow::ShadowedScene*
404  createModelSetSpecificShadowRootAndScene( int modelSet );
405  virtual osg::Group* modelSetSpecificShadowRoot( int modelSet );
406  virtual osgShadow::ShadowedScene*
407  modelSetSpecificShadowScene( int modelSet );
408 
409  virtual void updateTerrainScaling();
410 
411  virtual void initAerodromeManagers();
412  virtual void updateAerodrome();
413 
414  // replace currentChild in all its parents with newChild
415  void swapChildren( osg::Node* currentChild, osg::Node* newChild );
416 
419  virtual void updateRenderMap( const CullSet& cullSet );
420 
423  void postInitialize();
424 
425  protected:
427 
430 
432 
438  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
439 
440  // This the top of the render graph
441  osg::ref_ptr<osg::Group> myRenderRoot;
443  osg::ref_ptr<osg::Group> myDebugRoot;
444 
446  osg::ref_ptr<osg::Geode> myDebugBox;
447 
448  // This goes directly below the root, and sets the environment (such as sky)
449  osg::ref_ptr<osg::Group> myEnvironmentRoot;
450 
451  // attached under each modelset root, terrains are placed here
452  osg::ref_ptr<osg::Group> myTerrainRoot;
453 
454  // attached under each modelset root, props are placed here
455  osg::ref_ptr<osg::Group> myPropsRoot;
456 
457  // when terrain scaling is enabled, this is placed above the
458  // terrain root
459  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
460 
461  // when terrain scaling is enabled, this is placed above the
462  // props root
463  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
464 
465  osg::Matrix myScaleMatrix;
466 
467  // shadows and visual type roots are done one per model set
468  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
469  typedef boost::unordered_map<int, osg::ref_ptr<osgShadow::ShadowedScene> > ShadowedSceneMap;
470 
471  typedef int ModelSet;
472  typedef int VisualizerType;
473 
474  // There is one group for each model set, which is either an osg::Group
475  // or a DtChannelSpecificGroup
476  typedef boost::unordered_map<ModelSet, osg::ref_ptr<osg::Group> >
478 
479  typedef boost::unordered_map<VisualizerType, osg::ref_ptr<osg::Group> >
481 
485  typedef boost::unordered_map<ModelSet, VisualizerTypeRootMap>
487 
488 
489  // This is a map of the model set roots. CWhen a channel uses a model set
490  // (or more correctly, when a channel's observer uses a model set) the
491  // channel subscribes to the appropriate one of these
493 
494  // Under each model set root is a root for each visualizer type. This map
495  // provides another map, by model set, of the roots for each visual type
497 
498  // This is a map of channel roots by model set. Each channel root is a unique
505  typedef boost::unordered_map<DtChannel*, ModelSetRootMap >
507 
511 
512  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
513  osg::ref_ptr<osgUtil::RenderBin> myDepthOnlyBin;
514  osg::ref_ptr<osgUtil::RenderBin> myOceanBin;
515  osg::ref_ptr<osgUtil::RenderBin> myLightPointBin;
516  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
517  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
518 
521 
524 
528 
534 
535  protected:
540 
541  };
542 
546  {
547  public:
548 
550  virtual DtRenderer* create(DtDe& de);
551  };
552 }

Document ID: Generated on Mon Jul 4 01:00:18 EDT 2016 from SVN revision 166489
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)