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