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

Revision 2280, 9.7 KB checked in by mattausch, 18 years ago (diff)

removed dependency on ogre in gtpvisibility

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