source: GTP/trunk/Lib/Vis/OnlineCullingCHC/OGRE/include/OgreKdTreeSceneManager.h @ 1192

Revision 1192, 9.2 KB checked in by szydlowski, 18 years ago (diff)

pre-major-changes-backup (TM)
fixed node vis issues for internal culling

Line 
1/*
2-----------------------------------------------------------------------------
3This source file is part of the GameTools Project
4http://www.gametools.org
5
6Author: Martin Szydlowski
7-----------------------------------------------------------------------------
8*/
9
10#ifndef _KdTreeSceneManager_H__
11#define _KdTreeSceneManager_H__
12
13#include <OgreKdTreeHierarchyInterface.h>
14#include <OgreSceneManager.h>
15#include <VisibilityManager.h>
16#include "OgreKdTree.h"
17
18#define KDTREE_MAX_DEPTH 12
19
20namespace Ogre
21{
22
23class KdTreeSceneNode;
24//class WireBoundingBox;
25
26class KdTreeSceneManager : public SceneManager
27{
28public:
29        KdTreeSceneManager(const String& name, GtpVisibility::VisibilityManager *vm);
30        ~KdTreeSceneManager(void);
31
32        virtual const String& getTypeName(void) const;
33
34        //typedef std::list<KdTreeSceneNode *> NodeList;
35        //typedef std::list<WireBoundingBox *> BoxList;
36
37        /************************************************************************/
38        /* Functions overridden form SceneManager for KdTree                    */
39        /************************************************************************/
40
41        /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode
42        */
43        virtual SceneNode* createSceneNode(void);
44        /** Override from SceneManager to create SceneNodes as instance of KdTreeSceneNode
45        */
46        virtual SceneNode* createSceneNode(const String& name);
47
48        /** Override from Scenemanager, employ kd-tree based culling or CHC
49        */
50        virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters);
51
52        virtual bool setOption(const String& strKey, const void* pValue);
53        virtual bool getOption(const String& strKey, void* pDestValue);
54
55        bool getOptionValues(const String & key, StringVector &refValueList);
56        bool getOptionKeys(StringVector &refKeys);
57
58        /** Overide from scene manager to destroy kdtree properly (before the scene graph is destroyed)
59        */
60        virtual void clearScene()
61        {
62                // DEBUG
63                //if (mKdTree)
64                //      mKdTree->dump();
65
66                // must happen before actual scene is cleared
67                OGRE_DELETE(mKdTree);
68
69                SceneManager::clearScene();
70        }
71
72        /************************************************************************/
73        /* Functions overridden from SceneManager for CHC                       */
74        /************************************************************************/
75
76        /** Override from SceneManager so that sub entities can be assigned an id for item buffer.
77        */
78        Entity* createEntity(const String& entityName, const String& meshName);
79
80        /** Override from scene manager to set up culling manager
81        */
82        virtual void _updateSceneGraph(Camera* cam);
83
84        /** Override from SceneManager, employ normal rendering or CHC
85        */
86        virtual void _renderVisibleObjects();
87
88        /** Override pass so we can do the z-fail pass.
89        */
90        const Pass* _setPass(Pass* pass);
91
92        /** Render a queue group.
93        Override so we can handle delayed rendering of transparent objects
94        */
95        void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
96                QueuedRenderableCollection::OrganisationMode om);
97
98        /** Override from scene manager
99        */
100        void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
101                QueuedRenderableCollection::OrganisationMode om);
102
103        /** Override from SceneManager so we can skip all but first pass for depth pass.
104        */
105        bool validatePassForRendering(Pass* pass);
106
107        /** Override from SceneManager because idontknow
108        */
109        void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
110                QueuedRenderableCollection::OrganisationMode om);
111        void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
112                QueuedRenderableCollection::OrganisationMode om);
113
114
115        /************************************************************************/
116        /* Functions which are specific to the KdTree                           */
117        /************************************************************************/
118       
119        /** Update the KdTree with the node (more or less disabled now)
120        */
121        virtual void _updateNode(KdTreeSceneNode *node); // TODO:
122
123        /** Show or hide the bounding boxes of KdTree nodes - obsolete, use options
124        */
125        virtual void setShowBoxes(bool showboxes);
126        /** Tell if show boxes is enabled - obsolete, use options
127        */
128        virtual bool getShowBoxes(void) const;
129
130        /************************************************************************/
131        /* Functions for CHC                                                    */
132        /************************************************************************/
133
134        /** Render a list of scenenodes
135        */
136        //virtual void _renderNodes(const KdRenderableList& nodelist, Camera * cam,
137        //      bool onlyShadowCasters, int leavePassesInQueue);
138        virtual void _renderNode(KdTree::NodePtr node, Camera * cam,
139                bool onlyShadowCasters, int leavePassesInQueue);
140
141        /** Sets the visibility manager.
142        @param visManager the visibility manager
143        */
144        void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
145        /** See set.
146        */
147        GtpVisibility::VisibilityManager *getVisibilityManager();
148
149        /** Returns pointer to visibility manager.
150        */
151        GtpVisibility::VisibilityManager *GetVisibilityManager();
152
153        /** Returns hierarchy interface.
154        */
155        KdTreeHierarchyInterface *GetHierarchyInterface();
156
157protected:
158        /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
159        */
160        void InitDepthPass();
161        /** Creates material for item buffer.
162        */
163        void InitItemBufferPass();
164        /** Fills render queue so that a visualization can be rendered.
165        */
166        void PrepareVisualization(Camera *cam);
167        /** Initialises necessary parameters for hierarchical visibility culling.
168        */
169        void InitVisibilityCulling(Camera *cam);
170
171        /** Writes out stats into the Ogre log file.
172        */
173        void WriteLog();
174
175
176        /************************************************************************/
177        /* CHC-specific options & members                                       */
178        /************************************************************************/
179        // pointer to the visibility manager
180        GtpVisibility::VisibilityManager *mVisibilityManager;
181
182        // the hierarchy interface for CHC
183        KdTreeHierarchyInterface *mHierarchyInterface;
184
185        // if hierarchical culling is currently in use
186        bool mIsHierarchicalCulling;
187
188        // if a visualization of the hierarchical culling is shown
189        bool mShowVisualization;
190       
191        // if the culled nodes are indicated in the visualization
192        bool mVisualizeCulledNodes;
193
194        // consecutive number for sub-entities
195        int mCurrentEntityId;
196
197        // flag for passes which should not be deleted from queue during first traversal
198        int mLeavePassesInQueue;
199
200        // if symbols for the nodes are shown in the visualization
201        bool mRenderNodesForViz;
202        // if content of the nodes is shown in the visualization
203        bool mRenderNodesContentForViz;
204        /// render transparents after the hierarchical traversal
205        bool mDelayRenderTransparents;
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        // the depth pass (no lighting, just filling the depth buffer)
213        Pass *mDepthPass;
214        // use a depth pass (i.e., fill only the depth buffer in the first pass)
215        bool mUseDepthPass;
216        // flag indicating if we currently render the depth pass
217        bool mIsDepthPassPhase;
218        // if depth write should be enabled
219        bool mEnableDepthWrite;
220        // if transparents are skipped during rendering
221        bool mSkipTransparents;
222
223        // the item buffer pass (render items color-coded)
224        Pass *mItemBufferPass;
225        // if we use an item buffer for rendering (i.e., object ids as color codes
226        bool mUseItemBuffer;
227        // if we currently render the item buffer
228        bool mIsItemBufferPhase;
229
230        // remember visited scene nodes for viz
231        //KdRenderableList mVisibleNodes;
232        KdTree::NodeList mVisibleNodes;
233
234        /************************************************************************/
235        /* Kd-Tree specific options & members                                   */
236        /************************************************************************/
237        // maximum depth of the kdtree
238        int mMaxDepth;
239
240        // the kdtree which holds the scene
241        KdTree *mKdTree;
242
243        // if bounding boxes of kdtree nodes are shown
244        bool mShowBoxes;
245        // bounding boxes of kd nodes will be highlighted on this level of the kd tree
246        int mHiLiteLevel;
247        // if all bounding boxes shall be displayed, not only the highlighted level
248        bool mShowAllBoxes;
249        // visualize kdtree nodes or bounding boxes of objects in nodes
250        bool mShowNodes;
251
252        // the method/algorithm used when rendering the scene
253        KdTree::RenderMethod mRenderMethod;
254
255        // the method of building the tree
256        KdTree::BuildMethod mBuildMethod;
257};
258
259
260
261/// Factory for KdTreeSceneManager
262class KdTreeSceneManagerFactory : public SceneManagerFactory
263{
264protected:
265        void initMetaData(void) const;
266        GtpVisibility::VisibilityManager *visManager;
267public:
268        KdTreeSceneManagerFactory(GtpVisibility::VisibilityManager * vm)
269        {
270                visManager = vm;
271        };
272        ~KdTreeSceneManagerFactory(void) {};
273        /// Factory type name
274        static const String FACTORY_TYPE_NAME;
275        SceneManager* createInstance(const String& instanceName);
276        void destroyInstance(SceneManager* instance);
277};
278
279} // namespace Ogre
280
281#endif // _KdTreeSceneManager_H__
Note: See TracBrowser for help on using the repository browser.