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

Revision 2119, 8.4 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
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        /** Load an iv scene.
145        */
146        bool LoadSceneIV(const String &filename,
147                                         SceneNode *root,
148                                         const int index);
149
150        /** Load obj scene.
151        */
152        bool LoadSceneObj(const String &filename,
153                                          const String &viewCellsFile,
154                                          SceneNode *root);
155
156        /** Load a scene.
157        */
158        bool LoadScene(const String &filename, const String &viewCellsFilename);
159
160        void loadConfig(DataStreamPtr& stream);
161
162        //////////////////////////////////////////
163
164        /// the interface to the scene hierarchy.
165        OctreeHierarchyInterface *mHierarchyInterface;
166
167        /// manages all visibility options
168        GtpVisibility::VisibilityManager *mVisibilityManager;
169
170        /// if a visualization of the hierarchical culling is shown
171        bool mShowVisualization;
172
173        /// if the culled nodes are indicated in the visualization
174        bool mVisualizeCulledNodes;
175
176        /// if symbols for the nodes are shown in the visualization
177        bool mRenderNodesForViz;
178        /// if content of the nodes is shown in the visualization
179        bool mRenderNodesContentForViz;
180
181        /// render transparents after the hierarchical traversal
182        bool mDelayRenderTransparents;
183
184        /// use a depth pass (i.e., fill only the depth buffer in the first pass)
185        bool mUseDepthPass;
186        /// flag indicating if we currently render the depth pass
187        bool mIsDepthPassPhase;
188       
189        /// if we use an item buffer for rendering (i.e., object ids as color codes
190        bool mUseItemBuffer;
191        /// if we currently render the item buffer
192        bool mIsItemBufferPhase;
193
194        /// if depth write should be enabled
195        bool mEnableDepthWrite;
196        /// if transparents are skipped during rendering
197        bool mSkipTransparents;
198
199        /// the depth pass (no lighting, just filling the depth buffer)
200        Pass *mDepthPass;
201        /// the pass for item buffer setting a color id
202        Pass *mItemBufferPass;
203
204        /// flag for passes which should not be deleted from queue during first traversal
205        int mLeavePassesInQueue;
206
207        /// if transparent object are considered for item buffer visibility
208        bool mRenderTransparentsForItemBuffer;
209        /// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
210        bool mExecuteVertexProgramForAllPasses;
211
212        /// if hierarchical culling is currently in use
213        bool mIsHierarchicalCulling;
214
215        /// do we use preprocessed visibility
216        bool mViewCellsLoaded;
217
218        /// the view cells manager handling the preprocesor stuff
219        GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
220
221
222        /// Used to assign Ogre meshes to view cell entries.
223        GtpVisibilityPreprocessor::ObjectContainer mObjects;
224
225        GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
226        GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
227
228        /// If view cells are used.
229        bool mUseViewCells;
230
231        /// if view cells visualization should be shown
232        bool mShowViewCells;
233
234        /// if the view cells are filtered
235        bool mUseVisibilityFilter;
236
237        bool mDeleteQueueAfterRendering;
238
239        // normal terrain rendering
240        bool mNormalExecution;
241
242        // helper variable to provide sequential numbering for sub-entities
243        int mCurrentEntityId;
244
245        typedef map<int, MovableObject *> MovableMap;
246
247        /// hash table for view cells geometry
248    MovableMap mViewCellsGeometry;
249
250        bool mViewCellsGeometryLoaded;
251
252        string mViewCellsFilename;
253        string mFilename;
254
255        bool mShowTerrain;
256};
257
258
259/** Factory for VisibilityOctreeSceneManager.
260*/
261class OcclusionCullingSceneManagerFactory : public SceneManagerFactory
262{
263protected:
264        typedef std::vector<TerrainPageSource*> TerrainPageSources;
265        TerrainPageSources mTerrainPageSources;
266        void initMetaData(void) const;
267        GtpVisibility::VisibilityManager *visManager;
268public:
269        OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
270        {
271                visManager = vm;
272        }
273
274        /// Factory type name
275        static const String FACTORY_TYPE_NAME;
276        SceneManager* createInstance(const String& instanceName);
277        void destroyInstance(SceneManager* instance);
278};
279
280} // namespace Ogre
281
282#endif // OcclusionCullingSceneManager_H
Note: See TracBrowser for help on using the repository browser.