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

Revision 2171, 9.1 KB checked in by mattausch, 17 years ago (diff)

implemented function for exact visibility queries

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 myFindVisibleObjects(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
126        void RenderDepthForQuery(Camera* camera, Viewport* vp);
127
128protected:
129       
130        void MailPvsObjects();
131        void RenderPvsEntry(GtpVisibilityPreprocessor::Intersectable *obj);
132        void SetObjectVisible(GtpVisibilityPreprocessor::Intersectable *entry,
133                                                  const bool visible);
134
135        void ShowViewCellsGeometry();
136
137        /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
138        */
139        void InitDepthPass();
140        /** Creates material for item buffer.
141        */
142        void InitItemBufferPass();
143        /** Fills render queue so that a visualization can be rendered.
144        */
145        void PrepareVisualization(Camera *cam);
146        /** Initialises necessary parameters for hierarchical visibility culling.
147        */
148        void InitVisibilityCulling(Camera *cam);
149        /** Loads / unloads pvs of the view cell to set the visibility in the scene.
150        */
151        void ApplyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
152
153        /** updates pvs in current frame.
154        */
155        void UpdatePvs(Camera *cam);
156
157        /** Sets all objects invisible.
158        */
159        void SetObjectsVisible(const bool visible);
160
161        /** Creates view cells geometry from the loaded view cells.
162        */
163        void CreateViewCellsGeometry();
164        void VisualizeViewCells(const bool visualize);
165
166        /** Load an iv scene.
167        */
168        bool LoadSceneIV(const String &filename,
169                                         SceneNode *root,
170                                         const int index);
171
172        /** Load obj scene.
173        */
174        bool LoadSceneObj(const String &filename,
175                                          const String &viewCellsFile,
176                                          SceneNode *root);
177
178        /** Load a scene.
179        */
180        bool LoadScene(const String &filename,
181                                   const String &viewCellsFilename);
182
183        void loadConfig(DataStreamPtr& stream);
184
185        void RenderDepthPass(const bool fillRenderQueue = true);
186
187        void _renderScene(Camera* camera, Viewport* vp, bool includeOverlays);
188
189        int FindExactVisibleObjects(Camera *camera,
190                                                                Viewport* vp,
191                                                                const bool fromPoint,
192                                                                const bool nodeVisibility);     
193
194        //////////////////////////////////////////
195
196        /// the interface to the scene hierarchy.
197        OctreeHierarchyInterface *mHierarchyInterface;
198
199        /// manages all visibility options
200        GtpVisibility::VisibilityManager *mVisibilityManager;
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        /// if symbols for the nodes are shown in the visualization
209        bool mRenderNodesForViz;
210        /// if content of the nodes is shown in the visualization
211        bool mRenderNodesContentForViz;
212
213        /// render transparents after the hierarchical traversal
214        bool mDelayRenderTransparents;
215
216        /// use a depth pass (i.e., fill only the depth buffer in the first pass)
217        bool mUseDepthPass;
218        /// flag indicating if we currently render the depth pass
219        bool mIsDepthPassPhase;
220       
221        /// if we use an item buffer for rendering (i.e., object ids as color codes
222        bool mUseItemBuffer;
223        /// if we currently render the item buffer
224        bool mIsItemBufferPhase;
225
226        /// if depth write should be enabled
227        bool mEnableDepthWrite;
228        /// if transparents are skipped during rendering
229        bool mSkipTransparents;
230
231        /// the depth pass (no lighting, just filling the depth buffer)
232        Pass *mDepthPass;
233        /// the pass for item buffer setting a color id
234        Pass *mItemBufferPass;
235
236        /// flag for passes which should not be deleted from queue during first traversal
237        int mLeavePassesInQueue;
238
239        /// if transparent object are considered for item buffer visibility
240        bool mRenderTransparentsForItemBuffer;
241        /// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
242        bool mExecuteVertexProgramForAllPasses;
243
244        /// if hierarchical culling is currently in use
245        bool mIsHierarchicalCulling;
246
247        /// do we use preprocessed visibility
248        bool mViewCellsLoaded;
249
250        /// the view cells manager handling the preprocesor stuff
251        GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
252
253
254        /// Used to assign Ogre meshes to view cell entries.
255        GtpVisibilityPreprocessor::ObjectContainer mObjects;
256
257        GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
258        GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
259
260        /// If view cells are used.
261        bool mUseViewCells;
262
263        /// if view cells visualization should be shown
264        bool mShowViewCells;
265
266        /// if the view cells are filtered
267        bool mUseVisibilityFilter;
268
269        bool mDeleteQueueAfterRendering;
270
271        // normal terrain rendering
272        bool mNormalExecution;
273
274        // helper variable to provide sequential numbering for sub-entities
275        int mCurrentEntityId;
276
277        typedef map<int, MovableObject *> MovableMap;
278
279        /// hash table for view cells geometry
280    MovableMap mViewCellsGeometry;
281
282        bool mViewCellsGeometryLoaded;
283
284        string mViewCellsFilename;
285        string mFilename;
286
287        bool mShowTerrain;
288
289        int mFlushRate;
290        int mCurrentFrame;
291
292        ObjReader *mObjReader;
293};
294
295
296/** Factory for VisibilityOctreeSceneManager.
297*/
298class OcclusionCullingSceneManagerFactory : public SceneManagerFactory
299{
300protected:
301        typedef std::vector<TerrainPageSource*> TerrainPageSources;
302        TerrainPageSources mTerrainPageSources;
303        void initMetaData(void) const;
304        GtpVisibility::VisibilityManager *visManager;
305public:
306        OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
307        {
308                visManager = vm;
309        }
310
311        /// Factory type name
312        static const String FACTORY_TYPE_NAME;
313        SceneManager* createInstance(const String& instanceName);
314        void destroyInstance(SceneManager* instance);
315};
316
317} // namespace Ogre
318
319#endif // OcclusionCullingSceneManager_H
Note: See TracBrowser for help on using the repository browser.