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

Revision 1823, 8.2 KB checked in by mattausch, 18 years ago (diff)

changed occlusion culling scene manager
the configuration goes to the scene manager directly (only terrainculling.cfg)

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