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

Revision 1296, 11.7 KB checked in by szydlowski, 18 years ago (diff)

Implemented PVS support in kdtree scene manager - not complete, defunct
modified BoundingBoxConverter? to work with KdTreeSceneManager?

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
13#include <OgreSceneManager.h>
[1175]14#include <VisibilityManager.h>
[1296]15#include <ViewCellsManager.h>
[1258]16
[1163]17#include "OgreKdTree.h"
[1206]18#include "OgreKdTreeCamera.h"
[1258]19#include "OgreKdTreeHierarchyInterface.h"
[1163]20
[1187]21#define KDTREE_MAX_DEPTH 12
[1165]22
[1163]23namespace Ogre
24{
25
[1185]26class KdTreeSceneNode;
[1163]27
[1185]28class KdTreeSceneManager : public SceneManager
29{
30public:
31        KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm);
32        ~KdTreeSceneManager(void);
[1175]33
[1185]34        virtual const String& getTypeName(void) const;
[1182]35
[1185]36        //typedef std::list<KdTreeSceneNode *> NodeList;
37        //typedef std::list<WireBoundingBox *> BoxList;
[1182]38
[1185]39        /************************************************************************/
40        /* Functions overridden form SceneManager for KdTree                    */
41        /************************************************************************/
[1177]42
[1206]43        /** Override from Scenemanager to create Camera as instance of KdTreeCamera
44        */
45        virtual Camera* createCamera(const String& name);
46
[1185]47        /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode
48        */
49        virtual SceneNode* createSceneNode(void);
50        /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode
51        */
52        virtual SceneNode* createSceneNode(const String& name);
[1182]53
[1185]54        /** Override from Scenemanager, employ kd-tree based culling or CHC
55        */
56        virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters);
[1182]57
[1185]58        virtual bool setOption(const String& strKey, const void* pValue);
59        virtual bool getOption(const String& strKey, void* pDestValue);
[1182]60
[1185]61        bool getOptionValues(const String & key, StringVector &refValueList);
62        bool getOptionKeys(StringVector &refKeys);
[1182]63
[1185]64        /** Overide from scene manager to destroy kdtree properly (before the scene graph is destroyed)
65        */
[1285]66        virtual void clearScene();
[1182]67
[1185]68        /************************************************************************/
69        /* Functions overridden from SceneManager for CHC                       */
70        /************************************************************************/
[1163]71
[1185]72        /** Override from SceneManager so that sub entities can be assigned an id for item buffer.
73        */
74        Entity* createEntity(const String& entityName, const String& meshName);
[1182]75
[1185]76        /** Override from scene manager to set up culling manager
77        */
78        virtual void _updateSceneGraph(Camera* cam);
[1182]79
[1185]80        /** Override from SceneManager, employ normal rendering or CHC
81        */
82        virtual void _renderVisibleObjects();
[1182]83
[1185]84        /** Override pass so we can do the z-fail pass.
85        */
[1221]86        virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
[1182]87
[1185]88        /** Render a queue group.
89        Override so we can handle delayed rendering of transparent objects
90        */
91        void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
92                QueuedRenderableCollection::OrganisationMode om);
[1182]93
[1185]94        /** Override from scene manager
95        */
96        void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
97                QueuedRenderableCollection::OrganisationMode om);
[1182]98
[1185]99        /** Override from SceneManager so we can skip all but first pass for depth pass.
100        */
101        bool validatePassForRendering(Pass* pass);
[1182]102
[1185]103        /** Override from SceneManager because idontknow
104        */
105        void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
106                QueuedRenderableCollection::OrganisationMode om);
107        void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
108                QueuedRenderableCollection::OrganisationMode om);
[1182]109
[1175]110
[1185]111        /************************************************************************/
112        /* Functions which are specific to the KdTree                           */
113        /************************************************************************/
114       
115        /** Update the KdTree with the node (more or less disabled now)
116        */
117        virtual void _updateNode(KdTreeSceneNode *node); // TODO:
[1163]118
[1185]119        /** Show or hide the bounding boxes of KdTree nodes - obsolete, use options
120        */
121        virtual void setShowBoxes(bool showboxes);
122        /** Tell if show boxes is enabled - obsolete, use options
123        */
124        virtual bool getShowBoxes(void) const;
[1182]125
[1296]126        /** Recurses the kdtree, adding any nodes intersecting with the
127        box/sphere/volume/ray into the given list.
128        It ignores the exclude scene node.
129        */
130        void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 )
131        {
132                if (mKdTree)
133                        mKdTree->findNodesIn(box, list, exclude);
134        }
135        void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 )
136        {
137                if (mKdTree)
138                        mKdTree->findNodesIn(sphere, list, exclude);
139        }
140        void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 )
141        {
142                if (mKdTree)
143                        mKdTree->findNodesIn(volume, list, exclude);
144        }
145        void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 )
146        {
147                if (mKdTree)
148                        mKdTree->findNodesIn(ray, list, exclude);
149        }
150
[1185]151        /************************************************************************/
[1296]152        /* Functions for PVS                                                    */
153        /************************************************************************/
154        /** Loads view cells for this particular scene.
155        */
156        bool LoadViewCells(const String &filename);
157
158        /************************************************************************/
[1185]159        /* Functions for CHC                                                    */
160        /************************************************************************/
[1173]161
[1185]162        /** Render a list of scenenodes
163        */
[1187]164        //virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam,
165        //      bool onlyShadowCasters, int leavePassesInQueue);
166        virtual void _renderNode(KdTree::NodePtr node, Camera * cam,
[1185]167                bool onlyShadowCasters, int leavePassesInQueue);
[1175]168
[1185]169        /** Sets the visibility manager.
170        @param visManager the visibility manager
171        */
172        void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
173        /** See set.
174        */
175        GtpVisibility::VisibilityManager *getVisibilityManager();
[1175]176
[1185]177        /** Returns pointer to visibility manager.
178        */
179        GtpVisibility::VisibilityManager *GetVisibilityManager();
[1175]180
[1185]181        /** Returns hierarchy interface.
182        */
183        KdTreeHierarchyInterface *GetHierarchyInterface();
[1175]184
[1185]185protected:
186        /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
187        */
188        void InitDepthPass();
189        /** Creates material for item buffer.
190        */
191        void InitItemBufferPass();
192        /** Fills render queue so that a visualization can be rendered.
193        */
194        void PrepareVisualization(Camera *cam);
195        /** Initialises necessary parameters for hierarchical visibility culling.
196        */
197        void InitVisibilityCulling(Camera *cam);
[1175]198
[1185]199        /** Writes out stats into the Ogre log file.
200        */
201        void WriteLog();
[1175]202
[1296]203        /************************************************************************/
204        /* Functions for PVS                                                    */
205        /************************************************************************/
206        /** Loads / unloads pvs of the view cell to set the visibility in the scene.
[1206]207        */
[1296]208        void applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
[1175]209
[1296]210        /** updates pvs in current frame.
211        */
212        void updatePvs(Camera *cam);
[1206]213
[1296]214        /** Sets all objects invisible.
215        */
216        void SetObjectsVisible(const bool visible);
217
[1185]218        /************************************************************************/
219        /* CHC-specific options & members                                       */
220        /************************************************************************/
221        // pointer to the visibility manager
222        GtpVisibility::VisibilityManager *mVisibilityManager;
[1163]223
[1185]224        // the hierarchy interface for CHC
225        KdTreeHierarchyInterface *mHierarchyInterface;
[1165]226
[1185]227        // if hierarchical culling is currently in use
228        bool mIsHierarchicalCulling;
[1182]229
[1185]230        // if a visualization of the hierarchical culling is shown
231        bool mShowVisualization;
232       
233        // if the culled nodes are indicated in the visualization
234        bool mVisualizeCulledNodes;
[1182]235
[1185]236        // consecutive number for sub-entities
237        int mCurrentEntityId;
[1175]238
[1185]239        // flag for passes which should not be deleted from queue during first traversal
240        int mLeavePassesInQueue;
[1182]241
[1185]242        // if symbols for the nodes are shown in the visualization
243        bool mRenderNodesForViz;
244        // if content of the nodes is shown in the visualization
245        bool mRenderNodesContentForViz;
246        /// render transparents after the hierarchical traversal
247        bool mDelayRenderTransparents;
248       
249        // if transparent object are considered for item buffer visibility
250        bool mRenderTransparentsForItemBuffer;
251        // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
252        bool mExecuteVertexProgramForAllPasses;
[1182]253
[1185]254        // the depth pass (no lighting, just filling the depth buffer)
255        Pass *mDepthPass;
256        // use a depth pass (i.e., fill only the depth buffer in the first pass)
257        bool mUseDepthPass;
258        // flag indicating if we currently render the depth pass
259        bool mIsDepthPassPhase;
260        // if depth write should be enabled
261        bool mEnableDepthWrite;
262        // if transparents are skipped during rendering
263        bool mSkipTransparents;
264        // the item buffer pass (render items color-coded)
265        Pass *mItemBufferPass;
266        // if we use an item buffer for rendering (i.e., object ids as color codes
267        bool mUseItemBuffer;
268        // if we currently render the item buffer
269        bool mIsItemBufferPhase;
[1296]270        // delete or clear the renderqueue after each rame?
271        bool mDeleteQueueAfterRendering;
[1182]272
[1296]273
[1185]274        // remember visited scene nodes for viz
[1187]275        KdTree::NodeList mVisibleNodes;
[1163]276
[1185]277        /************************************************************************/
278        /* Kd-Tree specific options & members                                   */
279        /************************************************************************/
280        // maximum depth of the kdtree
281        int mMaxDepth;
[1163]282
[1185]283        // the kdtree which holds the scene
284        KdTree *mKdTree;
[1163]285
[1185]286        // if bounding boxes of kdtree nodes are shown
287        bool mShowBoxes;
[1192]288        // bounding boxes of kd nodes will be highlighted on this level of the kd tree
289        int mHiLiteLevel;
290        // if all bounding boxes shall be displayed, not only the highlighted level
291        bool mShowAllBoxes;
292        // visualize kdtree nodes or bounding boxes of objects in nodes
293        bool mShowNodes;
[1170]294
[1214]295        // vis mode
296        bool mEnhancedVisiblity;
297
[1185]298        // the method/algorithm used when rendering the scene
299        KdTree::RenderMethod mRenderMethod;
300
301        // the method of building the tree
302        KdTree::BuildMethod mBuildMethod;
[1296]303
304        /************************************************************************/
305        /* PVS specific options and members                                     */
306        /************************************************************************/
307
308        // The view cell manager
309        GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
310
311        /// Used to assign Ogre meshes to view cell entries.
312        GtpVisibilityPreprocessor::ObjectContainer mObjects;
313
314        GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
315        GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
316
317        /// If view cells are loaded.
318        bool mViewCellsLoaded;
319
320        /// If view cells are used.
321        bool mUseViewCells;
322
323        /// if the view cells are filtered
324        bool mUseVisibilityFilter;
[1185]325};
[1163]326
327
328
[1185]329/// Factory for KdTreeSceneManager
330class KdTreeSceneManagerFactory : public SceneManagerFactory
331{
332protected:
333        void initMetaData(void) const;
334        GtpVisibility::VisibilityManager *visManager;
335public:
336        KdTreeSceneManagerFactory(GtpVisibility::VisibilityManager * vm)
[1163]337        {
[1185]338                visManager = vm;
[1163]339        };
[1185]340        ~KdTreeSceneManagerFactory(void) {};
341        /// Factory type name
342        static const String FACTORY_TYPE_NAME;
343        SceneManager* createInstance(const String& instanceName);
344        void destroyInstance(SceneManager* instance);
345};
[1163]346
347} // namespace Ogre
348
349#endif // _KdTreeSceneManager_H__
Note: See TracBrowser for help on using the repository browser.