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 | /************************************************************************/
|
---|
68 | /* Functions overridden from SceneManager for CHC */
|
---|
69 | /************************************************************************/
|
---|
70 |
|
---|
71 | /** Override from SceneManager so that sub entities can be assigned an id for item buffer.
|
---|
72 | */
|
---|
73 | Entity* createEntity(const String& entityName, const String& meshName);
|
---|
74 |
|
---|
75 | /** Override from scene manager to set up culling manager
|
---|
76 | */
|
---|
77 | virtual void _updateSceneGraph(Camera* cam);
|
---|
78 |
|
---|
79 | /** Override from SceneManager, employ normal rendering or CHC
|
---|
80 | */
|
---|
81 | virtual void _renderVisibleObjects();
|
---|
82 |
|
---|
83 | /** Override pass so we can do the z-fail pass.
|
---|
84 | */
|
---|
85 | virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
|
---|
86 |
|
---|
87 | /** Render a queue group.
|
---|
88 | Override so we can handle delayed rendering of transparent objects
|
---|
89 | */
|
---|
90 | void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
91 | QueuedRenderableCollection::OrganisationMode om);
|
---|
92 |
|
---|
93 | /** Override from scene manager
|
---|
94 | */
|
---|
95 | void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
96 | QueuedRenderableCollection::OrganisationMode om);
|
---|
97 |
|
---|
98 | /** Override from SceneManager so we can skip all but first pass for depth pass.
|
---|
99 | */
|
---|
100 | bool validatePassForRendering(Pass* pass);
|
---|
101 |
|
---|
102 | /** Override from SceneManager because idontknow
|
---|
103 | */
|
---|
104 | void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
105 | QueuedRenderableCollection::OrganisationMode om);
|
---|
106 | void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
107 | QueuedRenderableCollection::OrganisationMode om);
|
---|
108 |
|
---|
109 |
|
---|
110 | /************************************************************************/
|
---|
111 | /* Functions which are specific to the KdTree */
|
---|
112 | /************************************************************************/
|
---|
113 |
|
---|
114 | /** Update the KdTree with the node (more or less disabled now)
|
---|
115 | */
|
---|
116 | virtual void _updateNode(KdTreeSceneNode *node); // TODO:
|
---|
117 |
|
---|
118 | /** Show or hide the bounding boxes of KdTree nodes - obsolete, use options
|
---|
119 | */
|
---|
120 | virtual void setShowBoxes(bool showboxes);
|
---|
121 | /** Tell if show boxes is enabled - obsolete, use options
|
---|
122 | */
|
---|
123 | virtual bool getShowBoxes(void) const;
|
---|
124 |
|
---|
125 | /************************************************************************/
|
---|
126 | /* Functions for CHC */
|
---|
127 | /************************************************************************/
|
---|
128 |
|
---|
129 | /** Render a list of scenenodes
|
---|
130 | */
|
---|
131 | //virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam,
|
---|
132 | // bool onlyShadowCasters, int leavePassesInQueue);
|
---|
133 | virtual void _renderNode(KdTree::NodePtr node, Camera * cam,
|
---|
134 | bool onlyShadowCasters, int leavePassesInQueue);
|
---|
135 |
|
---|
136 | /** Sets the visibility manager.
|
---|
137 | @param visManager the visibility manager
|
---|
138 | */
|
---|
139 | void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
|
---|
140 | /** See set.
|
---|
141 | */
|
---|
142 | GtpVisibility::VisibilityManager *getVisibilityManager();
|
---|
143 |
|
---|
144 | /** Returns pointer to visibility manager.
|
---|
145 | */
|
---|
146 | GtpVisibility::VisibilityManager *GetVisibilityManager();
|
---|
147 |
|
---|
148 | /** Returns hierarchy interface.
|
---|
149 | */
|
---|
150 | KdTreeHierarchyInterface *GetHierarchyInterface();
|
---|
151 |
|
---|
152 | protected:
|
---|
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 | /** Switches between simple & enhanced visibility
|
---|
171 | */
|
---|
172 | //void setEnhancedVis(bool enhanced);
|
---|
173 |
|
---|
174 |
|
---|
175 | /************************************************************************/
|
---|
176 | /* CHC-specific options & members */
|
---|
177 | /************************************************************************/
|
---|
178 | // pointer to the visibility manager
|
---|
179 | GtpVisibility::VisibilityManager *mVisibilityManager;
|
---|
180 |
|
---|
181 | // the hierarchy interface for CHC
|
---|
182 | KdTreeHierarchyInterface *mHierarchyInterface;
|
---|
183 |
|
---|
184 | // if hierarchical culling is currently in use
|
---|
185 | bool mIsHierarchicalCulling;
|
---|
186 |
|
---|
187 | // if a visualization of the hierarchical culling is shown
|
---|
188 | bool mShowVisualization;
|
---|
189 |
|
---|
190 | // if the culled nodes are indicated in the visualization
|
---|
191 | bool mVisualizeCulledNodes;
|
---|
192 |
|
---|
193 | // consecutive number for sub-entities
|
---|
194 | int mCurrentEntityId;
|
---|
195 |
|
---|
196 | // flag for passes which should not be deleted from queue during first traversal
|
---|
197 | int mLeavePassesInQueue;
|
---|
198 |
|
---|
199 | // if symbols for the nodes are shown in the visualization
|
---|
200 | bool mRenderNodesForViz;
|
---|
201 | // if content of the nodes is shown in the visualization
|
---|
202 | bool mRenderNodesContentForViz;
|
---|
203 | /// render transparents after the hierarchical traversal
|
---|
204 | bool mDelayRenderTransparents;
|
---|
205 |
|
---|
206 | // if transparent object are considered for item buffer visibility
|
---|
207 | bool mRenderTransparentsForItemBuffer;
|
---|
208 | // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
|
---|
209 | bool mExecuteVertexProgramForAllPasses;
|
---|
210 |
|
---|
211 | // the depth pass (no lighting, just filling the depth buffer)
|
---|
212 | Pass *mDepthPass;
|
---|
213 | // use a depth pass (i.e., fill only the depth buffer in the first pass)
|
---|
214 | bool mUseDepthPass;
|
---|
215 | // flag indicating if we currently render the depth pass
|
---|
216 | bool mIsDepthPassPhase;
|
---|
217 | // if depth write should be enabled
|
---|
218 | bool mEnableDepthWrite;
|
---|
219 | // if transparents are skipped during rendering
|
---|
220 | bool mSkipTransparents;
|
---|
221 | // the item buffer pass (render items color-coded)
|
---|
222 | Pass *mItemBufferPass;
|
---|
223 | // if we use an item buffer for rendering (i.e., object ids as color codes
|
---|
224 | bool mUseItemBuffer;
|
---|
225 | // if we currently render the item buffer
|
---|
226 | bool mIsItemBufferPhase;
|
---|
227 |
|
---|
228 | // remember visited scene nodes for viz
|
---|
229 | //KdRenderableList mVisibleNodes;
|
---|
230 | KdTree::NodeList mVisibleNodes;
|
---|
231 |
|
---|
232 | bool mDeleteQueueAfterRendering;
|
---|
233 |
|
---|
234 | /************************************************************************/
|
---|
235 | /* Kd-Tree specific options & members */
|
---|
236 | /************************************************************************/
|
---|
237 | // maximum depth of the kdtree
|
---|
238 | int mMaxDepth;
|
---|
239 |
|
---|
240 | // the kdtree which holds the scene
|
---|
241 | KdTree *mKdTree;
|
---|
242 |
|
---|
243 | // if bounding boxes of kdtree nodes are shown
|
---|
244 | bool mShowBoxes;
|
---|
245 | // bounding boxes of kd nodes will be highlighted on this level of the kd tree
|
---|
246 | int mHiLiteLevel;
|
---|
247 | // if all bounding boxes shall be displayed, not only the highlighted level
|
---|
248 | bool mShowAllBoxes;
|
---|
249 | // visualize kdtree nodes or bounding boxes of objects in nodes
|
---|
250 | bool mShowNodes;
|
---|
251 |
|
---|
252 | // vis mode
|
---|
253 | bool mEnhancedVisiblity;
|
---|
254 |
|
---|
255 | // the method/algorithm used when rendering the scene
|
---|
256 | KdTree::RenderMethod mRenderMethod;
|
---|
257 |
|
---|
258 | // the method of building the tree
|
---|
259 | KdTree::BuildMethod mBuildMethod;
|
---|
260 | };
|
---|
261 |
|
---|
262 |
|
---|
263 |
|
---|
264 | /// Factory for KdTreeSceneManager
|
---|
265 | class KdTreeSceneManagerFactory : public SceneManagerFactory
|
---|
266 | {
|
---|
267 | protected:
|
---|
268 | void initMetaData(void) const;
|
---|
269 | GtpVisibility::VisibilityManager *visManager;
|
---|
270 | public:
|
---|
271 | KdTreeSceneManagerFactory(GtpVisibility::VisibilityManager * vm)
|
---|
272 | {
|
---|
273 | visManager = vm;
|
---|
274 | };
|
---|
275 | ~KdTreeSceneManagerFactory(void) {};
|
---|
276 | /// Factory type name
|
---|
277 | static const String FACTORY_TYPE_NAME;
|
---|
278 | SceneManager* createInstance(const String& instanceName);
|
---|
279 | void destroyInstance(SceneManager* instance);
|
---|
280 | };
|
---|
281 |
|
---|
282 | } // namespace Ogre
|
---|
283 |
|
---|
284 | #endif // _KdTreeSceneManager_H__ |
---|