source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreVisibilityOctreeSceneManager.h @ 903

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