VR-Forces 4.3.1 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 
12 #include <vrvOsg/vrvOsg.h>
13 
15 
16 #include <vrvCore/DtRenderer.h>
17 #include <vrvCore/DtDe.h>
18 
19 #include <osg/ref_ptr>
20 #include <osgShadow/ShadowedScene>
21 #include <osgUtil/RenderBin>
22 #include <osgViewer/Viewer>
23 #include <vector>
24 #include <string>
25 
26 #include <boost/unordered_map.hpp>
27 #include <boost/signals.hpp>
28 
29 namespace osg
30 {
31  class Group;
32  class Node;
33  class Camera;
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 
64  {
65  public:
66 
70  {
77  ChannelSpecific
78  };
79 
84  class SceneRoot
85  {
86  public:
87  SceneRoot() {}
89  : myDomain(domain)
90  {}
91  SceneRoot(int modelSet)
92  : myDomain(ModelSetSpecific)
93  {
94  myParameter.modelSetId = modelSet;
95  }
96  SceneRoot(int modelSet, int visualizerType)
97  : myDomain(VisualizerTypeSpecific)
98  {
99  myParameter.modelSetId = modelSet;
100  myParameter.visualizerType = visualizerType;
101  }
102 
103  SceneRoot(int modelSet, DtChannel* channel)
104  : myDomain(ChannelSpecific)
105  {
106  myParameter.modelSetId = modelSet;
107  myParameter.channel = channel;
108  }
109 
110  bool operator==(SceneRoot rhs) const
111  {
112  if ( myDomain == ModelSetSpecific )
113  {
114  return myDomain == rhs.myDomain &&
115  myParameter.modelSetId == rhs.myParameter.modelSetId;
116  }
117  if ( myDomain == VisualizerTypeSpecific )
118  {
119  return myDomain == rhs.myDomain &&
120  myParameter.modelSetId == rhs.myParameter.modelSetId &&
121  myParameter.visualizerType == rhs.myParameter.visualizerType;
122  }
123  if ( myDomain == ChannelSpecific )
124  {
125  return myDomain == rhs.myDomain &&
126  myParameter.modelSetId == rhs.myParameter.modelSetId &&
127  myParameter.channel == rhs.myParameter.channel;
128  }
129  return myDomain == rhs.myDomain;
130  }
131 
134  struct
135  {
142  } myParameter;
143  };
144 
146  typedef std::vector<SceneRoot> RootList;
147 
148  public:
149 
150  friend class DtSceneGraph;
151  friend class DtOsgRendererCreator;
152  friend class DtSceneGraphTreeLogic;
153 
154  //Render bin definitions.
155  const static int SKY_RENDERBIN = -10;
156  const static int DEFAULT_RENDERBIN = 0;
157  const static int OCEAN_RENDERBIN = 7;
158  const static int LIGHTPOINT_RENDERBIN = 8;
159  const static int CLOUD_RENDERBIN = 9;
160  const static int DEFAULT_TRANSPARENT_RENDERBIN = 10;
161  const static int COCKPIT_RENDERBIN = 25;
162 
163  //Render bin names
164  static const std::string SkyBin;
165  static const std::string LightPointBin;
166  static const std::string OceanBin;
167  static const std::string CloudBin;
168  static const std::string CockpitBin;
169 
174  static DtOsgRenderer* findInstance(DtDe& de);
175 
177  virtual ~DtOsgRenderer();
178 
180  virtual void update();
181 
183  virtual void render();
184 
186  virtual bool viewExists() const;
187 
189  virtual void resetSceneGraph();
190 
193  virtual void removeChannelRoot(DtChannel* channel);
194 
196  virtual void addNodeToRoot(osg::Node* node, SceneRoot sr, bool createOnAccess=true );
197 
199  virtual void removeNodeFromRoot(osg::Node* node, SceneRoot sr);
200 
202  virtual void traverseRoot(osg::NodeVisitor& nv, SceneRoot sr);
203 
205  virtual void setSceneRootNodeMask(SceneRoot sr,
206  osg::Node::NodeMask nodemask);
207 
209  virtual osg::Node::NodeMask sceneRootNodeMask(SceneRoot sr);
210 
212  virtual osg::BoundingSphere sceneRootBound(SceneRoot sr);
213 
215  virtual osg::BoundingSphere sceneRootListBound(const RootList& srList);
216 
218  virtual void addChannelToModelSetRoot( int modelSetId,
219  DtChannel* channel );
220 
222  virtual void removeChannelFromModelSetRoot( int modelSetId,
223  DtChannel* channel );
224 
226  virtual void addChannelToVisualizerRoot( int modelSetId,
227  int visualizerType, DtChannel* channel );
228 
230  virtual void removeChannelFromVisualizerRoot( int modelSetId,
231  int visualizerType, DtChannel* channel );
232 
234  virtual void setSceneDataToRenderRoot( osgViewer::View& view );
235 
237  virtual void addSceneToCamera(osg::Camera* camera);
238 
243  virtual void addSceneRootToNode(DtOsgRenderer::SceneRoot sr,
244  osg::Group* node, bool createOnAccess=true);
245 
250  virtual osg::Group* findSceneRootChildByName( SceneRoot parent,
251  const std::string& rootName );
252 
254  virtual bool matchesSceneRoot( SceneRoot sr, osg::Group* group );
255 
257  virtual void releaseResources()
258  {
259  releaseResources(0);
260  }
261 
263  virtual void releaseResources(osg::State* state);
264 
267  void setRootNode(osg::Group*,bool copyChildrenFromOldRoot);
268 
270  void resetRoot();
271 
274  void registerPagedLODs(osg::Node* node);
275 
278  void clearPagedLODs();
279 
281  virtual void setPerformanceStatsOverlayEnabled(bool show);
282 
284  virtual bool performanceStatsOverlayEnabled() const;
285 
287  virtual void setProfilerOverlayEnabled(bool show);
288 
290  virtual bool profilerOverlayEnabled() const;
291 
293  virtual void setWireframeRendering(bool enabled);
294 
296  virtual void setDdsFlip(bool flip);
297 
299  virtual bool wireframeRendering() const;
300 
302  virtual void setShadowState(bool enabled);
303 
305  virtual bool shadowsEnabled() const;
306 
308  void setTerrainScalingEnabled( bool enabled );
309 
311  void setTerrainScaleFactor( double scaleFactor );
312 
315  virtual bool makeContextCurrent();
316 
318  DtFontManager& fontManager();
319  const DtFontManager& fontManager() const;
320 
322  DtEffectManager& effectManager();
323  const DtEffectManager& effectManager() const;
324 
325  boost::signal< void ( int modelSet, int visualType ) > signal_visualizerRootAdded;
326  boost::signal< void ( DtChannel* ) > signal_channelRootAdded;
327 
329  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents);
330 
332  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents, const osg::Quat& orientation);
333 
335  void setChannelShadowState(DtOsgChannel* osgChannel, bool enable);
336 
338  bool getChannelShadowSettings(DtOsgChannel* osgChannel, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
339 
341  bool getChannelCloudShadowMap(DtOsgChannel* osgChannel, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix);
342 
344  bool getCameraCloudShadowMap(osg::Camera* camera, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix);
345 
346  public:
348  //@ {
349  static SceneRoot renderRoot();
350  static SceneRoot environmentRoot();
351  static SceneRoot terrainRoot();
352  static SceneRoot propRoot();
353  static SceneRoot modelSetRoot(int modelSet)
354  { return SceneRoot(modelSet); }
355  static SceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
356  { return SceneRoot(modelSet, visualizerType); }
357  static SceneRoot channelRoot(int modelSet, DtChannel* channel)
358  { return SceneRoot(modelSet, channel); }
359  //@ }
360 
361  protected:
362 
364  virtual void moveRootToShadowRoot( SceneRoot targetRoot, 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  // replace currentChild in all its parents with newChild
487  void swapChildren( osg::Node* currentChild, osg::Node* newChild );
488 
491  virtual void updateRenderMap( const DtInstanceManager::CullSet& cullSet );
492 
495  void postInitialize();
496 
497  protected:
499 
502 
504 
510  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
511 
512  // This the top of the render graph
513  osg::ref_ptr<osg::Group> myRenderRoot;
515  osg::ref_ptr<osg::Group> myDebugRoot;
516 
518  osg::ref_ptr<osg::Geode> myDebugBox;
519 
520  // This goes directly below the root, and sets the environment (such as sky)
521  osg::ref_ptr<osg::Group> myEnvironmentRoot;
522 
523  // attached under each modelset root, terrains are placed here
524  osg::ref_ptr<osg::Group> myTerrainRoot;
525 
526  // attached under each modelset root, props are placed here
527  osg::ref_ptr<osg::Group> myPropsRoot;
528 
529  // when terrain scaling is enabled, this is placed above the
530  // terrain root
531  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
532 
533  // when terrain scaling is enabled, this is placed above the
534  // props root
535  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
536 
537  osg::Matrix myScaleMatrix;
538 
539  // shadows and visual type roots are done one per model set
540  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
541  typedef boost::unordered_map<int, osg::ref_ptr<osgShadow::ShadowedScene> > ShadowedSceneMap;
542 
543  typedef int ModelSet;
544  typedef int VisualizerType;
545 
546  // There is one group for each model set, which is either an osg::Group
547  // or a DtChannelSpecificGroup
548  typedef boost::unordered_map<ModelSet, osg::ref_ptr<osg::Group> >
550 
551  typedef boost::unordered_map<VisualizerType, osg::ref_ptr<osg::Group> >
553 
557  typedef boost::unordered_map<ModelSet, VisualizerTypeRootMap>
559 
560 
561  // This is a map of the model set roots. CWhen a channel uses a model set
562  // (or more correctly, when a channel's observer uses a model set) the
563  // channel subscribes to the appropriate one of these
565 
566  // Under each model set root is a root for each visualizer type. This map
567  // provides another map, by model set, of the roots for each visual type
569 
570  // This is a map of channel roots by model set. Each channel root is a unique
577  typedef boost::unordered_map<DtChannel*, ModelSetRootMap >
579 
583 
584  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
585  osg::ref_ptr<osgUtil::RenderBin> myLightPointBin;
586  osg::ref_ptr<osgUtil::RenderBin> myOceanBin;
587  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
588  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
589 
592 
595 
601 
602  protected:
607 
608  };
609 
613  {
614  public:
615 
617  virtual DtRenderer* create(DtDe& de);
618  };
619 }

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)