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

Revision 931, 7.4 KB checked in by mattausch, 18 years ago (diff)

added bounding boxes to xml description

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