source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreOcclusionCullingSceneManager.h @ 2145

Revision 2145, 8.8 KB checked in by mattausch, 17 years ago (diff)
Line 
1#ifndef _OcclusionCullingSceneManager_H__
2#define _OcclusionCullingSceneManager_H__
3
4#include <OgreSceneNode.h>
5#include <OgreTerrainSceneManager.h>
6#include <OgreOctreeNode.h>
7#include <OgreOctreeCamera.h>
8#include <OgrePrerequisites.h>
9#include <OgreMovableObject.h>
10#include "OgreOctreeHierarchyInterface.h"
11#include "OgrePlatformQueryManager.h"
12#include "VisibilityManager.h"
13#include "Containers.h"
14#include "ViewCellsManager.h"
15
16
17namespace GtpVisibilityPreprocessor {
18class Intersectable;
19}
20
21class ObjReader;
22
23namespace Ogre {
24
25
26/**
27        This class extends the terrain scene manager,
28        using occlusion queries for visibility culling.
29*/
30class __declspec(dllexport) OcclusionCullingSceneManager: public TerrainSceneManager
31{
32public:
33        OcclusionCullingSceneManager(const String& name,
34                                                                 GtpVisibility::VisibilityManager *visManager);
35        ~OcclusionCullingSceneManager();
36
37        void _renderVisibleObjects();
38        void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
39        void _updateSceneGraph(Camera* cam);
40
41        /** Sets the given option for the SceneManager
42                @remarks Options are: "Algorithm", int *;                       
43        */
44       
45        virtual bool setOption(const String &, const void *);
46        /** Gets the given option for the Scene VisibilityManager.
47            @remarks
48                See setOption
49        */
50        virtual bool getOption(const String &, void *);
51
52        bool getOptionValues(const String & key, StringVector &refValueList);
53        bool getOptionKeys(StringVector &refKeys);
54
55        /** Sets the visibility manager.
56                @param visManager the visibility manager
57        */
58        void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
59        /** See set.
60        */
61        GtpVisibility::VisibilityManager *getVisibilityManager();
62
63        /** Render a queue group.
64                Override so we can handle delayed rendering of transparent objects
65        */
66        void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
67                                                                          QueuedRenderableCollection::OrganisationMode om);
68
69        /** Writes out stats into the Ogre log file.
70        */
71        void WriteLog();
72
73        /** Override pass so we can do the z-fail pass.
74        */
75        virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
76
77        /** Override from SceneManager so we can skip all but first pass for depth pass.
78        */
79        bool validatePassForRendering(Pass* pass);
80
81#ifdef ITEM_BUFFER
82        void RenderItemBuffer(RenderPriorityGroup* pGroup);
83        void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass);
84#endif // ITEM_BUFFER
85
86        void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
87                                                                  QueuedRenderableCollection::OrganisationMode om);
88
89        /** Override from SceneManager so that sub entities can be assigned
90                an id for item buffer.
91        */
92        Entity* createEntity(const String& entityName, const String& meshName);
93
94        /** Returns pointer to visibility manager.
95        */
96        GtpVisibility::VisibilityManager *GetVisibilityManager();
97
98        /** Returns hierarchy interface.
99        */
100        OctreeHierarchyInterface *GetHierarchyInterface();
101
102        /** Inherited from scene manager. Neccesary to draw terrain properly.
103        */
104        void endFrame();
105
106        void renderAdditiveStencilShadowedQueueGroupObjects(
107                                RenderQueueGroup* pGroup,
108                                QueuedRenderableCollection::OrganisationMode om);
109        void renderModulativeStencilShadowedQueueGroupObjects(
110                                RenderQueueGroup* pGroup,
111                                QueuedRenderableCollection::OrganisationMode om);
112       
113        /** Override standard function so octree boxes are always of equal side length.
114                This has advantages for CHC, because terrain tiles are in different octree nodes
115                and can be culled.
116                msz: Modified to reflect changes in Ogre::TerrainSceneManager
117        */
118#if 1
119        virtual void setWorldGeometry(DataStreamPtr& stream, const String& typeName);
120#endif
121       
122        /** Loads view cells for this particular scene.
123        */
124        bool LoadViewCells(const String &filename);
125
126protected:
127       
128        void MailPvsObjects();
129        void RenderPvsEntry(GtpVisibilityPreprocessor::Intersectable *obj);
130        void SetObjectVisible(GtpVisibilityPreprocessor::Intersectable *entry,
131                                                  const bool visible);
132        void ShowViewCellsGeometry();
133
134        /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
135        */
136        void InitDepthPass();
137        /** Creates material for item buffer.
138        */
139        void InitItemBufferPass();
140        /** Fills render queue so that a visualization can be rendered.
141        */
142        void PrepareVisualization(Camera *cam);
143        /** Initialises necessary parameters for hierarchical visibility culling.
144        */
145        void InitVisibilityCulling(Camera *cam);
146        /** Loads / unloads pvs of the view cell to set the visibility in the scene.
147        */
148        void ApplyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
149
150        /** updates pvs in current frame.
151        */
152        void UpdatePvs(Camera *cam);
153
154        /** Sets all objects invisible.
155        */
156        void SetObjectsVisible(const bool visible);
157
158        /** Creates view cells geometry from the loaded view cells.
159        */
160        void CreateViewCellsGeometry();
161        void VisualizeViewCells(const bool visualize);
162
163        /** Load an iv scene.
164        */
165        bool LoadSceneIV(const String &filename,
166                                         SceneNode *root,
167                                         const int index);
168
169        /** Load obj scene.
170        */
171        bool LoadSceneObj(const String &filename,
172                                          const String &viewCellsFile,
173                                          SceneNode *root);
174
175        /** Load a scene.
176        */
177        bool LoadScene(const String &filename, const String &viewCellsFilename);
178
179        void loadConfig(DataStreamPtr& stream);
180
181        //////////////////////////////////////////
182
183        /// the interface to the scene hierarchy.
184        OctreeHierarchyInterface *mHierarchyInterface;
185
186        /// manages all visibility options
187        GtpVisibility::VisibilityManager *mVisibilityManager;
188
189        /// if a visualization of the hierarchical culling is shown
190        bool mShowVisualization;
191
192        /// if the culled nodes are indicated in the visualization
193        bool mVisualizeCulledNodes;
194
195        /// if symbols for the nodes are shown in the visualization
196        bool mRenderNodesForViz;
197        /// if content of the nodes is shown in the visualization
198        bool mRenderNodesContentForViz;
199
200        /// render transparents after the hierarchical traversal
201        bool mDelayRenderTransparents;
202
203        /// use a depth pass (i.e., fill only the depth buffer in the first pass)
204        bool mUseDepthPass;
205        /// flag indicating if we currently render the depth pass
206        bool mIsDepthPassPhase;
207       
208        /// if we use an item buffer for rendering (i.e., object ids as color codes
209        bool mUseItemBuffer;
210        /// if we currently render the item buffer
211        bool mIsItemBufferPhase;
212
213        /// if depth write should be enabled
214        bool mEnableDepthWrite;
215        /// if transparents are skipped during rendering
216        bool mSkipTransparents;
217
218        /// the depth pass (no lighting, just filling the depth buffer)
219        Pass *mDepthPass;
220        /// the pass for item buffer setting a color id
221        Pass *mItemBufferPass;
222
223        /// flag for passes which should not be deleted from queue during first traversal
224        int mLeavePassesInQueue;
225
226        /// if transparent object are considered for item buffer visibility
227        bool mRenderTransparentsForItemBuffer;
228        /// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
229        bool mExecuteVertexProgramForAllPasses;
230
231        /// if hierarchical culling is currently in use
232        bool mIsHierarchicalCulling;
233
234        /// do we use preprocessed visibility
235        bool mViewCellsLoaded;
236
237        /// the view cells manager handling the preprocesor stuff
238        GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
239
240
241        /// Used to assign Ogre meshes to view cell entries.
242        GtpVisibilityPreprocessor::ObjectContainer mObjects;
243
244        GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
245        GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
246
247        /// If view cells are used.
248        bool mUseViewCells;
249
250        /// if view cells visualization should be shown
251        bool mShowViewCells;
252
253        /// if the view cells are filtered
254        bool mUseVisibilityFilter;
255
256        bool mDeleteQueueAfterRendering;
257
258        // normal terrain rendering
259        bool mNormalExecution;
260
261        // helper variable to provide sequential numbering for sub-entities
262        int mCurrentEntityId;
263
264        typedef map<int, MovableObject *> MovableMap;
265
266        /// hash table for view cells geometry
267    MovableMap mViewCellsGeometry;
268
269        bool mViewCellsGeometryLoaded;
270
271        string mViewCellsFilename;
272        string mFilename;
273
274        bool mShowTerrain;
275
276        int mFlushRate;
277        int mCurrentFrame;
278
279        ObjReader *mObjReader;
280};
281
282
283/** Factory for VisibilityOctreeSceneManager.
284*/
285class OcclusionCullingSceneManagerFactory : public SceneManagerFactory
286{
287protected:
288        typedef std::vector<TerrainPageSource*> TerrainPageSources;
289        TerrainPageSources mTerrainPageSources;
290        void initMetaData(void) const;
291        GtpVisibility::VisibilityManager *visManager;
292public:
293        OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
294        {
295                visManager = vm;
296        }
297
298        /// Factory type name
299        static const String FACTORY_TYPE_NAME;
300        SceneManager* createInstance(const String& instanceName);
301        void destroyInstance(SceneManager* instance);
302};
303
304} // namespace Ogre
305
306#endif // OcclusionCullingSceneManager_H
Note: See TracBrowser for help on using the repository browser.