VR-Forces 4.0.4 Class Documentation
include/vrvOsg/DtOsgRenderer.h
Go to the documentation of this file.
00001 /****************************************************************************** 
00002 ** Copyright (c) 2012 MAK Technologies, Inc. 
00003 ** All rights reserved. 
00004 ******************************************************************************/ 
00005  
00009 
00010 #pragma once
00011  
00012 #include <vrvOsg/vrvOsg.h>
00013 #include <vrvCore/DtRenderer.h>
00014 #include <vrvCore/DtDe.h>
00015 
00016 #include <osg/ref_ptr>
00017 #include <osgUtil/RenderBin>
00018 #include <osgViewer/Viewer>
00019 #include <vector>
00020 
00021 #include <boost/unordered_map.hpp>
00022 #include <boost/signals.hpp>
00023 
00024 namespace osg
00025 {
00026    class Group;
00027    class Node;
00028 }
00029 
00030 namespace makOsgShadowFX
00031 {
00032    class DtShadowEffect;
00033 }
00034 
00035 namespace makVrv 
00036 {
00037    class DtStatsSet;
00038    class DtChannel;
00039    class DtEffectManager;
00040    class DtFontManager;
00041    class DtOsgWindowManager;
00042    class DtOsgPerformanceStatsOverlay;
00043    class DtFastMatrixTransform;
00044  
00051    class DT_DLL_VRVOSG DtOsgRenderer : public DtRenderer
00052    {
00053    public:
00054 
00057       enum RootDomain
00058       {
00059          RenderSystem,
00060          Environment,
00061          Terrain,
00062          Prop,
00063          ModelSetSpecific,
00064          VisualizerTypeSpecific     
00065       };
00066 
00071       class SceneRoot
00072       {
00073       public:
00074          SceneRoot() {}
00075          SceneRoot(RootDomain domain) 
00076             : myDomain(domain) 
00077          {}
00078          SceneRoot(int modelSet)
00079             : myDomain(ModelSetSpecific)
00080          { 
00081             myParameter.modelSetId = modelSet; 
00082          }
00083          SceneRoot(int modelSet, int visualizerType)
00084             : myDomain(VisualizerTypeSpecific)
00085          {
00086             myParameter.modelSetId = modelSet;
00087             myParameter.visualizerType = visualizerType;
00088          }
00089 
00090          bool operator==(SceneRoot rhs) const
00091          {
00092             if ( myDomain == ModelSetSpecific )
00093             {
00094                return myDomain == rhs.myDomain && 
00095                   myParameter.modelSetId == rhs.myParameter.modelSetId;
00096             }
00097             if ( myDomain == VisualizerTypeSpecific )
00098             {
00099                return myDomain == rhs.myDomain && 
00100                   myParameter.modelSetId == rhs.myParameter.modelSetId &&
00101                   myParameter.visualizerType == rhs.myParameter.visualizerType;
00102             }
00103             return myDomain == rhs.myDomain;
00104          }
00105 
00107          RootDomain myDomain;
00108          struct
00109          {    
00111             int modelSetId;
00113             int visualizerType;        
00114          } myParameter;
00115       };
00116      
00118       typedef std::vector<SceneRoot> RootList;
00119 
00120    public:
00121 
00122       friend class DtOsgRendererCreator;
00123       friend class DtSceneGraphTreeLogic;
00124 
00125       //Render bin definitions.
00126       const static int SKY_RENDERBIN    = -10;
00127       const static int CLOUDS_RENDERBIN = 9;
00128       const static int COCKPIT_RENDERBIN    = 25;
00129 
00134       static DtOsgRenderer* findInstance(DtDe& de);
00135 
00137       virtual ~DtOsgRenderer();
00138 
00140       virtual void update();      
00141       
00143       virtual void render();
00144 
00146       virtual void resetSceneGraph();
00147 
00149       virtual void addNodeToRoot(osg::Node* node, SceneRoot sr, bool createOnAccess=true );
00150 
00152       virtual void removeNodeFromRoot(osg::Node* node, SceneRoot sr);
00153 
00155       virtual void traverseRoot(osg::NodeVisitor& nv, SceneRoot sr);  
00156   
00158       virtual void setSceneRootNodeMask(SceneRoot sr, 
00159          osg::Node::NodeMask nodemask);
00160 
00162       virtual osg::Node::NodeMask sceneRootNodeMask(SceneRoot sr);
00163 
00165       virtual osg::BoundingSphere sceneRootBound(SceneRoot sr);
00166 
00168       virtual osg::BoundingSphere sceneRootListBound(const RootList& srList);
00169 
00171       virtual void addChannelToModelSetRoot( int modelSetId, 
00172          DtChannel* channel );
00173 
00175       virtual void removeChannelFromModelSetRoot( int modelSetId, 
00176          DtChannel* channel );
00177    
00179       virtual void addChannelToVisualizerRoot( int modelSetId, 
00180          int visualizerType, DtChannel* channel );
00181 
00183       virtual void removeChannelFromVisualizerRoot( int modelSetId, 
00184          int visualizerType, DtChannel* channel );
00185 
00187       virtual void setViewToScene( osgViewer::View& view );
00188 
00193        virtual osg::Group* findSceneRootChildByName( SceneRoot parent, 
00194           const std::string& rootName );
00195 
00196 
00197 
00198 
00200       virtual void releaseResources()
00201       {
00202          releaseResources(0);
00203       }
00204 
00206       virtual void releaseResources(osg::State* state);
00207 
00210       void setRootNode(osg::Group*,bool copyChildrenFromOldRoot);
00211 
00213       void resetRoot();
00214 
00217       void registerPagedLODs(osg::Node* node);
00218 
00221       void clearPagedLODs();
00222 
00224       virtual void setPerformanceStatsOverlayEnabled(bool show);
00225 
00227       virtual bool performanceStatsOverlayEnabled() const;
00228 
00230       virtual void setWireframeRendering(bool enabled);
00231 
00233       virtual void setDdsFlip(bool flip);
00234 
00236       virtual bool wireframeRendering() const;
00237 
00239       virtual void setShadowState(bool enabled, int quality, bool entity, 
00240                                  bool prop, bool terrain);
00241 
00243       //@ {
00244       virtual bool shadowsEnabled() const;
00245       virtual int shadowQuality() const;
00246       virtual bool entityShadowsEnabled() const;
00247       virtual bool propShadowsEnabled() const;
00248       virtual bool terrainShadowsEnabled() const;   
00249       //@ }
00250 
00252       void setTerrainScalingEnabled( bool enabled );
00253 
00255       void setTerrainScaleFactor( double scaleFactor );
00256 
00259       virtual bool makeContextCurrent();
00260 
00262       DtFontManager& fontManager();
00263       const DtFontManager& fontManager() const;
00264 
00266       DtEffectManager& effectManager();
00267       const DtEffectManager& effectManager() const;
00268       
00269       boost::signal< void ( int modelSet, int visualType ) > signal_visualizerRootAdded;
00270          
00271    public:
00273       //@ {
00274       static SceneRoot renderRoot() { return theRenderRoot; }
00275       static SceneRoot environmentRoot() { return theEnvironmentRoot; };
00276       static SceneRoot terrainRoot() { return theTerrainRoot; }   
00277       static SceneRoot propRoot() { return thePropRoot; }   
00278       static SceneRoot modelSetRoot(int modelSet) 
00279          { return SceneRoot(modelSet); }
00280       static SceneRoot visualizerTypeRoot(int modelSet, int visualizerType) 
00281          { return SceneRoot(modelSet, visualizerType); }
00282       //@ }
00283 
00284    protected:
00286       virtual void onActiveStatsOverlayChanged(DtStatsSet* activeStats);
00287 
00290       DtOsgRenderer(DtDe& de);
00291       
00294       osg::Group* sgRenderRoot();
00295       
00298       osg::Group* sgEnvironmentRoot();
00299 
00301       osg::Group* sgPropsRoot();
00302 
00304       osg::Group* sgTerrainRoot();
00305 
00307       osg::Group* sgScaledTerrainRoot();
00308 
00310       osg::Group* sgScaledPropsRoot();
00311       
00317       osg::Group* sgModelSetRoot( int modelSet );
00318       
00324       osg::Group* sgVisualizerRoot( int modelSet, int visualizerType,
00325          bool createOnAccess=true );
00326 
00328       void slot_onViewCreated();
00329 
00332       void slot_onViewToBeDestroyed();
00333 
00335       void slot_onWireframeModeChanged(bool mode);
00336 
00338       void slot_onDdsFlipChanged(bool flip);
00339 
00341       virtual void slot_onPerformanceOverlayOnChanged(bool mode);
00342 
00344       void slot_onShadowStateChanged(bool shadowMode, int shadowQual,
00345          bool entityMode, bool propMode, bool terrainMode);
00346 
00348       void slot_onTerrainScalingEnabledChanged( bool enabled );
00349 
00351       void slot_onTerrainScaleFactorChanged( double scaleFactor );
00352  
00354       void slot_onCoordinateSystemChanged(const std::string& coordinateSystemType);
00355 
00357       void advanceTime();
00358 
00359       void updateSceneGraph();
00360 
00363       void clearEmptyWindows();
00364 
00367       virtual void removeShadows();
00368 
00370       virtual void createShadowRoots();
00371 
00375       virtual bool exportTerrainAndProps(const std::string&);
00376       
00377       virtual osg::Group* createModelSetRoot( int modelSet );
00378       virtual osg::Group* createVisualizerRoot( int modelSet, 
00379          int visualizer );
00380       
00381       virtual makOsgShadowFX::DtShadowEffect* 
00382          createModelSetSpecificShadowRootAndEffect( int modelSet );
00383       virtual osg::Group* modelSetSpecificShadowRoot( int modelSet );
00384       virtual makOsgShadowFX::DtShadowEffect* 
00385          modelSetSpecificShadowEffect( int modelSet );
00386 
00387       virtual void updateTerrainScaling();
00388 
00389       // Used internally by the other scene root using functions to find the
00390       // correct root for adding/removing children, Getting child counts, etc.
00391       virtual osg::Group* getContainerRoot(SceneRoot root, bool createOnAccess);
00392 
00393       // Container roots may have other roots over them for doing transforms, etc.
00394       // This gets the topmost root associated with that scene root, useful for
00395       // traversal, nodeMask setting/getting, etc.
00396       virtual osg::Group* getActiveRoot(SceneRoot root);
00397 
00398       // replace currentChild in all its parents with newChild
00399       void swapChildren( osg::Node* currentChild, osg::Node* newChild );
00400               
00401    protected:
00402 
00403       DtFontManager*  myFontManager;
00404       DtEffectManager* myEffectManager;
00405 
00406       DtOsgWindowManager* myOsgWindowManager;
00407 
00413       osg::ref_ptr<osgViewer::Viewer> myDefaultViewer;
00414       
00415       // This the top of the render graph
00416       osg::ref_ptr<osg::Group> myRenderRoot;
00417     
00418       // This goes directly below the root, and sets the environment (such as sky)
00419       osg::ref_ptr<osg::Group> myEnvironmentRoot;
00420    
00421       // attached under each modelset root, terrains are placed here
00422       osg::ref_ptr<osg::Group> myTerrainRoot;
00423    
00424       // attached under each modelset root,  props are placed here
00425       osg::ref_ptr<osg::Group> myPropsRoot;
00426       
00427       // when terrain scaling is enabled, this is placed above the
00428       // terrain root
00429       osg::ref_ptr<DtFastMatrixTransform> myScaledTerrainRoot;
00430 
00431       // when terrain scaling is enabled, this is placed above the
00432       // props root
00433       osg::ref_ptr<DtFastMatrixTransform> myScaledPropsRoot;
00434 
00435       osg::Matrix myScaleMatrix;
00436       
00437       // shadows and visual type roots are done one per model set
00438       typedef boost::unordered_map<int, osg::ref_ptr<osg::Group> > RootMap;
00439       typedef boost::unordered_map<int, 
00440          osg::ref_ptr<makOsgShadowFX::DtShadowEffect> > ShadowEffectMap;
00441       
00442       typedef int ModelSet;
00443       typedef int VisualizerType;
00444 
00445       // There is one group for each model set, which is either an osg::Group
00446       // or a DtChannelSpecificGroup
00447       typedef boost::unordered_map<ModelSet, osg::ref_ptr<osg::Group> >
00448          ModelSetRootMap;
00449 
00450       typedef boost::unordered_map<VisualizerType, osg::ref_ptr<osg::Group> > 
00451          VisualizerTypeRootMap;
00452       
00456       typedef boost::unordered_map<ModelSet, VisualizerTypeRootMap> 
00457          ModelSetVisualizerTypeRootMap;
00458       
00459       
00460       // This is a map of the model set  roots.  CWhen a channel uses a model set 
00461       // (or more correctly, when a channel's observer uses a model set) the
00462       // channel subscribes to the appropriate one of these
00463       ModelSetRootMap myModelSetMap;
00464       
00465       // Under each model set root is a root for each visualizer type.  This map
00466       // provides another map, by model set, of the roots for each visual type
00467       ModelSetVisualizerTypeRootMap myVisualizerRootMap;
00468       
00469       ShadowEffectMap myShadowEffectMap;
00470       RootMap myShadowRootMap;
00471       
00472       osg::ref_ptr<osgUtil::RenderBin> myCloudBin;
00473       osg::ref_ptr<osgUtil::RenderBin> mySkyBin;
00474       osg::ref_ptr<osgUtil::RenderBin> myCockpitBin;
00475       
00476       bool myWireframeOn;
00477       bool myShadowsEnabled;
00478       int myShadowQuality;
00479       bool myEntityShadowMode;
00480       bool myPropShadowMode;
00481       bool myTerrainShadowMode;
00482 
00483       DtOsgPerformanceStatsOverlay* myPerformanceStatsOverlay;
00484 
00485       double myTerrainScaleFactor;
00486       bool myTerrainScaleFactorChanged;
00487       bool myTerrainScalingEnabled;
00488       bool myTerrainScalingEnabledChanged;
00489 
00490    protected:
00491       static SceneRoot theRenderRoot; 
00492       static SceneRoot theEnvironmentRoot; 
00493       static SceneRoot theTerrainRoot; 
00494       static SceneRoot thePropRoot; 
00495    };
00496 
00499    class DT_DLL_VRVOSG DtOsgRendererCreator : public DtRendererCreator
00500    {
00501    public:
00502 
00504       virtual DtRenderer* create(DtDe& de);
00505    };
00506 
00507 }

Document ID: Generated on Fri Jun 29 16:33:32 EDT 2012 from SVN revision 116588
Copyright © 2005-2012 VT MÄK Inc. All Rights Reserved (www.mak.com)