VR-Forces 4.3 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 #include <vrvCore/DtRenderer.h>
14 #include <vrvCore/DtDe.h>
15 
16 #include <osg/ref_ptr>
17 #include <osgShadow/ShadowedScene>
18 #include <osgUtil/RenderBin>
19 #include <osgViewer/Viewer>
20 #include <vector>
21 #include <string>
22 
23 #include <boost/unordered_map.hpp>
24 #include <boost/signals.hpp>
25 
26 namespace osg
27 {
28  class Group;
29  class Node;
30  class Camera;
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==(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 OCEAN_RENDERBIN = 7;
155  const static int LIGHTPOINT_RENDERBIN = 8;
156  const static int CLOUD_RENDERBIN = 9;
157  const static int DEFAULT_TRANSPARENT_RENDERBIN = 10;
158  const static int COCKPIT_RENDERBIN = 25;
159 
160  //Render bin names
161  static const std::string SkyBin;
162  static const std::string LightPointBin;
163  static const std::string OceanBin;
164  static const std::string CloudBin;
165  static const std::string CockpitBin;
166 
171  static DtOsgRenderer* findInstance(DtDe& de);
172 
174  virtual ~DtOsgRenderer();
175 
177  virtual void update();
178 
180  virtual void render();
181 
183  virtual bool viewExists() const;
184 
186  virtual void resetSceneGraph();
187 
190  virtual void removeChannelRoot(DtChannel* channel);
191 
193  virtual void addNodeToRoot(osg::Node* node, SceneRoot sr, bool createOnAccess=true );
194 
196  virtual void removeNodeFromRoot(osg::Node* node, SceneRoot sr);
197 
199  virtual void traverseRoot(osg::NodeVisitor& nv, SceneRoot sr);
200 
202  virtual void setSceneRootNodeMask(SceneRoot sr,
203  osg::Node::NodeMask nodemask);
204 
206  virtual osg::Node::NodeMask sceneRootNodeMask(SceneRoot sr);
207 
209  virtual osg::BoundingSphere sceneRootBound(SceneRoot sr);
210 
212  virtual osg::BoundingSphere sceneRootListBound(const RootList& srList);
213 
215  virtual void addChannelToModelSetRoot( int modelSetId,
216  DtChannel* channel );
217 
219  virtual void removeChannelFromModelSetRoot( int modelSetId,
220  DtChannel* channel );
221 
223  virtual void addChannelToVisualizerRoot( int modelSetId,
224  int visualizerType, DtChannel* channel );
225 
227  virtual void removeChannelFromVisualizerRoot( int modelSetId,
228  int visualizerType, DtChannel* channel );
229 
231  virtual void setSceneDataToRenderRoot( osgViewer::View& view );
232 
234  virtual void addSceneToCamera(osg::Camera* camera);
235 
240  virtual void addSceneRootToNode(DtOsgRenderer::SceneRoot sr,
241  osg::Group* node, bool createOnAccess=true);
242 
247  virtual osg::Group* findSceneRootChildByName( SceneRoot parent,
248  const std::string& rootName );
249 
251  virtual void releaseResources()
252  {
253  releaseResources(0);
254  }
255 
257  virtual void releaseResources(osg::State* state);
258 
261  void setRootNode(osg::Group*,bool copyChildrenFromOldRoot);
262 
264  void resetRoot();
265 
268  void registerPagedLODs(osg::Node* node);
269 
272  void clearPagedLODs();
273 
275  virtual void setPerformanceStatsOverlayEnabled(bool show);
276 
278  virtual bool performanceStatsOverlayEnabled() const;
279 
281  virtual void setProfilerOverlayEnabled(bool show);
282 
284  virtual bool profilerOverlayEnabled() const;
285 
287  virtual void setWireframeRendering(bool enabled);
288 
290  virtual void setDdsFlip(bool flip);
291 
293  virtual bool wireframeRendering() const;
294 
296  virtual void setShadowState(bool enabled);
297 
299  virtual bool shadowsEnabled() const;
300 
302  void setTerrainScalingEnabled( bool enabled );
303 
305  void setTerrainScaleFactor( double scaleFactor );
306 
309  virtual bool makeContextCurrent();
310 
312  DtFontManager& fontManager();
313  const DtFontManager& fontManager() const;
314 
316  DtEffectManager& effectManager();
317  const DtEffectManager& effectManager() const;
318 
319  boost::signal< void ( int modelSet, int visualType ) > signal_visualizerRootAdded;
320  boost::signal< void ( DtChannel* ) > signal_channelRootAdded;
321 
323  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents);
324 
326  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents, const osg::Quat& orientation);
327 
329  void setChannelShadowState(DtOsgChannel* osgChannel, bool enable);
330 
332  bool getChannelShadowSettings(DtOsgChannel* osgChannel, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
333 
335  bool getChannelCloudShadowMap(DtOsgChannel* osgChannel, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix);
336 
338  bool getCameraCloudShadowMap(osg::Camera* camera, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix);
339 
340  public:
342  //@ {
343  static SceneRoot renderRoot();
344  static SceneRoot environmentRoot();
345  static SceneRoot terrainRoot();
346  static SceneRoot propRoot();
347  static SceneRoot modelSetRoot(int modelSet)
348  { return SceneRoot(modelSet); }
349  static SceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
350  { return SceneRoot(modelSet, visualizerType); }
351  static SceneRoot channelRoot(int modelSet, DtChannel* channel)
352  { return SceneRoot(modelSet, channel); }
353  //@ }
354 
355  protected:
356 
358  virtual void moveRootToShadowRoot( SceneRoot targetRoot, osg::Group* shadowRoot, osg::Group* modelSetRoot );
359 
364  virtual osgViewer::ViewerBase& viewer();
365 
368  DtOsgRenderer(DtDe& de);
369 
372  osg::Group* sgRenderRoot();
373 
376  osg::Group* sgEnvironmentRoot();
377 
379  osg::Group* sgPropsRoot();
380 
382  osg::Group* sgTerrainRoot();
383 
385  osg::Group* sgScaledTerrainRoot();
386 
388  osg::Group* sgScaledPropsRoot();
389 
395  osg::Group* sgModelSetRoot( int modelSet );
396 
402  osg::Group* sgVisualizerRoot( int modelSet, int visualizerType,
403  bool createOnAccess=true );
404 
410  osg::Group* sgChannelRoot( int modelSet,
411  DtChannel* channel, bool createOnAccess=true );
412 
414  void slot_onViewCreated();
415 
418  void slot_onViewToBeDestroyed();
419 
421  void slot_onWireframeModeChanged(bool mode);
422 
424  void slot_onDdsFlipChanged(bool flip);
425 
427  virtual void slot_onProfilerOverlayOnChanged(bool mode);
428 
430  virtual void slot_onPerformanceStatsOverlayOnChanged(bool mode);
431 
433  void slot_onShadowStateChanged(bool shadowMode);
434 
436  void slot_onTerrainScalingEnabledChanged( bool enabled );
437 
439  void slot_onTerrainScaleFactorChanged( double scaleFactor );
440 
442  void slot_onCoordinateSystemChanged(const std::string& coordinateSystemType);
443 
445  void advanceTime();
446 
447  void updateSceneGraph();
448 
451  void clearEmptyWindows();
452 
455  virtual void removeShadows();
456 
458  virtual void createShadowRoots();
459 
463  virtual bool exportTerrainAndProps(const std::string&);
464 
465  virtual osg::Group* createModelSetRoot( int modelSet );
466  virtual osg::Group* createVisualizerRoot( int modelSet,
467  int visualizer );
468 
470  virtual osg::Group* createChannelRoot( int modelSet, DtChannel* );
471 
472  virtual osgShadow::ShadowedScene*
473  createModelSetSpecificShadowRootAndScene( int modelSet );
474  virtual osg::Group* modelSetSpecificShadowRoot( int modelSet );
475  virtual osgShadow::ShadowedScene*
476  modelSetSpecificShadowScene( int modelSet );
477 
478  virtual void updateTerrainScaling();
479 
480  // replace currentChild in all its parents with newChild
481  void swapChildren( osg::Node* currentChild, osg::Node* newChild );
482  protected:
484 
487 
489 
495  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
496 
497  // This the top of the render graph
498  osg::ref_ptr<osg::Group> myRenderRoot;
500  osg::ref_ptr<osg::Group> myDebugRoot;
501 
503  osg::ref_ptr<osg::Geode> myDebugBox;
504 
505  // This goes directly below the root, and sets the environment (such as sky)
506  osg::ref_ptr<osg::Group> myEnvironmentRoot;
507 
508  // attached under each modelset root, terrains are placed here
509  osg::ref_ptr<osg::Group> myTerrainRoot;
510 
511  // attached under each modelset root, props are placed here
512  osg::ref_ptr<osg::Group> myPropsRoot;
513 
514  // when terrain scaling is enabled, this is placed above the
515  // terrain root
516  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
517 
518  // when terrain scaling is enabled, this is placed above the
519  // props root
520  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
521 
522  osg::Matrix myScaleMatrix;
523 
524  // shadows and visual type roots are done one per model set
525  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
526  typedef boost::unordered_map<int, osg::ref_ptr<osgShadow::ShadowedScene> > ShadowedSceneMap;
527 
528  typedef int ModelSet;
529  typedef int VisualizerType;
530 
531  // There is one group for each model set, which is either an osg::Group
532  // or a DtChannelSpecificGroup
533  typedef boost::unordered_map<ModelSet, osg::ref_ptr<osg::Group> >
535 
536  typedef boost::unordered_map<VisualizerType, osg::ref_ptr<osg::Group> >
538 
542  typedef boost::unordered_map<ModelSet, VisualizerTypeRootMap>
544 
545 
546  // This is a map of the model set roots. CWhen a channel uses a model set
547  // (or more correctly, when a channel's observer uses a model set) the
548  // channel subscribes to the appropriate one of these
550 
551  // Under each model set root is a root for each visualizer type. This map
552  // provides another map, by model set, of the roots for each visual type
554 
555  // This is a map of channel roots by model set. Each channel root is a unique
562  typedef boost::unordered_map<DtChannel*, ModelSetRootMap >
564 
568 
569  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
570  osg::ref_ptr<osgUtil::RenderBin> myLightPointBin;
571  osg::ref_ptr<osgUtil::RenderBin> myOceanBin;
572  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
573  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
574 
577 
580 
586 
587  protected:
592 
593  };
594 
598  {
599  public:
600 
602  virtual DtRenderer* create(DtDe& de);
603  };
604 }

Document ID: Generated on Wed Mar 11 21:20:57 EDT 2015 from SVN revision 150940
Copyright © 2005-2014 VT MÄK. All Rights Reserved (www.mak.com)