VR-Forces 4.6.1 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) 2018 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  class DtMainThreadJobsManager;
61 
62 
70  {
71  public:
72  friend class DtSceneGraph;
73  friend class DtOsgRendererCreator;
74  friend class DtSceneGraphTreeLogic;
75 
76  //Render bin definitions.
77  const static int SKY_RENDERBIN = -10;
78  const static int DEFAULT_RENDERBIN = 0;
79  const static int DEPTH_ONLY_RENDERBIN = 6;
80  const static int OCEAN_RENDERBIN = 7;
81  const static int LIGHTPOINT_RENDERBIN = 8;
82  const static int CLOUD_RENDERBIN = 9;
83  const static int DEFAULT_TRANSPARENT_RENDERBIN = 10;
84  const static int COCKPIT_RENDERBIN = 25;
85 
86  //Render bin names
87  static const std::string AlphaToCoverageBin;
88  static const std::string SkyBin;
89  static const std::string DepthOnlyBin;
90  static const std::string OceanBin;
91  static const std::string LightPointBin;
92  static const std::string CloudBin;
93  static const std::string CockpitBin;
94 
99  static DtOsgRenderer* findInstance(DtDe& de);
100 
102  virtual ~DtOsgRenderer();
103 
105  virtual void update();
106 
108  virtual void render();
109 
111  virtual bool viewExists() const;
112 
114  virtual void resetSceneGraph();
115 
118  virtual void removeChannelRoot(DtChannel* channel);
119 
121  virtual void addNodeToRoot(osg::Node* node, const DtSceneRoot& sr, bool createOnAccess = true);
122 
124  virtual void removeNodeFromRoot(osg::Node* node, const DtSceneRoot& sr);
125 
127  virtual void traverseRoot(osg::NodeVisitor& nv, const DtSceneRoot& sr);
128 
130  virtual void setSceneRootNodeMask(const DtSceneRoot& sr,
131  osg::Node::NodeMask nodemask);
132 
134  virtual osg::Node::NodeMask sceneRootNodeMask(const DtSceneRoot& sr);
135 
137  virtual osg::BoundingSphere sceneRootBound(const DtSceneRoot& sr);
138 
140  virtual osg::BoundingSphere sceneRootListBound(const DtSceneRootList& srList);
141 
143  virtual void addChannelToModelSetRoot(int modelSetId,
144  DtChannel* channel);
145 
147  virtual void removeChannelFromModelSetRoot(int modelSetId,
148  DtChannel* channel);
149 
151  virtual void addChannelToVisualizerRoot(int modelSetId,
152  int visualizerType, DtChannel* channel);
153 
155  virtual void removeChannelFromVisualizerRoot(int modelSetId,
156  int visualizerType, DtChannel* channel);
157 
159  virtual void setSceneDataToRenderRoot(osgViewer::View& view);
160 
162  virtual void addSceneToCamera(osg::Camera* camera);
163 
168  virtual void addSceneRootToNode(const DtSceneRoot& sr,
169  osg::Group* node, bool createOnAccess = true);
170 
175  virtual osg::Group* findSceneRootChildByName(const DtSceneRoot& parent,
176  const std::string& rootName);
177 
179  virtual bool matchesSceneRoot(const DtSceneRoot& sr, osg::Group* group);
180 
182  virtual void releaseResources()
183  {
184  releaseResources(0);
185  }
186 
188  virtual void releaseResources(osg::State* state);
189 
192  void setRootNode(osg::Group*, bool copyChildrenFromOldRoot);
193 
195  void resetRoot();
196 
199  void registerPagedLODs(osg::Node* node);
200 
203  void clearPagedLODs();
204 
206  virtual void setWireframeRendering(bool enabled);
207 
209  virtual void setDdsFlip(bool flip);
210 
212  virtual bool wireframeRendering() const;
213 
215  virtual void setShadowState(bool enabled);
216 
218  virtual bool shadowsEnabled() const;
219 
221  void setTerrainScalingEnabled(bool enabled);
222 
224  void setTerrainScaleFactor(double scaleFactor);
225 
228  virtual bool makeContextCurrent();
229 
231  DtFontManager& fontManager();
232  const DtFontManager& fontManager() const;
233 
235  DtEffectManager& effectManager();
236  const DtEffectManager& effectManager() const;
237 
238  boost::signal< void(int modelSet, int visualType) > signal_visualizerRootAdded;
239  boost::signal< void(DtChannel*) > signal_channelRootAdded;
240 
241 
242  boost::signal< void() > signal_shadowsRemoved;
243 
245  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents);
246 
248  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents, const osg::Quat& orientation);
249 
251  void setChannelShadowState(DtOsgChannel* osgChannel, bool enable);
252 
254  bool getChannelShadowSettings(DtOsgChannel* osgChannel, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
255 
257  bool getChannelCloudShadowMap(DtOsgChannel* osgChannel, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix,
258  unsigned int* textureIndex2, osg::Matrix* textureViewProjMatrix2);
259 
261  bool getCameraCloudShadowMap(osg::Camera* camera, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix,
262  unsigned int* textureIndex2, osg::Matrix* textureViewProjMatrix2);
263 
265  osg::StateSet* sgRenderRootStateSet();
266 
268  // structure to expedite culling. We need to clear any memory
269  // that this structure caches to decrement reference count of
270  // StateSets (and hence drawables, textures, etc) when scene
271  // changes completely (e.g. on post processor turned off/on)
272  // so that memory can be reclaimed
273  // This helper function accomplishes that
274  void clearStateGraphForAllChannels(void);
275 
277  virtual void addMainThreadPersistantJob(osg::Operation * opp);
278 
280  virtual void removeMainThreadPersistantJob(osg::Operation * opp);
281 
283  virtual void addMainThreadPreDrawJob(osg::Operation * opp);
284 
286  virtual void addMainThreadTransientJob(osg::Operation * operation);
287 
289  virtual DtMainThreadJobsManager * createJobsManager();
290 
292  virtual int alphaToCoverageRenderBin();
293 
294  public:
296  //@ {
297  static DtSceneRoot renderRoot();
298  static DtSceneRoot environmentRoot();
299  static DtSceneRoot terrainRoot();
300  static DtSceneRoot propRoot();
301  static DtSceneRoot oceanRoot();
302  static DtSceneRoot modelSetRoot(int modelSet)
303  {
304  return DtSceneRoot(modelSet);
305  }
306  static DtSceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
307  {
308  return DtSceneRoot(modelSet, visualizerType);
309  }
310  static DtSceneRoot channelRoot(int modelSet, DtChannel* channel)
311  {
312  return DtSceneRoot(modelSet, channel);
313  }
314  //@ }
315 
316 
319  osg::Group* sgRenderRoot();
320 
323  osg::Group* sgEnvironmentRoot();
324 
326  osg::Group* sgPropsRoot();
327 
329  osg::Group* sgTerrainRoot();
330 
332  osg::Group* sgScaledTerrainRoot();
333 
335  osg::Group* sgScaledPropsRoot();
336 
338  osg::Group* sgStatic2dDebugRoot();
339 
341  osg::Group* sgStatic3dDebugRoot();
342 
344  osg::Group* sgOceanRoot();
345 
346  protected:
347 
349  virtual void moveRootToShadowRoot(const DtSceneRoot& targetRoot,
350  osg::Group* shadowRoot, osg::Group* modelSetRoot);
351 
356  virtual osgViewer::ViewerBase& viewer();
357 
360  DtOsgRenderer(DtDe& de);
361 
362 
368  osg::Group* sgModelSetRoot(int modelSet);
369 
375  osg::Group* sgVisualizerRoot(int modelSet, int visualizerType,
376  bool createOnAccess = true);
377 
383  osg::Group* sgChannelRoot(int modelSet,
384  DtChannel* channel, bool createOnAccess = true);
385 
387  void slot_onViewCreated();
388 
391  void slot_onViewToBeDestroyed();
392 
394  void slot_onWireframeModeChanged(bool mode);
395 
397  void slot_onDdsFlipChanged(bool flip);
398 
400  void slot_onShadowStateChanged(bool shadowMode);
401 
403  void slot_onTerrainScalingEnabledChanged(bool enabled);
404 
406  void slot_onTerrainScaleFactorChanged(double scaleFactor);
407 
409  void slot_onCoordinateSystemChanged(const std::string& coordinateSystemType);
410 
412  void advanceTime();
413 
414  void updateSceneGraph();
415 
418  void clearEmptyWindows();
419 
424  void clearFrameBufferIfChannelChanged();
425 
428  virtual void removeShadows();
429 
431  virtual void createShadowRoots();
432 
436  virtual bool exportTerrainAndProps(const std::string&);
437 
438  virtual osg::Group* createModelSetRoot(int modelSet);
439  virtual osg::Group* createVisualizerRoot(int modelSet,
440  int visualizer);
441 
443  virtual osg::Group* createChannelRoot(int modelSet, DtChannel*);
444 
445  virtual osgShadow::ShadowedScene*
446  createModelSetSpecificShadowRootAndScene(int modelSet);
447  virtual osg::Group* modelSetSpecificShadowRoot(int modelSet);
448  virtual osgShadow::ShadowedScene*
449  modelSetSpecificShadowScene(int modelSet);
450 
451  virtual void updateTerrainScaling();
452 
453  virtual void initAerodromeManagers();
454  virtual void updateAerodrome();
455 
456  // replace currentChild in all its parents with newChild
457  void swapChildren(osg::Node* currentChild, osg::Node* newChild);
458 
461  virtual void updateRenderMap(const CullSet& cullSet);
462 
465  void postInitialize();
466 
468  void setupAtcVirtualProgram();
469 
470  protected:
474  static int numDatabasePagerThreads(osgViewer::CompositeViewer& viewer);
475 
477  static void plotHistogram(float frame_duration, int paging_threads, int mipthreads);
478 
480  static void updateLoaderStats(DtDe & myDe, osgViewer::CompositeViewer &viewer,
481  osg::Texture::TextureObjectManager * tom);
482 
483  protected:
485 
488 
490 
496  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
497 
498  // This the top of the render graph
499  osg::ref_ptr<osg::Group> myRenderRoot;
500 
502  osg::ref_ptr<osg::Group> myDebugRoot;
503 
505  osg::ref_ptr<osg::Group> myStatic2dDebugRoot;
506 
508  osg::ref_ptr<osg::Group> myStatic3dDebugRoot;
509 
511  osg::ref_ptr<osg::Geode> myDebugBox;
512 
513  // This goes directly below the root, and sets the environment (such as sky)
514  osg::ref_ptr<osg::Group> myEnvironmentRoot;
515 
516  // attached under each modelset root, terrains are placed here
517  osg::ref_ptr<osg::Group> myTerrainRoot;
518 
519  // attached under each modelset root, props are placed here
520  osg::ref_ptr<osg::Group> myPropsRoot;
521 
522  // root for triton
523  osg::ref_ptr<osg::Group> myOceanRoot;
524 
525  // when terrain scaling is enabled, this is placed above the
526  // terrain root
527  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
528 
529  // when terrain scaling is enabled, this is placed above the
530  // props root
531  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
532 
533  osg::Matrix myScaleMatrix;
534 
535  // shadows and visual type roots are done one per model set
536  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
537  typedef boost::unordered_map<int, osg::ref_ptr<osgShadow::ShadowedScene> > ShadowedSceneMap;
538 
539  typedef int ModelSet;
540  typedef int VisualizerType;
541 
542  // There is one group for each model set, which is either an osg::Group
543  // or a DtChannelSpecificGroup
544  typedef boost::unordered_map < ModelSet, osg::ref_ptr<osg::Group> >
546 
547  typedef boost::unordered_map < VisualizerType, osg::ref_ptr<osg::Group> >
549 
553  typedef boost::unordered_map < ModelSet, VisualizerTypeRootMap >
555 
556 
557  // This is a map of the model set roots. CWhen a channel uses a model set
558  // (or more correctly, when a channel's observer uses a model set) the
559  // channel subscribes to the appropriate one of these
561 
562  // Under each model set root is a root for each visualizer type. This map
563  // provides another map, by model set, of the roots for each visual type
565 
566  // This is a map of channel roots by model set. Each channel root is a unique
573  typedef boost::unordered_map < DtChannel*, ModelSetRootMap >
575 
579 
580  osg::ref_ptr<osgUtil::RenderBin> myAlphaToCoverageBin;
581  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
582  osg::ref_ptr<osgUtil::RenderBin> myDepthOnlyBin;
583  osg::ref_ptr<osgUtil::RenderBin> myOceanBin;
584  osg::ref_ptr<osgUtil::RenderBin> myLightPointBin;
585  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
586  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
587 
590 
594 
600 
602 
603  // system for doing work during cull
606 
607  protected:
613 
614  };
615 
619  {
620  public:
621 
623  virtual DtRenderer* create(DtDe& de);
624  };
625 }

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)