VR-Forces 4.5 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 
271  // structure to expedite culling. We need to clear any memory
272  // that this structure caches to decrement reference count of
273  // StateSets (and hence drawables, textures, etc) when scene
274  // changes completely (e.g. on post processor turned off/on)
275  // so that memory can be reclaimed
276  // This helper function accomplishes that
277  void clearStateGraphForAllChannels(void);
278  public:
280  //@ {
281  static DtSceneRoot renderRoot();
282  static DtSceneRoot environmentRoot();
283  static DtSceneRoot terrainRoot();
284  static DtSceneRoot propRoot();
285  static DtSceneRoot modelSetRoot(int modelSet)
286  { return DtSceneRoot(modelSet); }
287  static DtSceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
288  { return DtSceneRoot(modelSet, visualizerType); }
289  static DtSceneRoot channelRoot(int modelSet, DtChannel* channel)
290  { return DtSceneRoot(modelSet, channel); }
291  //@ }
292 
293  protected:
294 
296  virtual void moveRootToShadowRoot( const DtSceneRoot& targetRoot,
297  osg::Group* shadowRoot, osg::Group* modelSetRoot );
298 
303  virtual osgViewer::ViewerBase& viewer();
304 
307  DtOsgRenderer(DtDe& de);
308 
311  osg::Group* sgRenderRoot();
312 
315  osg::Group* sgEnvironmentRoot();
316 
318  osg::Group* sgPropsRoot();
319 
321  osg::Group* sgTerrainRoot();
322 
324  osg::Group* sgScaledTerrainRoot();
325 
327  osg::Group* sgScaledPropsRoot();
328 
334  osg::Group* sgModelSetRoot( int modelSet );
335 
341  osg::Group* sgVisualizerRoot( int modelSet, int visualizerType,
342  bool createOnAccess=true );
343 
349  osg::Group* sgChannelRoot( int modelSet,
350  DtChannel* channel, bool createOnAccess=true );
351 
353  void slot_onViewCreated();
354 
357  void slot_onViewToBeDestroyed();
358 
360  void slot_onWireframeModeChanged(bool mode);
361 
363  void slot_onDdsFlipChanged(bool flip);
364 
366  virtual void slot_onProfilerOverlayOnChanged(bool mode);
367 
369  virtual void slot_onPerformanceStatsOverlayOnChanged(bool mode);
370 
372  void slot_onShadowStateChanged(bool shadowMode);
373 
375  void slot_onTerrainScalingEnabledChanged( bool enabled );
376 
378  void slot_onTerrainScaleFactorChanged( double scaleFactor );
379 
381  void slot_onCoordinateSystemChanged(const std::string& coordinateSystemType);
382 
384  void advanceTime();
385 
386  void updateSceneGraph();
387 
390  void clearEmptyWindows();
391 
394  virtual void removeShadows();
395 
397  virtual void createShadowRoots();
398 
402  virtual bool exportTerrainAndProps(const std::string&);
403 
404  virtual osg::Group* createModelSetRoot( int modelSet );
405  virtual osg::Group* createVisualizerRoot( int modelSet,
406  int visualizer );
407 
409  virtual osg::Group* createChannelRoot( int modelSet, DtChannel* );
410 
411  virtual osgShadow::ShadowedScene*
412  createModelSetSpecificShadowRootAndScene( int modelSet );
413  virtual osg::Group* modelSetSpecificShadowRoot( int modelSet );
414  virtual osgShadow::ShadowedScene*
415  modelSetSpecificShadowScene( int modelSet );
416 
417  virtual void updateTerrainScaling();
418 
419  virtual void initAerodromeManagers();
420  virtual void updateAerodrome();
421 
422  // replace currentChild in all its parents with newChild
423  void swapChildren( osg::Node* currentChild, osg::Node* newChild );
424 
427  virtual void updateRenderMap( const CullSet& cullSet );
428 
431  void postInitialize();
432 
433  protected:
435 
438 
440 
446  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
447 
448  // This the top of the render graph
449  osg::ref_ptr<osg::Group> myRenderRoot;
451  osg::ref_ptr<osg::Group> myDebugRoot;
452 
454  osg::ref_ptr<osg::Geode> myDebugBox;
455 
456  // This goes directly below the root, and sets the environment (such as sky)
457  osg::ref_ptr<osg::Group> myEnvironmentRoot;
458 
459  // attached under each modelset root, terrains are placed here
460  osg::ref_ptr<osg::Group> myTerrainRoot;
461 
462  // attached under each modelset root, props are placed here
463  osg::ref_ptr<osg::Group> myPropsRoot;
464 
465  // when terrain scaling is enabled, this is placed above the
466  // terrain root
467  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
468 
469  // when terrain scaling is enabled, this is placed above the
470  // props root
471  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
472 
473  osg::Matrix myScaleMatrix;
474 
475  // shadows and visual type roots are done one per model set
476  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
477  typedef boost::unordered_map<int, osg::ref_ptr<osgShadow::ShadowedScene> > ShadowedSceneMap;
478 
479  typedef int ModelSet;
480  typedef int VisualizerType;
481 
482  // There is one group for each model set, which is either an osg::Group
483  // or a DtChannelSpecificGroup
484  typedef boost::unordered_map<ModelSet, osg::ref_ptr<osg::Group> >
486 
487  typedef boost::unordered_map<VisualizerType, osg::ref_ptr<osg::Group> >
489 
493  typedef boost::unordered_map<ModelSet, VisualizerTypeRootMap>
495 
496 
497  // This is a map of the model set roots. CWhen a channel uses a model set
498  // (or more correctly, when a channel's observer uses a model set) the
499  // channel subscribes to the appropriate one of these
501 
502  // Under each model set root is a root for each visualizer type. This map
503  // provides another map, by model set, of the roots for each visual type
505 
506  // This is a map of channel roots by model set. Each channel root is a unique
513  typedef boost::unordered_map<DtChannel*, ModelSetRootMap >
515 
519 
520  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
521  osg::ref_ptr<osgUtil::RenderBin> myDepthOnlyBin;
522  osg::ref_ptr<osgUtil::RenderBin> myOceanBin;
523  osg::ref_ptr<osgUtil::RenderBin> myLightPointBin;
524  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
525  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
526 
529 
532 
536 
542 
543  protected:
548 
549  };
550 
554  {
555  public:
556 
558  virtual DtRenderer* create(DtDe& de);
559  };
560 }

Document ID: Generated on Thu Mar 23 18:54:12 EDT 2017 from SVN revision 174804
Copyright © 2005-2017 VT MÄK. All Rights Reserved (www.mak.com)