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

Revision 1616, 7.9 KB checked in by mattausch, 18 years ago (diff)

some shit happen

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