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)

RevLine 
[675]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>
[897]9#include <OgreMovableObject.h>
[675]10#include "OgreOctreeHierarchyInterface.h"
11#include "OgrePlatformQueryManager.h"
12#include "VisibilityManager.h"
[897]13#include "Containers.h"
[828]14#include "ViewCellsManager.h"
[675]15
16namespace Ogre {
17
[1593]18
[675]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:
[897]26        OcclusionCullingSceneManager(const String& name, GtpVisibility::VisibilityManager *visManager);
[675]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
[925]55        /** Render a queue group.
[675]56                Override so we can handle delayed rendering of transparent objects
57        */
[925]58        void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
59                                                                          QueuedRenderableCollection::OrganisationMode om);
[675]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        */
[1221]67        virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
[675]68
69        /** Override from SceneManager so we can skip all but first pass for depth pass.
70        */
71        bool validatePassForRendering(Pass* pass);
[897]72#ifdef ITEM_BUFFER
[675]73        void RenderItemBuffer(RenderPriorityGroup* pGroup);
74        void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass);
[897]75#endif // ITEM_BUFFER
76        void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
77                QueuedRenderableCollection::OrganisationMode om);
[675]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
[897]91        /** Inherited from scene manager. Neccesary to draw terrain properly.
[675]92        */
93        void endFrame();
94
[897]95        void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
96                QueuedRenderableCollection::OrganisationMode om);
97        void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
98                QueuedRenderableCollection::OrganisationMode om);
[931]99       
[675]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.
[897]103                msz: Modified to reflect changes in Ogre::TerrainSceneManager
[675]104        */
[925]105#if 1
[1816]106        virtual void setWorldGeometry(DataStreamPtr& stream, const String& typeName);
[925]107#endif
[897]108       
[828]109        /** Loads view cells for this particular scene.
110        */
[938]111        bool LoadViewCells(const String &filename);
[828]112
[675]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);
[903]127        /** Loads / unloads pvs of the view cell to set the visibility in the scene.
128        */
[1593]129        void ApplyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
[903]130
131        /** updates pvs in current frame.
132        */
[1593]133        void UpdatePvs(Camera *cam);
[903]134
135        /** Sets all objects invisible.
136        */
137        void SetObjectsVisible(const bool visible);
138
[1593]139        /** Creates view cells geometry from the loaded view cells.
140        */
141        void CreateViewCellsGeometry();
[1602]142        void VisualizeViewCells(const bool visualize);
[1593]143
[1816]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
[1221]152        //////////////////////////////////////////
153
[675]154        /// the interface to the scene hierarchy.
155        OctreeHierarchyInterface *mHierarchyInterface;
[1593]156
[675]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
[903]171        /// render transparents after the hierarchical traversal
[675]172        bool mDelayRenderTransparents;
173
[903]174        /// use a depth pass (i.e., fill only the depth buffer in the first pass)
[675]175        bool mUseDepthPass;
[903]176        /// flag indicating if we currently render the depth pass
[675]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;
[1593]191        /// the pass for item buffer setting a color id
[675]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;
[868]201
[863]202        /// if hierarchical culling is currently in use
[675]203        bool mIsHierarchicalCulling;
[828]204
[1593]205        /// do we use preprocessed visibility
[903]206        bool mViewCellsLoaded;
[1593]207
208        /// the view cells manager handling the preprocesor stuff
[863]209        GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
[903]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
[1606]221        /// if view cells visualization should be shown
222        bool mShowViewCells;
223
[903]224        /// if the view cells are filtered
225        bool mUseVisibilityFilter;
[1251]226
227        bool mDeleteQueueAfterRendering;
[1276]228
229        // normal terrain rendering
230        bool mNormalExecution;
[1593]231
232        // helper variable to provide sequential numbering for sub-entities
233        int mCurrentEntityId;
234
[1616]235        typedef map<int, MovableObject *> MovableMap;
[1593]236
237        /// hash table for view cells geometry
[1616]238    MovableMap mViewCellsGeometry;
239
240        bool mViewCellsGeometryLoaded;
[1816]241
[1823]242        string mViewCellsFilename;
243        string mFilename;
244
[1816]245        bool mShowTerrain;
[675]246};
247
[1593]248
249/** Factory for VisibilityOctreeSceneManager.
250*/
[903]251class OcclusionCullingSceneManagerFactory : public SceneManagerFactory
252{
253protected:
[925]254        typedef std::vector<TerrainPageSource*> TerrainPageSources;
255        TerrainPageSources mTerrainPageSources;
[903]256        void initMetaData(void) const;
257        GtpVisibility::VisibilityManager *visManager;
258public:
259        OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
260        {
261                visManager = vm;
262        }
[925]263
[903]264        /// Factory type name
265        static const String FACTORY_TYPE_NAME;
266        SceneManager* createInstance(const String& instanceName);
267        void destroyInstance(SceneManager* instance);
268};
269
[675]270} // namespace Ogre
271
[903]272#endif // OcclusionCullingSceneManager_H
Note: See TracBrowser for help on using the repository browser.