VR-Forces 4.6 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgRenderer.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2017 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 <osg/OperationThread>
20 #include <osgUtil/RenderBin>
21 #include <osgViewer/Viewer>
22 #include <vector>
23 #include <string>
24 
25 namespace osg
26 {
27  class Group;
28  class Node;
29  class Camera;
30 }
31 
32 namespace osgShadow
33 {
34  class ShadowedScene;
35 }
36 
37 namespace osgEarth
38 {
39  class MapNode;
40 }
41 
42 namespace makVrv
43 {
44  class DtStatsSet;
45  class DtChannel;
46  class DtOsgChannel;
47  class DtEffectManager;
48  class DtFontManager;
49  class DtOsgWindowManager;
50  class DtOsgProfilerOverlay;
51  class DtOsgPerformanceStatsOverlay;
52  class DtFastMatrixTransform;
53  class DtSceneGraph;
54  //class DtOsgLightingComponent;
55  class DtOsgGlobalShaderComponent;
56  class DtShadowSettingsObject;
57  class DtTaxiwaySignManager;
58  class DtRunwayMarkingManager;
59  class DtLightIndicatorManager;
60 
61  class DT_DLL_VRVOSG DtMainThreadOperation : public osg::Operation
62  {
63  float mySimTime;
64  };
65 
73  {
74  public:
75  friend class DtSceneGraph;
76  friend class DtOsgRendererCreator;
77  friend class DtSceneGraphTreeLogic;
78 
79  //Render bin definitions.
80  const static int SKY_RENDERBIN = -10;
81  const static int DEFAULT_RENDERBIN = 0;
82  const static int DEPTH_ONLY_RENDERBIN = 6;
83  const static int OCEAN_RENDERBIN = 7;
84  const static int LIGHTPOINT_RENDERBIN = 8;
85  const static int CLOUD_RENDERBIN = 9;
86  const static int DEFAULT_TRANSPARENT_RENDERBIN = 10;
87  const static int COCKPIT_RENDERBIN = 25;
88 
89  //Render bin names
90  static const std::string AlphaToCoverageBin;
91  static const std::string SkyBin;
92  static const std::string DepthOnlyBin;
93  static const std::string OceanBin;
94  static const std::string LightPointBin;
95  static const std::string CloudBin;
96  static const std::string CockpitBin;
97 
102  static DtOsgRenderer* findInstance(DtDe& de);
103 
105  virtual ~DtOsgRenderer();
106 
108  virtual void update();
109 
111  virtual void render();
112 
114  virtual bool viewExists() const;
115 
117  virtual void resetSceneGraph();
118 
121  virtual void removeChannelRoot(DtChannel* channel);
122 
124  virtual void addNodeToRoot(osg::Node* node, const DtSceneRoot& sr, bool createOnAccess = true);
125 
127  virtual void removeNodeFromRoot(osg::Node* node, const DtSceneRoot& sr);
128 
130  virtual void traverseRoot(osg::NodeVisitor& nv, const DtSceneRoot& sr);
131 
133  virtual void setSceneRootNodeMask(const DtSceneRoot& sr,
134  osg::Node::NodeMask nodemask);
135 
137  virtual osg::Node::NodeMask sceneRootNodeMask(const DtSceneRoot& sr);
138 
140  virtual osg::BoundingSphere sceneRootBound(const DtSceneRoot& sr);
141 
143  virtual osg::BoundingSphere sceneRootListBound(const DtSceneRootList& srList);
144 
146  virtual void addChannelToModelSetRoot(int modelSetId,
147  DtChannel* channel);
148 
150  virtual void removeChannelFromModelSetRoot(int modelSetId,
151  DtChannel* channel);
152 
154  virtual void addChannelToVisualizerRoot(int modelSetId,
155  int visualizerType, DtChannel* channel);
156 
158  virtual void removeChannelFromVisualizerRoot(int modelSetId,
159  int visualizerType, DtChannel* channel);
160 
162  virtual void setSceneDataToRenderRoot(osgViewer::View& view);
163 
165  virtual void addSceneToCamera(osg::Camera* camera);
166 
171  virtual void addSceneRootToNode(const DtSceneRoot& sr,
172  osg::Group* node, bool createOnAccess = true);
173 
178  virtual osg::Group* findSceneRootChildByName(const DtSceneRoot& parent,
179  const std::string& rootName);
180 
182  virtual bool matchesSceneRoot(const DtSceneRoot& sr, osg::Group* group);
183 
185  virtual void releaseResources()
186  {
187  releaseResources(0);
188  }
189 
191  virtual void releaseResources(osg::State* state);
192 
195  void setRootNode(osg::Group*, bool copyChildrenFromOldRoot);
196 
198  void resetRoot();
199 
202  void registerPagedLODs(osg::Node* node);
203 
206  void clearPagedLODs();
207 
209  virtual void setWireframeRendering(bool enabled);
210 
212  virtual void setDdsFlip(bool flip);
213 
215  virtual bool wireframeRendering() const;
216 
218  virtual void setShadowState(bool enabled);
219 
221  virtual bool shadowsEnabled() const;
222 
224  void setTerrainScalingEnabled(bool enabled);
225 
227  void setTerrainScaleFactor(double scaleFactor);
228 
231  virtual bool makeContextCurrent();
232 
234  DtFontManager& fontManager();
235  const DtFontManager& fontManager() const;
236 
238  DtEffectManager& effectManager();
239  const DtEffectManager& effectManager() const;
240 
241  boost::signal< void(int modelSet, int visualType) > signal_visualizerRootAdded;
242  boost::signal< void(DtChannel*) > signal_channelRootAdded;
243 
244 
245  boost::signal< void() > signal_shadowsRemoved;
246 
248  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents);
249 
251  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents, const osg::Quat& orientation);
252 
254  void setChannelShadowState(DtOsgChannel* osgChannel, bool enable);
255 
257  bool getChannelShadowSettings(DtOsgChannel* osgChannel, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
258 
260  bool getChannelCloudShadowMap(DtOsgChannel* osgChannel, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix,
261  unsigned int* textureIndex2, osg::Matrix* textureViewProjMatrix2);
262 
264  bool getCameraCloudShadowMap(osg::Camera* camera, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix,
265  unsigned int* textureIndex2, osg::Matrix* textureViewProjMatrix2);
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 
279  virtual void addMainThreadOperation(DtMainThreadOperation * opp);
280  virtual void addMainThreadPreDrawOperation(DtMainThreadOperation * opp);
281 
283  virtual int alphaToCoverageRenderBin();
284 
285  public:
287  //@ {
288  static DtSceneRoot renderRoot();
289  static DtSceneRoot environmentRoot();
290  static DtSceneRoot terrainRoot();
291  static DtSceneRoot propRoot();
292  static DtSceneRoot oceanRoot();
293  static DtSceneRoot modelSetRoot(int modelSet)
294  {
295  return DtSceneRoot(modelSet);
296  }
297  static DtSceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
298  {
299  return DtSceneRoot(modelSet, visualizerType);
300  }
301  static DtSceneRoot channelRoot(int modelSet, DtChannel* channel)
302  {
303  return DtSceneRoot(modelSet, channel);
304  }
305  //@ }
306 
307 
310  osg::Group* sgRenderRoot();
311 
314  osg::Group* sgEnvironmentRoot();
315 
317  osg::Group* sgPropsRoot();
318 
320  osg::Group* sgTerrainRoot();
321 
323  osg::Group* sgScaledTerrainRoot();
324 
326  osg::Group* sgScaledPropsRoot();
327 
329  osg::Group* sgStatic2dDebugRoot();
330 
332  osg::Group* sgStatic3dDebugRoot();
333 
335  osg::Group* sgOceanRoot();
336 
337  protected:
338 
340  virtual void moveRootToShadowRoot(const DtSceneRoot& targetRoot,
341  osg::Group* shadowRoot, osg::Group* modelSetRoot);
342 
347  virtual osgViewer::ViewerBase& viewer();
348 
351  DtOsgRenderer(DtDe& de);
352 
353 
359  osg::Group* sgModelSetRoot(int modelSet);
360 
366  osg::Group* sgVisualizerRoot(int modelSet, int visualizerType,
367  bool createOnAccess = true);
368 
374  osg::Group* sgChannelRoot(int modelSet,
375  DtChannel* channel, bool createOnAccess = true);
376 
378  void slot_onViewCreated();
379 
382  void slot_onViewToBeDestroyed();
383 
385  void slot_onWireframeModeChanged(bool mode);
386 
388  void slot_onDdsFlipChanged(bool flip);
389 
391  void slot_onShadowStateChanged(bool shadowMode);
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 
415  void clearFrameBufferIfChannelChanged();
416 
419  virtual void removeShadows();
420 
422  virtual void createShadowRoots();
423 
427  virtual bool exportTerrainAndProps(const std::string&);
428 
429  virtual osg::Group* createModelSetRoot(int modelSet);
430  virtual osg::Group* createVisualizerRoot(int modelSet,
431  int visualizer);
432 
434  virtual osg::Group* createChannelRoot(int modelSet, DtChannel*);
435 
436  virtual osgShadow::ShadowedScene*
437  createModelSetSpecificShadowRootAndScene(int modelSet);
438  virtual osg::Group* modelSetSpecificShadowRoot(int modelSet);
439  virtual osgShadow::ShadowedScene*
440  modelSetSpecificShadowScene(int modelSet);
441 
442  virtual void updateTerrainScaling();
443 
444  virtual void initAerodromeManagers();
445  virtual void updateAerodrome();
446 
447  // replace currentChild in all its parents with newChild
448  void swapChildren(osg::Node* currentChild, osg::Node* newChild);
449 
452  virtual void updateRenderMap(const CullSet& cullSet);
453 
456  void postInitialize();
457 
459  void setupAtcVirtualProgram();
460 
461  protected:
463 
466 
468 
474  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
475 
476  // This the top of the render graph
477  osg::ref_ptr<osg::Group> myRenderRoot;
478 
480  osg::ref_ptr<osg::Group> myDebugRoot;
481 
483  osg::ref_ptr<osg::Group> myStatic2dDebugRoot;
484 
486  osg::ref_ptr<osg::Group> myStatic3dDebugRoot;
487 
489  osg::ref_ptr<osg::Geode> myDebugBox;
490 
491  // This goes directly below the root, and sets the environment (such as sky)
492  osg::ref_ptr<osg::Group> myEnvironmentRoot;
493 
494  // attached under each modelset root, terrains are placed here
495  osg::ref_ptr<osg::Group> myTerrainRoot;
496 
497  // attached under each modelset root, props are placed here
498  osg::ref_ptr<osg::Group> myPropsRoot;
499 
500  // root for triton
501  osg::ref_ptr<osg::Group> myOceanRoot;
502 
503  // when terrain scaling is enabled, this is placed above the
504  // terrain root
505  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
506 
507  // when terrain scaling is enabled, this is placed above the
508  // props root
509  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
510 
511  osg::Matrix myScaleMatrix;
512 
513  // shadows and visual type roots are done one per model set
514  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
515  typedef boost::unordered_map<int, osg::ref_ptr<osgShadow::ShadowedScene> > ShadowedSceneMap;
516 
517  typedef int ModelSet;
518  typedef int VisualizerType;
519 
520  // There is one group for each model set, which is either an osg::Group
521  // or a DtChannelSpecificGroup
522  typedef boost::unordered_map < ModelSet, osg::ref_ptr<osg::Group> >
524 
525  typedef boost::unordered_map < VisualizerType, osg::ref_ptr<osg::Group> >
527 
531  typedef boost::unordered_map < ModelSet, VisualizerTypeRootMap >
533 
534 
535  // This is a map of the model set roots. CWhen a channel uses a model set
536  // (or more correctly, when a channel's observer uses a model set) the
537  // channel subscribes to the appropriate one of these
539 
540  // Under each model set root is a root for each visualizer type. This map
541  // provides another map, by model set, of the roots for each visual type
543 
544  // This is a map of channel roots by model set. Each channel root is a unique
551  typedef boost::unordered_map < DtChannel*, ModelSetRootMap >
553 
557 
558  osg::ref_ptr<osgUtil::RenderBin> myAlphaToCoverageBin;
559  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
560  osg::ref_ptr<osgUtil::RenderBin> myDepthOnlyBin;
561  osg::ref_ptr<osgUtil::RenderBin> myOceanBin;
562  osg::ref_ptr<osgUtil::RenderBin> myLightPointBin;
563  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
564  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
565 
568 
572 
578 
580 
581  protected:
587 
588  };
589 
593  {
594  public:
595 
597  virtual DtRenderer* create(DtDe& de);
598  };
599 }

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)