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) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
10 #pragma once
11 
13 
14 #include <vrvCore/DtRenderer.h>
15 
16 #include <osgUtil/RenderBin>
17 #include <osgViewer/Viewer>
18 #include <vector>
19 #include <string>
20 
21 namespace osg
22 {
23  class Group;
24  class Node;
25  class Camera;
26 }
27 
28 namespace osgShadow
29 {
30  class ShadowedScene;
31 }
32 
33 namespace osgEarth
34 {
35  class MapNode;
36 }
37 
38 namespace makVrv
39 {
40  class DtStatsSet;
41  class DtChannel;
42  class DtOsgChannel;
43  class DtEffectManager;
44  class DtFontManager;
45  class DtOsgWindowManager;
46  class DtOsgProfilerOverlay;
47  class DtOsgPerformanceStatsOverlay;
48  class DtFastMatrixTransform;
49  class DtSceneGraph;
50  //class DtOsgLightingComponent;
51  class DtOsgGlobalShaderComponent;
52  class DtShadowSettingsObject;
53 
61  {
62  public:
63 
67  {
74  ChannelSpecific
75  };
76 
81  class SceneRoot
82  {
83  public:
84  SceneRoot() {}
86  : myDomain(domain)
87  {}
88  SceneRoot(int modelSet)
89  : myDomain(ModelSetSpecific)
90  {
91  myParameter.modelSetId = modelSet;
92  }
93  SceneRoot(int modelSet, int visualizerType)
94  : myDomain(VisualizerTypeSpecific)
95  {
96  myParameter.modelSetId = modelSet;
97  myParameter.visualizerType = visualizerType;
98  }
99 
100  SceneRoot(int modelSet, DtChannel* channel)
101  : myDomain(ChannelSpecific)
102  {
103  myParameter.modelSetId = modelSet;
104  myParameter.channel = channel;
105  }
106 
107  bool operator==(const SceneRoot& rhs) const
108  {
109  if ( myDomain == ModelSetSpecific )
110  {
111  return myDomain == rhs.myDomain &&
112  myParameter.modelSetId == rhs.myParameter.modelSetId;
113  }
114  if ( myDomain == VisualizerTypeSpecific )
115  {
116  return myDomain == rhs.myDomain &&
117  myParameter.modelSetId == rhs.myParameter.modelSetId &&
118  myParameter.visualizerType == rhs.myParameter.visualizerType;
119  }
120  if ( myDomain == ChannelSpecific )
121  {
122  return myDomain == rhs.myDomain &&
123  myParameter.modelSetId == rhs.myParameter.modelSetId &&
124  myParameter.channel == rhs.myParameter.channel;
125  }
126  return myDomain == rhs.myDomain;
127  }
128 
131  struct
132  {
139  } myParameter;
140  };
141 
143  typedef std::vector<SceneRoot> RootList;
144 
145  public:
146 
147  friend class DtSceneGraph;
148  friend class DtOsgRendererCreator;
149  friend class DtSceneGraphTreeLogic;
150 
151  //Render bin definitions.
152  const static int SKY_RENDERBIN = -10;
153  const static int DEFAULT_RENDERBIN = 0;
154  const static int DEPTH_ONLY_RENDERBIN = 6;
155  const static int OCEAN_RENDERBIN = 7;
156  const static int LIGHTPOINT_RENDERBIN = 8;
157  const static int CLOUD_RENDERBIN = 9;
158  const static int DEFAULT_TRANSPARENT_RENDERBIN = 10;
159  const static int COCKPIT_RENDERBIN = 25;
160 
161  //Render bin names
162  static const std::string SkyBin;
163  static const std::string DepthOnlyBin;
164  static const std::string OceanBin;
165  static const std::string LightPointBin;
166  static const std::string CloudBin;
167  static const std::string CockpitBin;
168 
173  static DtOsgRenderer* findInstance(DtDe& de);
174 
176  virtual ~DtOsgRenderer();
177 
179  virtual void update();
180 
182  virtual void render();
183 
185  virtual bool viewExists() const;
186 
188  virtual void resetSceneGraph();
189 
192  virtual void removeChannelRoot(DtChannel* channel);
193 
195  virtual void addNodeToRoot(osg::Node* node, const SceneRoot& sr, bool createOnAccess=true );
196 
198  virtual void removeNodeFromRoot(osg::Node* node, const SceneRoot& sr);
199 
201  virtual void traverseRoot(osg::NodeVisitor& nv, const SceneRoot& sr);
202 
204  virtual void setSceneRootNodeMask(const SceneRoot& sr,
205  osg::Node::NodeMask nodemask);
206 
208  virtual osg::Node::NodeMask sceneRootNodeMask(const SceneRoot& sr);
209 
211  virtual osg::BoundingSphere sceneRootBound(const SceneRoot& sr);
212 
214  virtual osg::BoundingSphere sceneRootListBound(const RootList& srList);
215 
217  virtual void addChannelToModelSetRoot( int modelSetId,
218  DtChannel* channel );
219 
221  virtual void removeChannelFromModelSetRoot( int modelSetId,
222  DtChannel* channel );
223 
225  virtual void addChannelToVisualizerRoot( int modelSetId,
226  int visualizerType, DtChannel* channel );
227 
229  virtual void removeChannelFromVisualizerRoot( int modelSetId,
230  int visualizerType, DtChannel* channel );
231 
233  virtual void setSceneDataToRenderRoot( osgViewer::View& view );
234 
236  virtual void addSceneToCamera(osg::Camera* camera);
237 
242  virtual void addSceneRootToNode(const SceneRoot& sr,
243  osg::Group* node, bool createOnAccess=true);
244 
249  virtual osg::Group* findSceneRootChildByName( const SceneRoot& parent,
250  const std::string& rootName );
251 
253  virtual bool matchesSceneRoot(const SceneRoot& sr, osg::Group* group );
254 
256  virtual void releaseResources()
257  {
258  releaseResources(0);
259  }
260 
262  virtual void releaseResources(osg::State* state);
263 
266  void setRootNode(osg::Group*,bool copyChildrenFromOldRoot);
267 
269  void resetRoot();
270 
273  void registerPagedLODs(osg::Node* node);
274 
277  void clearPagedLODs();
278 
280  virtual void setPerformanceStatsOverlayEnabled(bool show);
281 
283  virtual bool performanceStatsOverlayEnabled() const;
284 
286  virtual void setProfilerOverlayEnabled(bool show);
287 
289  virtual bool profilerOverlayEnabled() const;
290 
292  virtual void setWireframeRendering(bool enabled);
293 
295  virtual void setDdsFlip(bool flip);
296 
298  virtual bool wireframeRendering() const;
299 
301  virtual void setShadowState(bool enabled);
302 
304  virtual bool shadowsEnabled() const;
305 
307  void setTerrainScalingEnabled( bool enabled );
308 
310  void setTerrainScaleFactor( double scaleFactor );
311 
314  virtual bool makeContextCurrent();
315 
317  DtFontManager& fontManager();
318  const DtFontManager& fontManager() const;
319 
321  DtEffectManager& effectManager();
322  const DtEffectManager& effectManager() const;
323 
324  boost::signal< void ( int modelSet, int visualType ) > signal_visualizerRootAdded;
325  boost::signal< void ( DtChannel* ) > signal_channelRootAdded;
326 
328  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents);
329 
331  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents, const osg::Quat& orientation);
332 
334  void setChannelShadowState(DtOsgChannel* osgChannel, bool enable);
335 
337  bool getChannelShadowSettings(DtOsgChannel* osgChannel, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
338 
340  bool getChannelCloudShadowMap(DtOsgChannel* osgChannel, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix);
341 
343  bool getCameraCloudShadowMap(osg::Camera* camera, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix);
344 
345  public:
347  //@ {
348  static SceneRoot renderRoot();
349  static SceneRoot environmentRoot();
350  static SceneRoot terrainRoot();
351  static SceneRoot propRoot();
352  static SceneRoot modelSetRoot(int modelSet)
353  { return SceneRoot(modelSet); }
354  static SceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
355  { return SceneRoot(modelSet, visualizerType); }
356  static SceneRoot channelRoot(int modelSet, DtChannel* channel)
357  { return SceneRoot(modelSet, channel); }
358  //@ }
359 
360  protected:
361 
363  virtual void moveRootToShadowRoot( const SceneRoot& targetRoot,
364  osg::Group* shadowRoot, osg::Group* modelSetRoot );
365 
370  virtual osgViewer::ViewerBase& viewer();
371 
374  DtOsgRenderer(DtDe& de);
375 
378  osg::Group* sgRenderRoot();
379 
382  osg::Group* sgEnvironmentRoot();
383 
385  osg::Group* sgPropsRoot();
386 
388  osg::Group* sgTerrainRoot();
389 
391  osg::Group* sgScaledTerrainRoot();
392 
394  osg::Group* sgScaledPropsRoot();
395 
401  osg::Group* sgModelSetRoot( int modelSet );
402 
408  osg::Group* sgVisualizerRoot( int modelSet, int visualizerType,
409  bool createOnAccess=true );
410 
416  osg::Group* sgChannelRoot( int modelSet,
417  DtChannel* channel, bool createOnAccess=true );
418 
420  void slot_onViewCreated();
421 
424  void slot_onViewToBeDestroyed();
425 
427  void slot_onWireframeModeChanged(bool mode);
428 
430  void slot_onDdsFlipChanged(bool flip);
431 
433  virtual void slot_onProfilerOverlayOnChanged(bool mode);
434 
436  virtual void slot_onPerformanceStatsOverlayOnChanged(bool mode);
437 
439  void slot_onShadowStateChanged(bool shadowMode);
440 
442  void slot_onTerrainScalingEnabledChanged( bool enabled );
443 
445  void slot_onTerrainScaleFactorChanged( double scaleFactor );
446 
448  void slot_onCoordinateSystemChanged(const std::string& coordinateSystemType);
449 
451  void advanceTime();
452 
453  void updateSceneGraph();
454 
457  void clearEmptyWindows();
458 
461  virtual void removeShadows();
462 
464  virtual void createShadowRoots();
465 
469  virtual bool exportTerrainAndProps(const std::string&);
470 
471  virtual osg::Group* createModelSetRoot( int modelSet );
472  virtual osg::Group* createVisualizerRoot( int modelSet,
473  int visualizer );
474 
476  virtual osg::Group* createChannelRoot( int modelSet, DtChannel* );
477 
478  virtual osgShadow::ShadowedScene*
479  createModelSetSpecificShadowRootAndScene( int modelSet );
480  virtual osg::Group* modelSetSpecificShadowRoot( int modelSet );
481  virtual osgShadow::ShadowedScene*
482  modelSetSpecificShadowScene( int modelSet );
483 
484  virtual void updateTerrainScaling();
485 
486  virtual void updateAerodrome();
487 
488  // replace currentChild in all its parents with newChild
489  void swapChildren( osg::Node* currentChild, osg::Node* newChild );
490 
493  virtual void updateRenderMap( const DtInstanceManager::CullSet& cullSet );
494 
497  void postInitialize();
498 
499  protected:
501 
504 
506 
512  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
513 
514  // This the top of the render graph
515  osg::ref_ptr<osg::Group> myRenderRoot;
517  osg::ref_ptr<osg::Group> myDebugRoot;
518 
520  osg::ref_ptr<osg::Geode> myDebugBox;
521 
522  // This goes directly below the root, and sets the environment (such as sky)
523  osg::ref_ptr<osg::Group> myEnvironmentRoot;
524 
525  // attached under each modelset root, terrains are placed here
526  osg::ref_ptr<osg::Group> myTerrainRoot;
527 
528  // attached under each modelset root, props are placed here
529  osg::ref_ptr<osg::Group> myPropsRoot;
530 
531  // when terrain scaling is enabled, this is placed above the
532  // terrain root
533  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
534 
535  // when terrain scaling is enabled, this is placed above the
536  // props root
537  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
538 
539  osg::Matrix myScaleMatrix;
540 
541  // shadows and visual type roots are done one per model set
542  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
543  typedef boost::unordered_map<int, osg::ref_ptr<osgShadow::ShadowedScene> > ShadowedSceneMap;
544 
545  typedef int ModelSet;
546  typedef int VisualizerType;
547 
548  // There is one group for each model set, which is either an osg::Group
549  // or a DtChannelSpecificGroup
550  typedef boost::unordered_map<ModelSet, osg::ref_ptr<osg::Group> >
552 
553  typedef boost::unordered_map<VisualizerType, osg::ref_ptr<osg::Group> >
555 
559  typedef boost::unordered_map<ModelSet, VisualizerTypeRootMap>
561 
562 
563  // This is a map of the model set roots. CWhen a channel uses a model set
564  // (or more correctly, when a channel's observer uses a model set) the
565  // channel subscribes to the appropriate one of these
567 
568  // Under each model set root is a root for each visualizer type. This map
569  // provides another map, by model set, of the roots for each visual type
571 
572  // This is a map of channel roots by model set. Each channel root is a unique
579  typedef boost::unordered_map<DtChannel*, ModelSetRootMap >
581 
585 
586  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
587  osg::ref_ptr<osgUtil::RenderBin> myDepthOnlyBin;
588  osg::ref_ptr<osgUtil::RenderBin> myOceanBin;
589  osg::ref_ptr<osgUtil::RenderBin> myLightPointBin;
590  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
591  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
592 
595 
598 
604 
605  protected:
610 
611  };
612 
616  {
617  public:
618 
620  virtual DtRenderer* create(DtDe& de);
621  };
622 }

Document ID: Generated on Tue Mar 8 22:13:38 EST 2016 from SVN revision 162938
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)