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

Revision 1182, 9.0 KB checked in by szydlowski, 18 years ago (diff)

all functions for CHC implemented in KdTreeSceneManager?, however CHC not working yet, many issues to resolve

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