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

Revision 1214, 9.4 KB checked in by szydlowski, 18 years ago (diff)
Line 
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 <OgreKdTreeHierarchyInterface.h>
14#include <OgreSceneManager.h>
15#include <VisibilityManager.h>
16#include "OgreKdTree.h"
17#include "OgreKdTreeCamera.h"
18
19#define KDTREE_MAX_DEPTH 12
20
21namespace Ogre
22{
23
24class KdTreeSceneNode;
25
26class KdTreeSceneManager : public SceneManager
27{
28public:
29        KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm);
30        ~KdTreeSceneManager(void);
31
32        virtual const String& getTypeName(void) const;
33
34        //typedef std::list<KdTreeSceneNode *> NodeList;
35        //typedef std::list<WireBoundingBox *> BoxList;
36
37        /************************************************************************/
38        /* Functions overridden form SceneManager for KdTree                    */
39        /************************************************************************/
40
41        /** Override from Scenemanager to create Camera as instance of KdTreeCamera
42        */
43        virtual Camera* createCamera(const String& name);
44
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);
51
52        /** Override from Scenemanager, employ kd-tree based culling or CHC
53        */
54        virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters);
55
56        virtual bool setOption(const String& strKey, const void* pValue);
57        virtual bool getOption(const String& strKey, void* pDestValue);
58
59        bool getOptionValues(const String & key, StringVector &refValueList);
60        bool getOptionKeys(StringVector &refKeys);
61
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();
69
70                // must happen before actual scene is cleared
71                OGRE_DELETE(mKdTree);
72
73                SceneManager::clearScene();
74        }
75
76        /************************************************************************/
77        /* Functions overridden from SceneManager for CHC                       */
78        /************************************************************************/
79
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);
83
84        /** Override from scene manager to set up culling manager
85        */
86        virtual void _updateSceneGraph(Camera* cam);
87
88        /** Override from SceneManager, employ normal rendering or CHC
89        */
90        virtual void _renderVisibleObjects();
91
92        /** Override pass so we can do the z-fail pass.
93        */
94        const Pass* _setPass(Pass* pass);
95
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);
101
102        /** Override from scene manager
103        */
104        void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
105                QueuedRenderableCollection::OrganisationMode om);
106
107        /** Override from SceneManager so we can skip all but first pass for depth pass.
108        */
109        bool validatePassForRendering(Pass* pass);
110
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);
117
118
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:
126
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;
133
134        /************************************************************************/
135        /* Functions for CHC                                                    */
136        /************************************************************************/
137
138        /** Render a list of scenenodes
139        */
140        //virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam,
141        //      bool onlyShadowCasters, int leavePassesInQueue);
142        virtual void _renderNode(KdTree::NodePtr node, Camera * cam,
143                bool onlyShadowCasters, int leavePassesInQueue);
144
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();
152
153        /** Returns pointer to visibility manager.
154        */
155        GtpVisibility::VisibilityManager *GetVisibilityManager();
156
157        /** Returns hierarchy interface.
158        */
159        KdTreeHierarchyInterface *GetHierarchyInterface();
160
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);
174
175        /** Writes out stats into the Ogre log file.
176        */
177        void WriteLog();
178
179        /** Switches between simple & enhanced visibility
180        */
181        //void setEnhancedVis(bool enhanced);
182
183
184        /************************************************************************/
185        /* CHC-specific options & members                                       */
186        /************************************************************************/
187        // pointer to the visibility manager
188        GtpVisibility::VisibilityManager *mVisibilityManager;
189
190        // the hierarchy interface for CHC
191        KdTreeHierarchyInterface *mHierarchyInterface;
192
193        // if hierarchical culling is currently in use
194        bool mIsHierarchicalCulling;
195
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;
201
202        // consecutive number for sub-entities
203        int mCurrentEntityId;
204
205        // flag for passes which should not be deleted from queue during first traversal
206        int mLeavePassesInQueue;
207
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;
219
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;
230
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;
237
238        // remember visited scene nodes for viz
239        //KdRenderableList mVisibleNodes;
240        KdTree::NodeList mVisibleNodes;
241
242        /************************************************************************/
243        /* Kd-Tree specific options & members                                   */
244        /************************************************************************/
245        // maximum depth of the kdtree
246        int mMaxDepth;
247
248        // the kdtree which holds the scene
249        KdTree *mKdTree;
250
251        // if bounding boxes of kdtree nodes are shown
252        bool mShowBoxes;
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;
259
260        // vis mode
261        bool mEnhancedVisiblity;
262
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};
269
270
271
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)
280        {
281                visManager = vm;
282        };
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};
289
290} // namespace Ogre
291
292#endif // _KdTreeSceneManager_H__
Note: See TracBrowser for help on using the repository browser.