VR-Forces 4.7 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 osgViewer
33 {
34  class CompositeViewer;
35 }
36 
37 namespace osgShadow
38 {
39  class ShadowedScene;
40 }
41 
42 namespace osgEarth
43 {
44  class MapNode;
45 }
46 
47 namespace makVrv
48 {
49  class DtStatsSet;
50  class DtChannel;
51  class DtOsgChannel;
52  class DtEffectManager;
53  class DtFontManager;
54  class DtOsgWindowManager;
55  class DtOsgProfilerOverlay;
56  class DtOsgPerformanceStatsOverlay;
57  class DtFastMatrixTransform;
58  class DtSceneGraph;
59  //class DtOsgLightingComponent;
60  class DtOsgGlobalShaderComponent;
61  class DtShadowSettingsObject;
62  class DtTaxiwaySignManager;
63  class DtRunwayMarkingManager;
64  class DtLightIndicatorManager;
65  class DtMainThreadJobsManager;
66 
67 
75  {
76  public:
77  friend class DtSceneGraph;
78  friend class DtOsgRendererCreator;
79  friend class DtSceneGraphTreeLogic;
80 
81  //Render bin definitions.
82  const static int SKY_RENDERBIN = -10;
83  const static int DEFAULT_RENDERBIN = 0;
84  const static int DEPTH_ONLY_RENDERBIN = 6;
85  const static int OCEAN_RENDERBIN = 7;
86  const static int LIGHTPOINT_RENDERBIN = 8;
87  const static int CLOUD_RENDERBIN = 9;
88  const static int DEFAULT_TRANSPARENT_RENDERBIN = 10;
89  const static int COCKPIT_RENDERBIN = 25;
90 
91  //Render bin names
92  static const std::string AlphaToCoverageBin;
93  static const std::string SkyBin;
94  static const std::string DepthOnlyBin;
95  static const std::string OceanBin;
96  static const std::string LightPointBin;
97  static const std::string CloudBin;
98  static const std::string CockpitBin;
99 
104  static DtOsgRenderer* findInstance(DtDe& de);
105 
107  virtual ~DtOsgRenderer();
108 
110  virtual void update();
111 
113  virtual void render();
114 
116  virtual bool viewExists() const;
117 
119  virtual void resetSceneGraph();
120 
123  virtual void removeChannelRoot(DtChannel* channel);
124 
126  virtual void addNodeToRoot(osg::Node* node, const DtSceneRoot& sr, bool createOnAccess = true);
127 
129  virtual void removeNodeFromRoot(osg::Node* node, const DtSceneRoot& sr);
130 
132  virtual void traverseRoot(osg::NodeVisitor& nv, const DtSceneRoot& sr);
133 
135  virtual void setSceneRootNodeMask(const DtSceneRoot& sr,
136  osg::Node::NodeMask nodemask);
137 
139  virtual osg::Node::NodeMask sceneRootNodeMask(const DtSceneRoot& sr);
140 
142  virtual osg::BoundingSphere sceneRootBound(const DtSceneRoot& sr);
143 
145  virtual osg::BoundingSphere sceneRootListBound(const DtSceneRootList& srList);
146 
148  virtual void addChannelToModelSetRoot(int modelSetId,
149  DtChannel* channel);
150 
152  virtual void removeChannelFromModelSetRoot(int modelSetId,
153  DtChannel* channel);
154 
156  virtual void addChannelToVisualizerRoot(int modelSetId,
157  int visualizerType, DtChannel* channel);
158 
160  virtual void removeChannelFromVisualizerRoot(int modelSetId,
161  int visualizerType, DtChannel* channel);
162 
164  virtual void setSceneDataToRenderRoot(osgViewer::View& view);
165 
167  virtual void addSceneToCamera(osg::Camera* camera);
168 
173  virtual void addSceneRootToNode(const DtSceneRoot& sr,
174  osg::Group* node, bool createOnAccess = true);
175 
180  virtual osg::Group* findSceneRootChildByName(const DtSceneRoot& parent,
181  const std::string& rootName);
182 
184  virtual bool matchesSceneRoot(const DtSceneRoot& sr, osg::Group* group);
185 
187  virtual void releaseResources()
188  {
189  releaseResources(0);
190  }
191 
193  virtual void releaseResources(osg::State* state);
194 
197  void setRootNode(osg::Group*, bool copyChildrenFromOldRoot);
198 
200  void resetRoot();
201 
204  void registerPagedLODs(osg::Node* node);
205 
208  void clearPagedLODs();
209 
211  virtual void setWireframeRendering(bool enabled);
212 
214  virtual void setDdsFlip(bool flip);
215 
217  virtual bool wireframeRendering() const;
218 
220  virtual void setShadowState(bool enabled);
221 
223  virtual bool shadowsEnabled() const;
224 
226  void setTerrainScalingEnabled(bool enabled);
227 
229  void setTerrainScaleFactor(double scaleFactor);
230 
233  virtual bool makeContextCurrent();
234 
236  DtFontManager& fontManager();
237  const DtFontManager& fontManager() const;
238 
240  DtEffectManager& effectManager();
241  const DtEffectManager& effectManager() const;
242 
243  boost::signal< void(int modelSet, int visualType) > signal_visualizerRootAdded;
244  boost::signal< void(DtChannel*) > signal_channelRootAdded;
245 
246 
247  boost::signal< void() > signal_shadowsRemoved;
248 
250  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents);
251 
253  void debugDrawBox(const osg::Vec3& center, const osg::Vec3& extents, const osg::Quat& orientation);
254 
256  void setChannelShadowState(DtOsgChannel* osgChannel, bool enable);
257 
259  bool getChannelShadowSettings(DtOsgChannel* osgChannel, DtShadowSettingsObject** shadowSettingObject, bool* isPlanView);
260 
262  bool getChannelCloudShadowMap(DtOsgChannel* osgChannel, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix,
263  unsigned int* textureIndex2, osg::Matrix* textureViewProjMatrix2);
264 
266  bool getCameraCloudShadowMap(osg::Camera* camera, unsigned int* textureIndex, osg::Matrix* textureViewProjMatrix,
267  unsigned int* textureIndex2, osg::Matrix* textureViewProjMatrix2);
268 
270  osg::StateSet* sgRenderRootStateSet();
271 
273  // structure to expedite culling. We need to clear any memory
274  // that this structure caches to decrement reference count of
275  // StateSets (and hence drawables, textures, etc) when scene
276  // changes completely (e.g. on post processor turned off/on)
277  // so that memory can be reclaimed
278  // This helper function accomplishes that
279  void clearStateGraphForAllChannels(void);
280 
282  virtual void addMainThreadPersistantJob(osg::Operation * opp);
283 
285  virtual void removeMainThreadPersistantJob(osg::Operation * opp);
286 
288  virtual void addMainThreadPreDrawJob(osg::Operation * opp);
289 
291  virtual void addMainThreadTransientJob(osg::Operation * operation);
292 
294  virtual DtMainThreadJobsManager * createJobsManager();
295 
297  virtual int alphaToCoverageRenderBin();
298 
299  public:
301  //@ {
302  static DtSceneRoot renderRoot();
303  static DtSceneRoot environmentRoot();
304  static DtSceneRoot terrainRoot();
305  static DtSceneRoot propRoot();
306  static DtSceneRoot oceanRoot();
307  static DtSceneRoot modelSetRoot(int modelSet)
308  {
309  return DtSceneRoot(modelSet);
310  }
311  static DtSceneRoot visualizerTypeRoot(int modelSet, int visualizerType)
312  {
313  return DtSceneRoot(modelSet, visualizerType);
314  }
315  static DtSceneRoot channelRoot(int modelSet, DtChannel* channel)
316  {
317  return DtSceneRoot(modelSet, channel);
318  }
319  //@ }
320 
321 
324  osg::Group* sgRenderRoot();
325 
328  osg::Group* sgEnvironmentRoot();
329 
331  osg::Group* sgPropsRoot();
332 
334  osg::Group* sgTerrainRoot();
335 
337  osg::Group* sgScaledTerrainRoot();
338 
340  osg::Group* sgScaledPropsRoot();
341 
343  osg::Group* sgStatic2dDebugRoot();
344 
346  osg::Group* sgStatic3dDebugRoot();
347 
349  osg::Group* sgOceanRoot();
350 
351  protected:
352 
354  virtual void moveRootToShadowRoot(const DtSceneRoot& targetRoot,
355  osg::Group* shadowRoot, osg::Group* modelSetRoot);
356 
361  virtual osgViewer::ViewerBase& viewer();
362 
365  DtOsgRenderer(DtDe& de);
366 
367 
373  osg::Group* sgModelSetRoot(int modelSet);
374 
380  osg::Group* sgVisualizerRoot(int modelSet, int visualizerType,
381  bool createOnAccess = true);
382 
388  osg::Group* sgChannelRoot(int modelSet,
389  DtChannel* channel, bool createOnAccess = true);
390 
392  void slot_onViewCreated();
393 
396  void slot_onViewToBeDestroyed();
397 
399  void slot_onWireframeModeChanged(bool mode);
400 
402  void slot_onDdsFlipChanged(bool flip);
403 
405  void slot_onShadowStateChanged(bool shadowMode);
406 
408  void slot_onTerrainScalingEnabledChanged(bool enabled);
409 
411  void slot_onTerrainScaleFactorChanged(double scaleFactor);
412 
414  void slot_onCoordinateSystemChanged(const std::string& coordinateSystemType);
415 
417  void advanceTime();
418 
419  void updateSceneGraph();
420 
423  void clearEmptyWindows();
424 
429  void clearFrameBufferIfChannelChanged();
430 
433  virtual void removeShadows();
434 
436  virtual void createShadowRoots();
437 
441  virtual bool exportTerrainAndProps(const std::string&);
442 
443  virtual osg::Group* createModelSetRoot(int modelSet);
444  virtual osg::Group* createVisualizerRoot(int modelSet,
445  int visualizer);
446 
448  virtual osg::Group* createChannelRoot(int modelSet, DtChannel*);
449 
450  virtual osgShadow::ShadowedScene*
451  createModelSetSpecificShadowRootAndScene(int modelSet);
452  virtual osg::Group* modelSetSpecificShadowRoot(int modelSet);
453  virtual osgShadow::ShadowedScene*
454  modelSetSpecificShadowScene(int modelSet);
455 
456  virtual void updateTerrainScaling();
457 
458  virtual void initAerodromeManagers();
459  virtual void updateAerodrome();
460 
461  // replace currentChild in all its parents with newChild
462  void swapChildren(osg::Node* currentChild, osg::Node* newChild);
463 
466  virtual void updateRenderMap(const CullSet& cullSet);
467 
470  void postInitialize();
471 
473  void setupAtcVirtualProgram();
474 
475  protected:
479  static int numDatabasePagerThreads(osgViewer::CompositeViewer& viewer);
480 
482  static void plotHistogram(float frame_duration, int paging_threads, int mipthreads);
483 
485  static void updateLoaderStats(DtDe & myDe, osgViewer::CompositeViewer &viewer,
486  osg::Texture::TextureObjectManager * tom);
487 
488  protected:
490 
493 
495 
501  osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
502 
503  // This the top of the render graph
504  osg::ref_ptr<osg::Group> myRenderRoot;
505 
507  osg::ref_ptr<osg::Group> myDebugRoot;
508 
510  osg::ref_ptr<osg::Group> myStatic2dDebugRoot;
511 
513  osg::ref_ptr<osg::Group> myStatic3dDebugRoot;
514 
516  osg::ref_ptr<osg::Geode> myDebugBox;
517 
518  // This goes directly below the root, and sets the environment (such as sky)
519  osg::ref_ptr<osg::Group> myEnvironmentRoot;
520 
521  // attached under each modelset root, terrains are placed here
522  osg::ref_ptr<osg::Group> myTerrainRoot;
523 
524  // attached under each modelset root, props are placed here
525  osg::ref_ptr<osg::Group> myPropsRoot;
526 
527  // root for triton
528  osg::ref_ptr<osg::Group> myOceanRoot;
529 
530  // when terrain scaling is enabled, this is placed above the
531  // terrain root
532  osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
533 
534  // when terrain scaling is enabled, this is placed above the
535  // props root
536  osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
537 
538  osg::Matrix myScaleMatrix;
539 
540  // shadows and visual type roots are done one per model set
541  typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
542  typedef boost::unordered_map<int, osg::ref_ptr<osgShadow::ShadowedScene> > ShadowedSceneMap;
543 
544  typedef int ModelSet;
545  typedef int VisualizerType;
546 
547  // There is one group for each model set, which is either an osg::Group
548  // or a DtChannelSpecificGroup
549  typedef boost::unordered_map < ModelSet, osg::ref_ptr<osg::Group> >
551 
552  typedef boost::unordered_map < VisualizerType, osg::ref_ptr<osg::Group> >
554 
558  typedef boost::unordered_map < ModelSet, VisualizerTypeRootMap >
560 
561 
562  // This is a map of the model set roots. CWhen a channel uses a model set
563  // (or more correctly, when a channel's observer uses a model set) the
564  // channel subscribes to the appropriate one of these
566 
567  // Under each model set root is a root for each visualizer type. This map
568  // provides another map, by model set, of the roots for each visual type
570 
571  // This is a map of channel roots by model set. Each channel root is a unique
578  typedef boost::unordered_map < DtChannel*, ModelSetRootMap >
580 
584 
585  osg::ref_ptr<osgUtil::RenderBin> myAlphaToCoverageBin;
586  osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
587  osg::ref_ptr<osgUtil::RenderBin> myDepthOnlyBin;
588  osg::ref_ptr<osgUtil::RenderBin> myOceanBin;
589  osg::ref_ptr<osgUtil::RenderBin> myLightPointBin;
590  osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
591  osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
592 
595 
599 
605 
607 
608  // system for doing work during cull
611 
612  protected:
618 
619  };
620 
624  {
625  public:
626 
628  virtual DtRenderer* create(DtDe& de);
629  };
630 }

Document ID: Generated on Fri Apr 26 21:53:14 EDT 2019 from SVN revision 197883
Copyright © 2005-2019 VT MAK. All Rights Reserved (www.mak.com)