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 _BiHierarchySceneManager_H__
|
---|
11 | #define _BiHierarchySceneManager_H__
|
---|
12 |
|
---|
13 | #include <OgreSceneManager.h>
|
---|
14 | #include <VisibilityManager.h>
|
---|
15 | #include <ViewCellsManager.h>
|
---|
16 |
|
---|
17 | #include "OgreBiHierarchy.h"
|
---|
18 | #include "OgreBiHierarchyCamera.h"
|
---|
19 | #include "OgreBiHierarchyInterface.h"
|
---|
20 |
|
---|
21 | #define BiHierarchy_MAX_DEPTH 12
|
---|
22 |
|
---|
23 | namespace Ogre
|
---|
24 | {
|
---|
25 |
|
---|
26 | class BiHierarchySceneNode;
|
---|
27 |
|
---|
28 | class BiHierarchySceneManager : public SceneManager
|
---|
29 | {
|
---|
30 | public:
|
---|
31 | BiHierarchySceneManager(const String& name, GtpVisibility::VisibilityManager *vm);
|
---|
32 | ~BiHierarchySceneManager(void);
|
---|
33 |
|
---|
34 | virtual const String& getTypeName(void) const;
|
---|
35 |
|
---|
36 | //typedef std::list<BiHierarchySceneNode *> NodeList;
|
---|
37 | //typedef std::list<WireBoundingBox *> BoxList;
|
---|
38 |
|
---|
39 | /************************************************************************/
|
---|
40 | /* Functions overridden form SceneManager for BiHierarchy */
|
---|
41 | /************************************************************************/
|
---|
42 |
|
---|
43 | /** Override from Scenemanager to create Camera as instance of BiHierarchyCamera
|
---|
44 | */
|
---|
45 | virtual Camera* createCamera(const String& name);
|
---|
46 |
|
---|
47 | /** Override from SceneManager to create SceneNodes as instance of BiHierarchySceneNode
|
---|
48 | */
|
---|
49 | virtual SceneNode* createSceneNode(void);
|
---|
50 | /** Override from SceneManager to create SceneNodes as instance of BiHierarchySceneNode
|
---|
51 | */
|
---|
52 | virtual SceneNode* createSceneNode(const String& name);
|
---|
53 |
|
---|
54 | /** Override from Scenemanager, employ kd-tree based culling or CHC
|
---|
55 | */
|
---|
56 | virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters);
|
---|
57 |
|
---|
58 | virtual bool setOption(const String& strKey, const void* pValue);
|
---|
59 | virtual bool getOption(const String& strKey, void* pDestValue);
|
---|
60 |
|
---|
61 | bool getOptionValues(const String & key, StringVector &refValueList);
|
---|
62 | bool getOptionKeys(StringVector &refKeys);
|
---|
63 |
|
---|
64 | /** Overide from scene manager to destroy BiHierarchy properly (before the scene graph is destroyed)
|
---|
65 | */
|
---|
66 | virtual void clearScene();
|
---|
67 |
|
---|
68 | /************************************************************************/
|
---|
69 | /* Functions overridden from SceneManager for CHC */
|
---|
70 | /************************************************************************/
|
---|
71 |
|
---|
72 | /** Override from SceneManager so that sub entities can be assigned an id for item buffer.
|
---|
73 | */
|
---|
74 | Entity* createEntity(const String& entityName, const String& meshName);
|
---|
75 |
|
---|
76 | /** Override from scene manager to set up culling manager
|
---|
77 | */
|
---|
78 | virtual void _updateSceneGraph(Camera* cam);
|
---|
79 |
|
---|
80 | /** Override from SceneManager, employ normal rendering or CHC
|
---|
81 | */
|
---|
82 | virtual void _renderVisibleObjects();
|
---|
83 |
|
---|
84 | /** Override pass so we can do the z-fail pass.
|
---|
85 | */
|
---|
86 | virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
|
---|
87 |
|
---|
88 | /** Render a queue group.
|
---|
89 | Override so we can handle delayed rendering of transparent objects
|
---|
90 | */
|
---|
91 | void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
92 | QueuedRenderableCollection::OrganisationMode om);
|
---|
93 |
|
---|
94 | /** Override from scene manager
|
---|
95 | */
|
---|
96 | void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
97 | QueuedRenderableCollection::OrganisationMode om);
|
---|
98 |
|
---|
99 | /** Override from SceneManager so we can skip all but first pass for depth pass.
|
---|
100 | */
|
---|
101 | bool validatePassForRendering(Pass* pass);
|
---|
102 |
|
---|
103 | /** Override from SceneManager because idontknow
|
---|
104 | */
|
---|
105 | void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
106 | QueuedRenderableCollection::OrganisationMode om);
|
---|
107 | void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
108 | QueuedRenderableCollection::OrganisationMode om);
|
---|
109 |
|
---|
110 |
|
---|
111 | /************************************************************************/
|
---|
112 | /* Functions which are specific to the BiHierarchy */
|
---|
113 | /************************************************************************/
|
---|
114 |
|
---|
115 | /** Update the BiHierarchy with the node (more or less disabled now)
|
---|
116 | */
|
---|
117 | virtual void _updateNode(BiHierarchySceneNode *node); // TODO:
|
---|
118 |
|
---|
119 | /** Show or hide the bounding boxes of BiHierarchy nodes - obsolete, use options
|
---|
120 | */
|
---|
121 | virtual void setShowBoxes(bool showboxes);
|
---|
122 | /** Tell if show boxes is enabled - obsolete, use options
|
---|
123 | */
|
---|
124 | virtual bool getShowBoxes(void) const;
|
---|
125 |
|
---|
126 | /** Recurses the BiHierarchy, adding any nodes intersecting with the
|
---|
127 | box/sphere/volume/ray into the given list.
|
---|
128 | It ignores the exclude scene node.
|
---|
129 | */
|
---|
130 | void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 )
|
---|
131 | {
|
---|
132 | if (mBiHierarchy)
|
---|
133 | mBiHierarchy->findNodesIn(box, list, exclude);
|
---|
134 | }
|
---|
135 | void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 )
|
---|
136 | {
|
---|
137 | if (mBiHierarchy)
|
---|
138 | mBiHierarchy->findNodesIn(sphere, list, exclude);
|
---|
139 | }
|
---|
140 | void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 )
|
---|
141 | {
|
---|
142 | if (mBiHierarchy)
|
---|
143 | mBiHierarchy->findNodesIn(volume, list, exclude);
|
---|
144 | }
|
---|
145 | void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 )
|
---|
146 | {
|
---|
147 | if (mBiHierarchy)
|
---|
148 | mBiHierarchy->findNodesIn(ray, list, exclude);
|
---|
149 | }
|
---|
150 |
|
---|
151 | /************************************************************************/
|
---|
152 | /* Functions for PVS */
|
---|
153 | /************************************************************************/
|
---|
154 | /** Loads view cells for this particular scene.
|
---|
155 | */
|
---|
156 | bool LoadViewCells(const String &filename);
|
---|
157 |
|
---|
158 | /************************************************************************/
|
---|
159 | /* Functions for CHC */
|
---|
160 | /************************************************************************/
|
---|
161 |
|
---|
162 | /** Render a list of scenenodes
|
---|
163 | */
|
---|
164 | //virtual void _renderNodes(const BihRenderableList& nodelist, Camera * cam,
|
---|
165 | // bool onlyShadowCasters, int leavePassesInQueue);
|
---|
166 | virtual void _renderNode(BiHierarchy::NodePtr node, Camera * cam,
|
---|
167 | bool onlyShadowCasters, int leavePassesInQueue);
|
---|
168 |
|
---|
169 | /** Sets the visibility manager.
|
---|
170 | @param visManager the visibility manager
|
---|
171 | */
|
---|
172 | void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
|
---|
173 | /** See set.
|
---|
174 | */
|
---|
175 | GtpVisibility::VisibilityManager *getVisibilityManager();
|
---|
176 |
|
---|
177 | /** Returns pointer to visibility manager.
|
---|
178 | */
|
---|
179 | GtpVisibility::VisibilityManager *GetVisibilityManager();
|
---|
180 |
|
---|
181 | /** Returns hierarchy interface.
|
---|
182 | */
|
---|
183 | BiHierarchyInterface *GetHierarchyInterface();
|
---|
184 |
|
---|
185 | protected:
|
---|
186 | /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
|
---|
187 | */
|
---|
188 | void InitDepthPass();
|
---|
189 | /** Creates material for item buffer.
|
---|
190 | */
|
---|
191 | void InitItemBufferPass();
|
---|
192 | /** Fills render queue so that a visualization can be rendered.
|
---|
193 | */
|
---|
194 | void PrepareVisualization(Camera *cam);
|
---|
195 | /** Initialises necessary parameters for hierarchical visibility culling.
|
---|
196 | */
|
---|
197 | void InitVisibilityCulling(Camera *cam);
|
---|
198 |
|
---|
199 | /** Writes out stats into the Ogre log file.
|
---|
200 | */
|
---|
201 | void WriteLog();
|
---|
202 |
|
---|
203 | /************************************************************************/
|
---|
204 | /* Functions for PVS */
|
---|
205 | /************************************************************************/
|
---|
206 | /** Loads / unloads pvs of the view cell to set the visibility in the scene.
|
---|
207 | */
|
---|
208 | void applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
|
---|
209 |
|
---|
210 | /** updates pvs in current frame.
|
---|
211 | */
|
---|
212 | void updatePvs(Camera *cam);
|
---|
213 |
|
---|
214 | /** Sets all objects invisible.
|
---|
215 | */
|
---|
216 | void SetObjectsVisible(const bool visible);
|
---|
217 |
|
---|
218 | /************************************************************************/
|
---|
219 | /* CHC-specific options & members */
|
---|
220 | /************************************************************************/
|
---|
221 | // pointer to the visibility manager
|
---|
222 | GtpVisibility::VisibilityManager *mVisibilityManager;
|
---|
223 |
|
---|
224 | // the hierarchy interface for CHC
|
---|
225 | BiHierarchyInterface *mHierarchyInterface;
|
---|
226 |
|
---|
227 | // if hierarchical culling is currently in use
|
---|
228 | bool mIsHierarchicalCulling;
|
---|
229 |
|
---|
230 | // if a visualization of the hierarchical culling is shown
|
---|
231 | bool mShowVisualization;
|
---|
232 |
|
---|
233 | // if the culled nodes are indicated in the visualization
|
---|
234 | bool mVisualizeCulledNodes;
|
---|
235 |
|
---|
236 | // consecutive number for sub-entities
|
---|
237 | int mCurrentEntityId;
|
---|
238 |
|
---|
239 | // flag for passes which should not be deleted from queue during first traversal
|
---|
240 | int mLeavePassesInQueue;
|
---|
241 |
|
---|
242 | // if symbols for the nodes are shown in the visualization
|
---|
243 | bool mRenderNodesForViz;
|
---|
244 | // if content of the nodes is shown in the visualization
|
---|
245 | bool mRenderNodesContentForViz;
|
---|
246 | /// render transparents after the hierarchical traversal
|
---|
247 | bool mDelayRenderTransparents;
|
---|
248 |
|
---|
249 | // if transparent object are considered for item buffer visibility
|
---|
250 | bool mRenderTransparentsForItemBuffer;
|
---|
251 | // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
|
---|
252 | bool mExecuteVertexProgramForAllPasses;
|
---|
253 |
|
---|
254 | // the depth pass (no lighting, just filling the depth buffer)
|
---|
255 | Pass *mDepthPass;
|
---|
256 | // use a depth pass (i.e., fill only the depth buffer in the first pass)
|
---|
257 | bool mUseDepthPass;
|
---|
258 | // flag indicating if we currently render the depth pass
|
---|
259 | bool mIsDepthPassPhase;
|
---|
260 | // if depth write should be enabled
|
---|
261 | bool mEnableDepthWrite;
|
---|
262 | // if transparents are skipped during rendering
|
---|
263 | bool mSkipTransparents;
|
---|
264 | // the item buffer pass (render items color-coded)
|
---|
265 | Pass *mItemBufferPass;
|
---|
266 | // if we use an item buffer for rendering (i.e., object ids as color codes
|
---|
267 | bool mUseItemBuffer;
|
---|
268 | // if we currently render the item buffer
|
---|
269 | bool mIsItemBufferPhase;
|
---|
270 | // delete or clear the renderqueue after each rame?
|
---|
271 | bool mDeleteQueueAfterRendering;
|
---|
272 |
|
---|
273 | // remember visited scene nodes for viz
|
---|
274 | BiHierarchy::NodeList mVisibleNodes;
|
---|
275 |
|
---|
276 |
|
---|
277 | /************************************************************************/
|
---|
278 | /* Bih specific options & members */
|
---|
279 | /************************************************************************/
|
---|
280 |
|
---|
281 |
|
---|
282 | // maximum depth of the BiHierarchy
|
---|
283 | int mMaxDepth;
|
---|
284 |
|
---|
285 | // the BiHierarchy which holds the scene
|
---|
286 | BiHierarchy *mBiHierarchy;
|
---|
287 |
|
---|
288 | // if bounding boxes of BiHierarchy nodes are shown
|
---|
289 | bool mShowBoxes;
|
---|
290 | // bounding boxes of kd nodes will be highlighted on this level of the kd tree
|
---|
291 | int mHiLiteLevel;
|
---|
292 | // if all bounding boxes shall be displayed, not only the highlighted level
|
---|
293 | bool mShowAllBoxes;
|
---|
294 | // visualize BiHierarchy nodes or bounding boxes of objects in nodes
|
---|
295 | bool mShowNodes;
|
---|
296 |
|
---|
297 | // vis mode
|
---|
298 | bool mEnhancedVisiblity;
|
---|
299 |
|
---|
300 | // the method/algorithm used when rendering the scene
|
---|
301 | BiHierarchy::RenderMethod mRenderMethod;
|
---|
302 |
|
---|
303 | // the method of building the tree
|
---|
304 | BiHierarchy::BuildMethod mBuildMethod;
|
---|
305 |
|
---|
306 | /************************************************************************/
|
---|
307 | /* PVS specific options and members */
|
---|
308 | /************************************************************************/
|
---|
309 |
|
---|
310 | // The view cell manager
|
---|
311 | GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
|
---|
312 |
|
---|
313 | /// Used to assign Ogre meshes to view cell entries.
|
---|
314 | GtpVisibilityPreprocessor::ObjectContainer mObjects;
|
---|
315 |
|
---|
316 | GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
|
---|
317 | GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
|
---|
318 |
|
---|
319 | /// If view cells are loaded.
|
---|
320 | bool mViewCellsLoaded;
|
---|
321 |
|
---|
322 | /// If view cells are used.
|
---|
323 | bool mUseViewCells;
|
---|
324 |
|
---|
325 | /// if the view cells are filtered
|
---|
326 | bool mUseVisibilityFilter;
|
---|
327 | };
|
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 | /// Factory for BiHierarchySceneManager
|
---|
332 | class BiHierarchySceneManagerFactory: public SceneManagerFactory
|
---|
333 | {
|
---|
334 | protected:
|
---|
335 | void initMetaData(void) const;
|
---|
336 | GtpVisibility::VisibilityManager *visManager;
|
---|
337 | public:
|
---|
338 | BiHierarchySceneManagerFactory(GtpVisibility::VisibilityManager * vm)
|
---|
339 | {
|
---|
340 | visManager = vm;
|
---|
341 | }
|
---|
342 | ~BiHierarchySceneManagerFactory(void) {};
|
---|
343 | /// Factory type name
|
---|
344 | static const String FACTORY_TYPE_NAME;
|
---|
345 | SceneManager* createInstance(const String& instanceName);
|
---|
346 | void destroyInstance(SceneManager* instance);
|
---|
347 | };
|
---|
348 |
|
---|
349 | } // namespace Ogre
|
---|
350 |
|
---|
351 | #endif // _BiHierarchySceneManager_H__ |
---|