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

Revision 2160, 8.9 KB checked in by mattausch, 17 years ago (diff)

depth pass now done in findVisibleObjects. This makes it possible to process the objects found in this method, e.g., with the illumination modules

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,
178                                   const String &viewCellsFilename);
179
180        void loadConfig(DataStreamPtr& stream);
181
182        void RenderDepthPass();
183
184        void _renderScene(Camera* camera, Viewport* vp, bool includeOverlays);
185
186        //////////////////////////////////////////
187
188        /// the interface to the scene hierarchy.
189        OctreeHierarchyInterface *mHierarchyInterface;
190
191        /// manages all visibility options
192        GtpVisibility::VisibilityManager *mVisibilityManager;
193
194        /// if a visualization of the hierarchical culling is shown
195        bool mShowVisualization;
196
197        /// if the culled nodes are indicated in the visualization
198        bool mVisualizeCulledNodes;
199
200        /// if symbols for the nodes are shown in the visualization
201        bool mRenderNodesForViz;
202        /// if content of the nodes is shown in the visualization
203        bool mRenderNodesContentForViz;
204
205        /// render transparents after the hierarchical traversal
206        bool mDelayRenderTransparents;
207
208        /// use a depth pass (i.e., fill only the depth buffer in the first pass)
209        bool mUseDepthPass;
210        /// flag indicating if we currently render the depth pass
211        bool mIsDepthPassPhase;
212       
213        /// if we use an item buffer for rendering (i.e., object ids as color codes
214        bool mUseItemBuffer;
215        /// if we currently render the item buffer
216        bool mIsItemBufferPhase;
217
218        /// if depth write should be enabled
219        bool mEnableDepthWrite;
220        /// if transparents are skipped during rendering
221        bool mSkipTransparents;
222
223        /// the depth pass (no lighting, just filling the depth buffer)
224        Pass *mDepthPass;
225        /// the pass for item buffer setting a color id
226        Pass *mItemBufferPass;
227
228        /// flag for passes which should not be deleted from queue during first traversal
229        int mLeavePassesInQueue;
230
231        /// if transparent object are considered for item buffer visibility
232        bool mRenderTransparentsForItemBuffer;
233        /// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
234        bool mExecuteVertexProgramForAllPasses;
235
236        /// if hierarchical culling is currently in use
237        bool mIsHierarchicalCulling;
238
239        /// do we use preprocessed visibility
240        bool mViewCellsLoaded;
241
242        /// the view cells manager handling the preprocesor stuff
243        GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
244
245
246        /// Used to assign Ogre meshes to view cell entries.
247        GtpVisibilityPreprocessor::ObjectContainer mObjects;
248
249        GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
250        GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
251
252        /// If view cells are used.
253        bool mUseViewCells;
254
255        /// if view cells visualization should be shown
256        bool mShowViewCells;
257
258        /// if the view cells are filtered
259        bool mUseVisibilityFilter;
260
261        bool mDeleteQueueAfterRendering;
262
263        // normal terrain rendering
264        bool mNormalExecution;
265
266        // helper variable to provide sequential numbering for sub-entities
267        int mCurrentEntityId;
268
269        typedef map<int, MovableObject *> MovableMap;
270
271        /// hash table for view cells geometry
272    MovableMap mViewCellsGeometry;
273
274        bool mViewCellsGeometryLoaded;
275
276        string mViewCellsFilename;
277        string mFilename;
278
279        bool mShowTerrain;
280
281        int mFlushRate;
282        int mCurrentFrame;
283
284        ObjReader *mObjReader;
285};
286
287
288/** Factory for VisibilityOctreeSceneManager.
289*/
290class OcclusionCullingSceneManagerFactory : public SceneManagerFactory
291{
292protected:
293        typedef std::vector<TerrainPageSource*> TerrainPageSources;
294        TerrainPageSources mTerrainPageSources;
295        void initMetaData(void) const;
296        GtpVisibility::VisibilityManager *visManager;
297public:
298        OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
299        {
300                visManager = vm;
301        }
302
303        /// Factory type name
304        static const String FACTORY_TYPE_NAME;
305        SceneManager* createInstance(const String& instanceName);
306        void destroyInstance(SceneManager* instance);
307};
308
309} // namespace Ogre
310
311#endif // OcclusionCullingSceneManager_H
Note: See TracBrowser for help on using the repository browser.