VR-Vantage API Documentation
DtOsgRenderer.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2012 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 #include <vrvCore/DtRenderer.h>
14 #include <vrvCore/DtDe.h>
15 
16 #include <osg/ref_ptr>
17 #include <osgUtil/RenderBin>
18 #include <osgViewer/Viewer>
19 #include <vector>
20 
21 #include <boost/unordered_map.hpp>
22 #include <boost/signals.hpp>
23 
24 namespace osg
25 {
26  class Group;
27  class Node;
28 }
29 
30 namespace makOsgShadowFX
31 {
32  class DtShadowEffect;
33 }
34 
35 namespace makVrv
36 {
37  class DtStatsSet;
38  class DtChannel;
39  class DtEffectManager;
40  class DtFontManager;
41  class DtOsgWindowManager;
42  class DtOsgPerformanceStatsOverlay;
43  class DtFastMatrixTransform;
44  class DtSceneGraph;
45 
53  {
54  public:
55 
59  {
66  ChannelSpecific
67  };
68 
73  class SceneRoot
74  {
75  public:
76  SceneRoot() {}
78  : myDomain(domain)
79  {}
80  SceneRoot(int modelSet)
81  : myDomain(ModelSetSpecific)
82  {
83  myParameter.modelSetId = modelSet;
84  }
85  SceneRoot(int modelSet, int visualizerType)
86  : myDomain(VisualizerTypeSpecific)
87  {
88  myParameter.modelSetId = modelSet;
89  myParameter.visualizerType = visualizerType;
90  }
91 
92  SceneRoot(int modelSet, DtChannel* channel)
93  : myDomain(ChannelSpecific)
94  {
95  myParameter.modelSetId = modelSet;
96  myParameter.channel = channel;
97  }
98 
99  bool operator==(SceneRoot rhs) const
100  {
101  if ( myDomain == ModelSetSpecific )
102  {
103  return myDomain == rhs.myDomain &&
104  myParameter.modelSetId == rhs.myParameter.modelSetId;
105  }
106  if ( myDomain == VisualizerTypeSpecific )
107  {
108  return myDomain == rhs.myDomain &&
109  myParameter.modelSetId == rhs.myParameter.modelSetId &&
110  myParameter.visualizerType == rhs.myParameter.visualizerType;
111  }
112  if ( myDomain == ChannelSpecific )
113  {
114  return myDomain == rhs.myDomain &&
115  myParameter.modelSetId == rhs.myParameter.modelSetId &&
116  myParameter.channel == rhs.myParameter.channel;
117  }
118  return myDomain == rhs.myDomain;
119  }
120 
123  struct
124  {
131  } myParameter;
132  };
133 
135  typedef std::vector<SceneRoot> RootList;
136 
137  public:
138 
139  friend class DtSceneGraph;
140  friend class DtOsgRendererCreator;
141  friend class DtSceneGraphTreeLogic;
142 
143  //Render bin definitions.
144  const static int SKY_RENDERBIN = -10;
145  const static int CLOUDS_RENDERBIN = 9;
146  const static int COCKPIT_RENDERBIN = 25;
147 
152  static DtOsgRenderer* findInstance(DtDe& de);
153 
155  virtual ~DtOsgRenderer();
156 
158  virtual void update();
159 
161  virtual void render();
162 
164  virtual bool viewExists() const;
165 
167  virtual void resetSceneGraph();
168 
171  virtual void removeChannelRoot(DtChannel* channel);
172 
174  virtual void addNodeToRoot(osg::Node* node, SceneRoot sr, bool createOnAccess=true );
175 
177  virtual void removeNodeFromRoot(osg::Node* node, SceneRoot sr);
178 
180  virtual void traverseRoot(osg::NodeVisitor& nv, SceneRoot sr);
181 
183  virtual void setSceneRootNodeMask(SceneRoot sr,
184  osg::Node::NodeMask nodemask);
185 
187  virtual osg::Node::NodeMask sceneRootNodeMask(SceneRoot sr);
188 
190  virtual osg::BoundingSphere sceneRootBound(SceneRoot sr);
191 
193  virtual osg::BoundingSphere sceneRootListBound(const RootList& srList);
194 
196  virtual void addChannelToModelSetRoot( int modelSetId,
197  DtChannel* channel );
198 
200  virtual void removeChannelFromModelSetRoot( int modelSetId,
201  DtChannel* channel );
202 
204  virtual void addChannelToVisualizerRoot( int modelSetId,
205  int visualizerType, DtChannel* channel );
206 
208  virtual void removeChannelFromVisualizerRoot( int modelSetId,
209  int visualizerType, DtChannel* channel );
210 
212  virtual void setSceneDataToRenderRoot( osgViewer::View& view );
213 
215  virtual void addSceneToCamera(osg::Camera* camera);
216 
221  virtual osg::Group* findSceneRootChildByName( SceneRoot parent,
222  const std::string& rootName );
223 
225  virtual void releaseResources()
226  {
227  releaseResources(0);
228  }
229 
231  virtual void releaseResources(osg::State* state);
232 
235  void setRootNode(osg::Group*,bool copyChildrenFromOldRoot);
236 
238  void resetRoot();
239 
242  void registerPagedLODs(osg::Node* node);
243 
246  void clearPagedLODs();
247 
249  virtual void setPerformanceStatsOverlayEnabled(bool show);
250 
252  virtual bool performanceStatsOverlayEnabled() const;
253 
255  virtual void setWireframeRendering(bool enabled);
256 
258  virtual void setDdsFlip(bool flip);
259 
261  virtual bool wireframeRendering() const;
262 
264  virtual void setShadowState(bool enabled, int quality, bool entity,
265  bool prop, bool terrain);
266 
268  //@ {
269  virtual bool shadowsEnabled() const;
270  virtual int shadowQuality() const;
271  virtual bool entityShadowsEnabled() const;
272  virtual bool propShadowsEnabled() const;
273  virtual bool terrainShadowsEnabled() const;
274  //@ }
275 
277  void setTerrainScalingEnabled( bool enabled );
278 
280  void setTerrainScaleFactor( double scaleFactor );
281 
284  virtual bool makeContextCurrent();
285 
287  DtFontManager& fontManager();
288  const DtFontManager& fontManager() const;
289 
291  DtEffectManager& effectManager();
292  const DtEffectManager& effectManager() const;
293 
294  boost::signal< void ( int modelSet, int visualType ) > signal_visualizerRootAdded;
295  boost::signal< void ( DtChannel* ) > signal_channelRootAdded;
296 
297  public:
299  //@ {
300  static SceneRoot renderRoot();
301  static SceneRoot environmentRoot();;
302  static SceneRoot terrainRoot();
303  static SceneRoot propRoot();
304  static SceneRoot modelSetRoot(int modelSet)
305  { return SceneRoot(modelSet); }
306  static SceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
307  { return SceneRoot(modelSet, visualizerType); }
308  static SceneRoot channelRoot(int modelSet, DtChannel* channel)
309  { return SceneRoot(modelSet, channel); }
310  //@ }
311 
312  protected:
313 
315  virtual void moveRootToShadowRoot( SceneRoot targetRoot, osg::Group* shadowRoot, osg::Group* modelSetRoot );
316 
321  virtual osgViewer::ViewerBase& viewer();
322 
324  virtual void onActiveStatsOverlayChanged(DtStatsSet* activeStats);
325 
328  DtOsgRenderer(DtDe& de);
329 
332  osg::Group* sgRenderRoot();
333 
336  osg::Group* sgEnvironmentRoot();
337 
339  osg::Group* sgPropsRoot();
340 
342  osg::Group* sgTerrainRoot();
343 
345  osg::Group* sgScaledTerrainRoot();
346 
348  osg::Group* sgScaledPropsRoot();
349 
355  osg::Group* sgModelSetRoot( int modelSet );
356 
362  osg::Group* sgVisualizerRoot( int modelSet, int visualizerType,
363  bool createOnAccess=true );
364 
370  osg::Group* sgChannelRoot( int modelSet,
371  DtChannel* channel, bool createOnAccess=true );
372 
374  void slot_onViewCreated();
375 
378  void slot_onViewToBeDestroyed();
379 
381  void slot_onWireframeModeChanged(bool mode);
382 
384  void slot_onDdsFlipChanged(bool flip);
385 
387  virtual void slot_onPerformanceOverlayOnChanged(bool mode);
388 
390  void slot_onShadowStateChanged(bool shadowMode, int shadowQual,
391  bool entityMode, bool propMode, bool terrainMode);
392 
394  void slot_onTerrainScalingEnabledChanged( bool enabled );
395 
397  void slot_onTerrainScaleFactorChanged( double scaleFactor );
398 
400  void slot_onCoordinateSystemChanged(const std::string& coordinateSystemType);
401 
403  void advanceTime();
404 
405  void updateSceneGraph();
406 
409  void clearEmptyWindows();
410 
413  virtual void removeShadows();
414 
416  virtual void createShadowRoots();
417 
421  virtual bool exportTerrainAndProps(const std::string&);
422 
423  virtual osg::Group* createModelSetRoot( int modelSet );
424  virtual osg::Group* createVisualizerRoot( int modelSet,
425  int visualizer );
426 
428  virtual osg::Group* createChannelRoot( int modelSet, DtChannel* );
429 
431  createModelSetSpecificShadowRootAndEffect( int modelSet );
432  virtual osg::Group* modelSetSpecificShadowRoot( int modelSet );
434  modelSetSpecificShadowEffect( int modelSet );
435 
436  virtual void updateTerrainScaling();
437 
438  // replace currentChild in all its parents with newChild
439  void swapChildren( osg::Node* currentChild, osg::Node* newChild );
440  protected:
442 
445 
447 
453  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
454 
455  // This the top of the render graph
456  osg::ref_ptr<osg::Group> myRenderRoot;
457 
458  // This goes directly below the root, and sets the environment (such as sky)
459  osg::ref_ptr<osg::Group> myEnvironmentRoot;
460 
461  // attached under each modelset root, terrains are placed here
462  osg::ref_ptr<osg::Group> myTerrainRoot;
463 
464  // attached under each modelset root, props are placed here
465  osg::ref_ptr<osg::Group> myPropsRoot;
466 
467  // when terrain scaling is enabled, this is placed above the
468  // terrain root
469  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
470 
471  // when terrain scaling is enabled, this is placed above the
472  // props root
473  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
474 
475  osg::Matrix myScaleMatrix;
476 
477  // shadows and visual type roots are done one per model set
478  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
479  typedef boost::unordered_map<int,
480  osg::ref_ptr<makOsgShadowFX::DtShadowEffect> > ShadowEffectMap;
481 
482  typedef int ModelSet;
483  typedef int VisualizerType;
484 
485  // There is one group for each model set, which is either an osg::Group
486  // or a DtChannelSpecificGroup
487  typedef boost::unordered_map<ModelSet, osg::ref_ptr<osg::Group> >
489 
490  typedef boost::unordered_map<VisualizerType, osg::ref_ptr<osg::Group> >
492 
496  typedef boost::unordered_map<ModelSet, VisualizerTypeRootMap>
498 
499 
500  // This is a map of the model set roots. CWhen a channel uses a model set
501  // (or more correctly, when a channel's observer uses a model set) the
502  // channel subscribes to the appropriate one of these
504 
505  // Under each model set root is a root for each visualizer type. This map
506  // provides another map, by model set, of the roots for each visual type
508 
509  // This is a map of channel roots by model set. Each channel root is a unique
516  typedef boost::unordered_map<DtChannel*, ModelSetRootMap >
518 
520 
523 
524  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
525  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
526  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
527 
534 
536 
541 
542  protected:
547 
548  };
549 
553  {
554  public:
555 
557  virtual DtRenderer* create(DtDe& de);
558  };
559 }


Copyright © 2005-2013 VT MÄK Inc. All Rights Reserved (www.mak.com)