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