source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h @ 1214

Revision 1214, 9.4 KB checked in by szydlowski, 18 years ago (diff)
RevLine 
[1163]1/*
2-----------------------------------------------------------------------------
3This source file is part of the GameTools Project
4http://www.gametools.org
5
6Author: Martin Szydlowski
7-----------------------------------------------------------------------------
8*/
9
10#ifndef _KdTreeSceneManager_H__
11#define _KdTreeSceneManager_H__
12
[1165]13#include <OgreKdTreeHierarchyInterface.h>
[1163]14#include <OgreSceneManager.h>
[1175]15#include <VisibilityManager.h>
[1163]16#include "OgreKdTree.h"
[1206]17#include "OgreKdTreeCamera.h"
[1163]18
[1187]19#define KDTREE_MAX_DEPTH 12
[1165]20
[1163]21namespace Ogre
22{
23
[1185]24class KdTreeSceneNode;
[1163]25
[1185]26class KdTreeSceneManager : public SceneManager
27{
28public:
29        KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm);
30        ~KdTreeSceneManager(void);
[1175]31
[1185]32        virtual const String& getTypeName(void) const;
[1182]33
[1185]34        //typedef std::list<KdTreeSceneNode *> NodeList;
35        //typedef std::list<WireBoundingBox *> BoxList;
[1182]36
[1185]37        /************************************************************************/
38        /* Functions overridden form SceneManager for KdTree                    */
39        /************************************************************************/
[1177]40
[1206]41        /** Override from Scenemanager to create Camera as instance of KdTreeCamera
42        */
43        virtual Camera* createCamera(const String& name);
44
[1185]45        /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode
46        */
47        virtual SceneNode* createSceneNode(void);
48        /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode
49        */
50        virtual SceneNode* createSceneNode(const String& name);
[1182]51
[1185]52        /** Override from Scenemanager, employ kd-tree based culling or CHC
53        */
54        virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters);
[1182]55
[1185]56        virtual bool setOption(const String& strKey, const void* pValue);
57        virtual bool getOption(const String& strKey, void* pDestValue);
[1182]58
[1185]59        bool getOptionValues(const String & key, StringVector &refValueList);
60        bool getOptionKeys(StringVector &refKeys);
[1182]61
[1185]62        /** Overide from scene manager to destroy kdtree properly (before the scene graph is destroyed)
63        */
64        virtual void clearScene()
65        {
66                // DEBUG
67                //if (mKdTree)
68                //      mKdTree->dump();
[1182]69
[1185]70                // must happen before actual scene is cleared
71                OGRE_DELETE(mKdTree);
[1182]72
[1185]73                SceneManager::clearScene();
74        }
[1182]75
[1185]76        /************************************************************************/
77        /* Functions overridden from SceneManager for CHC                       */
78        /************************************************************************/
[1163]79
[1185]80        /** Override from SceneManager so that sub entities can be assigned an id for item buffer.
81        */
82        Entity* createEntity(const String& entityName, const String& meshName);
[1182]83
[1185]84        /** Override from scene manager to set up culling manager
85        */
86        virtual void _updateSceneGraph(Camera* cam);
[1182]87
[1185]88        /** Override from SceneManager, employ normal rendering or CHC
89        */
90        virtual void _renderVisibleObjects();
[1182]91
[1185]92        /** Override pass so we can do the z-fail pass.
93        */
94        const Pass* _setPass(Pass* pass);
[1182]95
[1185]96        /** Render a queue group.
97        Override so we can handle delayed rendering of transparent objects
98        */
99        void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
100                QueuedRenderableCollection::OrganisationMode om);
[1182]101
[1185]102        /** Override from scene manager
103        */
104        void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
105                QueuedRenderableCollection::OrganisationMode om);
[1182]106
[1185]107        /** Override from SceneManager so we can skip all but first pass for depth pass.
108        */
109        bool validatePassForRendering(Pass* pass);
[1182]110
[1185]111        /** Override from SceneManager because idontknow
112        */
113        void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
114                QueuedRenderableCollection::OrganisationMode om);
115        void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
116                QueuedRenderableCollection::OrganisationMode om);
[1182]117
[1175]118
[1185]119        /************************************************************************/
120        /* Functions which are specific to the KdTree                           */
121        /************************************************************************/
122       
123        /** Update the KdTree with the node (more or less disabled now)
124        */
125        virtual void _updateNode(KdTreeSceneNode *node); // TODO:
[1163]126
[1185]127        /** Show or hide the bounding boxes of KdTree nodes - obsolete, use options
128        */
129        virtual void setShowBoxes(bool showboxes);
130        /** Tell if show boxes is enabled - obsolete, use options
131        */
132        virtual bool getShowBoxes(void) const;
[1182]133
[1185]134        /************************************************************************/
135        /* Functions for CHC                                                    */
136        /************************************************************************/
[1173]137
[1185]138        /** Render a list of scenenodes
139        */
[1187]140        //virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam,
141        //      bool onlyShadowCasters, int leavePassesInQueue);
142        virtual void _renderNode(KdTree::NodePtr node, Camera * cam,
[1185]143                bool onlyShadowCasters, int leavePassesInQueue);
[1175]144
[1185]145        /** Sets the visibility manager.
146        @param visManager the visibility manager
147        */
148        void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
149        /** See set.
150        */
151        GtpVisibility::VisibilityManager *getVisibilityManager();
[1175]152
[1185]153        /** Returns pointer to visibility manager.
154        */
155        GtpVisibility::VisibilityManager *GetVisibilityManager();
[1175]156
[1185]157        /** Returns hierarchy interface.
158        */
159        KdTreeHierarchyInterface *GetHierarchyInterface();
[1175]160
[1185]161protected:
162        /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
163        */
164        void InitDepthPass();
165        /** Creates material for item buffer.
166        */
167        void InitItemBufferPass();
168        /** Fills render queue so that a visualization can be rendered.
169        */
170        void PrepareVisualization(Camera *cam);
171        /** Initialises necessary parameters for hierarchical visibility culling.
172        */
173        void InitVisibilityCulling(Camera *cam);
[1175]174
[1185]175        /** Writes out stats into the Ogre log file.
176        */
177        void WriteLog();
[1175]178
[1206]179        /** Switches between simple & enhanced visibility
180        */
[1211]181        //void setEnhancedVis(bool enhanced);
[1175]182
[1206]183
[1185]184        /************************************************************************/
185        /* CHC-specific options & members                                       */
186        /************************************************************************/
187        // pointer to the visibility manager
188        GtpVisibility::VisibilityManager *mVisibilityManager;
[1163]189
[1185]190        // the hierarchy interface for CHC
191        KdTreeHierarchyInterface *mHierarchyInterface;
[1165]192
[1185]193        // if hierarchical culling is currently in use
194        bool mIsHierarchicalCulling;
[1182]195
[1185]196        // if a visualization of the hierarchical culling is shown
197        bool mShowVisualization;
198       
199        // if the culled nodes are indicated in the visualization
200        bool mVisualizeCulledNodes;
[1182]201
[1185]202        // consecutive number for sub-entities
203        int mCurrentEntityId;
[1175]204
[1185]205        // flag for passes which should not be deleted from queue during first traversal
206        int mLeavePassesInQueue;
[1182]207
[1185]208        // if symbols for the nodes are shown in the visualization
209        bool mRenderNodesForViz;
210        // if content of the nodes is shown in the visualization
211        bool mRenderNodesContentForViz;
212        /// render transparents after the hierarchical traversal
213        bool mDelayRenderTransparents;
214       
215        // if transparent object are considered for item buffer visibility
216        bool mRenderTransparentsForItemBuffer;
217        // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
218        bool mExecuteVertexProgramForAllPasses;
[1182]219
[1185]220        // the depth pass (no lighting, just filling the depth buffer)
221        Pass *mDepthPass;
222        // use a depth pass (i.e., fill only the depth buffer in the first pass)
223        bool mUseDepthPass;
224        // flag indicating if we currently render the depth pass
225        bool mIsDepthPassPhase;
226        // if depth write should be enabled
227        bool mEnableDepthWrite;
228        // if transparents are skipped during rendering
229        bool mSkipTransparents;
[1182]230
[1185]231        // the item buffer pass (render items color-coded)
232        Pass *mItemBufferPass;
233        // if we use an item buffer for rendering (i.e., object ids as color codes
234        bool mUseItemBuffer;
235        // if we currently render the item buffer
236        bool mIsItemBufferPhase;
[1182]237
[1185]238        // remember visited scene nodes for viz
[1187]239        //KdRenderableList mVisibleNodes;
240        KdTree::NodeList mVisibleNodes;
[1163]241
[1185]242        /************************************************************************/
243        /* Kd-Tree specific options & members                                   */
244        /************************************************************************/
245        // maximum depth of the kdtree
246        int mMaxDepth;
[1163]247
[1185]248        // the kdtree which holds the scene
249        KdTree *mKdTree;
[1163]250
[1185]251        // if bounding boxes of kdtree nodes are shown
252        bool mShowBoxes;
[1192]253        // bounding boxes of kd nodes will be highlighted on this level of the kd tree
254        int mHiLiteLevel;
255        // if all bounding boxes shall be displayed, not only the highlighted level
256        bool mShowAllBoxes;
257        // visualize kdtree nodes or bounding boxes of objects in nodes
258        bool mShowNodes;
[1170]259
[1214]260        // vis mode
261        bool mEnhancedVisiblity;
262
[1185]263        // the method/algorithm used when rendering the scene
264        KdTree::RenderMethod mRenderMethod;
265
266        // the method of building the tree
267        KdTree::BuildMethod mBuildMethod;
268};
[1163]269
270
271
[1185]272/// Factory for KdTreeSceneManager
273class KdTreeSceneManagerFactory : public SceneManagerFactory
274{
275protected:
276        void initMetaData(void) const;
277        GtpVisibility::VisibilityManager *visManager;
278public:
279        KdTreeSceneManagerFactory(GtpVisibility::VisibilityManager * vm)
[1163]280        {
[1185]281                visManager = vm;
[1163]282        };
[1185]283        ~KdTreeSceneManagerFactory(void) {};
284        /// Factory type name
285        static const String FACTORY_TYPE_NAME;
286        SceneManager* createInstance(const String& instanceName);
287        void destroyInstance(SceneManager* instance);
288};
[1163]289
290} // namespace Ogre
291
292#endif // _KdTreeSceneManager_H__
Note: See TracBrowser for help on using the repository browser.