[1318] | 1 | /*
|
---|
| 2 | -----------------------------------------------------------------------------
|
---|
| 3 | This source file is part of the GameTools Project
|
---|
| 4 | http://www.gametools.org
|
---|
| 5 |
|
---|
| 6 | Author: Martin Szydlowski
|
---|
| 7 | -----------------------------------------------------------------------------
|
---|
| 8 | */
|
---|
| 9 |
|
---|
[1320] | 10 | #ifndef _BvHierarchySceneManager_H__
|
---|
| 11 | #define _BvHierarchySceneManager_H__
|
---|
[1318] | 12 |
|
---|
| 13 | #include <OgreSceneManager.h>
|
---|
| 14 | #include <VisibilityManager.h>
|
---|
| 15 | #include <ViewCellsManager.h>
|
---|
| 16 |
|
---|
| 17 | #include "OgreBvHierarchy.h"
|
---|
| 18 | #include "OgreBvHierarchyCamera.h"
|
---|
| 19 | #include "OgreBvHierarchyInterface.h"
|
---|
| 20 |
|
---|
[1320] | 21 | #define BvHierarchy_MAX_DEPTH 12
|
---|
[1318] | 22 |
|
---|
| 23 | namespace Ogre
|
---|
| 24 | {
|
---|
| 25 |
|
---|
[1320] | 26 | class BvHierarchySceneNode;
|
---|
[1318] | 27 |
|
---|
[1320] | 28 | class BvHierarchySceneManager : public SceneManager
|
---|
[1318] | 29 | {
|
---|
| 30 | public:
|
---|
[1320] | 31 | BvHierarchySceneManager(const String& name, GtpVisibility::VisibilityManager *vm);
|
---|
| 32 | ~BvHierarchySceneManager(void);
|
---|
[1318] | 33 |
|
---|
| 34 | virtual const String& getTypeName(void) const;
|
---|
| 35 |
|
---|
[1320] | 36 | //typedef std::list<BvHierarchySceneNode *> NodeList;
|
---|
[1318] | 37 | //typedef std::list<WireBoundingBox *> BoxList;
|
---|
| 38 |
|
---|
| 39 | /************************************************************************/
|
---|
[1320] | 40 | /* Functions overridden form SceneManager for BvHierarchy */
|
---|
[1318] | 41 | /************************************************************************/
|
---|
| 42 |
|
---|
| 43 | /** Override from Scenemanager to create Camera as instance of BvHierarchyCamera
|
---|
| 44 | */
|
---|
| 45 | virtual Camera* createCamera(const String& name);
|
---|
| 46 |
|
---|
[1320] | 47 | /** Override from SceneManager to create SceneNodes as instance of BvHierarchySceneNode
|
---|
[1318] | 48 | */
|
---|
| 49 | virtual SceneNode* createSceneNode(void);
|
---|
[1320] | 50 | /** Override from SceneManager to create SceneNodes as instance of BvHierarchySceneNode
|
---|
[1318] | 51 | */
|
---|
| 52 | virtual SceneNode* createSceneNode(const String& name);
|
---|
| 53 |
|
---|
| 54 | /** Override from Scenemanager, employ kd-tree based culling or CHC
|
---|
| 55 | */
|
---|
| 56 | virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters);
|
---|
| 57 |
|
---|
| 58 | virtual bool setOption(const String& strKey, const void* pValue);
|
---|
| 59 | virtual bool getOption(const String& strKey, void* pDestValue);
|
---|
| 60 |
|
---|
| 61 | bool getOptionValues(const String & key, StringVector &refValueList);
|
---|
| 62 | bool getOptionKeys(StringVector &refKeys);
|
---|
| 63 |
|
---|
[1320] | 64 | /** Overide from scene manager to destroy BvHierarchy properly (before the scene graph is destroyed)
|
---|
[1318] | 65 | */
|
---|
| 66 | virtual void clearScene();
|
---|
| 67 |
|
---|
| 68 | /************************************************************************/
|
---|
| 69 | /* Functions overridden from SceneManager for CHC */
|
---|
| 70 | /************************************************************************/
|
---|
| 71 |
|
---|
| 72 | /** Override from SceneManager so that sub entities can be assigned an id for item buffer.
|
---|
| 73 | */
|
---|
| 74 | Entity* createEntity(const String& entityName, const String& meshName);
|
---|
| 75 |
|
---|
| 76 | /** Override from scene manager to set up culling manager
|
---|
| 77 | */
|
---|
| 78 | virtual void _updateSceneGraph(Camera* cam);
|
---|
| 79 |
|
---|
| 80 | /** Override from SceneManager, employ normal rendering or CHC
|
---|
| 81 | */
|
---|
| 82 | virtual void _renderVisibleObjects();
|
---|
| 83 |
|
---|
| 84 | /** Override pass so we can do the z-fail pass.
|
---|
| 85 | */
|
---|
| 86 | virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
|
---|
| 87 |
|
---|
| 88 | /** Render a queue group.
|
---|
| 89 | Override so we can handle delayed rendering of transparent objects
|
---|
| 90 | */
|
---|
| 91 | void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 92 | QueuedRenderableCollection::OrganisationMode om);
|
---|
| 93 |
|
---|
| 94 | /** Override from scene manager
|
---|
| 95 | */
|
---|
| 96 | void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 97 | QueuedRenderableCollection::OrganisationMode om);
|
---|
| 98 |
|
---|
| 99 | /** Override from SceneManager so we can skip all but first pass for depth pass.
|
---|
| 100 | */
|
---|
| 101 | bool validatePassForRendering(Pass* pass);
|
---|
| 102 |
|
---|
| 103 | /** Override from SceneManager because idontknow
|
---|
| 104 | */
|
---|
| 105 | void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 106 | QueuedRenderableCollection::OrganisationMode om);
|
---|
| 107 | void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 108 | QueuedRenderableCollection::OrganisationMode om);
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | /************************************************************************/
|
---|
[1320] | 112 | /* Functions which are specific to the BvHierarchy */
|
---|
[1318] | 113 | /************************************************************************/
|
---|
| 114 |
|
---|
[1320] | 115 | /** Update the BvHierarchy with the node (more or less disabled now)
|
---|
[1318] | 116 | */
|
---|
[1320] | 117 | virtual void _updateNode(BvHierarchySceneNode *node); // TODO:
|
---|
[1318] | 118 |
|
---|
[1320] | 119 | /** Show or hide the bounding boxes of BvHierarchy nodes - obsolete, use options
|
---|
[1318] | 120 | */
|
---|
| 121 | virtual void setShowBoxes(bool showboxes);
|
---|
| 122 | /** Tell if show boxes is enabled - obsolete, use options
|
---|
| 123 | */
|
---|
| 124 | virtual bool getShowBoxes(void) const;
|
---|
| 125 |
|
---|
[1320] | 126 | /** Recurses the BvHierarchy, adding any nodes intersecting with the
|
---|
[1318] | 127 | box/sphere/volume/ray into the given list.
|
---|
| 128 | It ignores the exclude scene node.
|
---|
| 129 | */
|
---|
| 130 | void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 )
|
---|
| 131 | {
|
---|
| 132 | if (mBvHierarchy)
|
---|
| 133 | mBvHierarchy->findNodesIn(box, list, exclude);
|
---|
| 134 | }
|
---|
| 135 | void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 )
|
---|
| 136 | {
|
---|
| 137 | if (mBvHierarchy)
|
---|
| 138 | mBvHierarchy->findNodesIn(sphere, list, exclude);
|
---|
| 139 | }
|
---|
| 140 | void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 )
|
---|
| 141 | {
|
---|
| 142 | if (mBvHierarchy)
|
---|
| 143 | mBvHierarchy->findNodesIn(volume, list, exclude);
|
---|
| 144 | }
|
---|
| 145 | void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 )
|
---|
| 146 | {
|
---|
| 147 | if (mBvHierarchy)
|
---|
| 148 | mBvHierarchy->findNodesIn(ray, list, exclude);
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | /************************************************************************/
|
---|
| 152 | /* Functions for PVS */
|
---|
| 153 | /************************************************************************/
|
---|
| 154 | /** Loads view cells for this particular scene.
|
---|
| 155 | */
|
---|
| 156 | bool LoadViewCells(const String &filename);
|
---|
| 157 |
|
---|
| 158 | /************************************************************************/
|
---|
| 159 | /* Functions for CHC */
|
---|
| 160 | /************************************************************************/
|
---|
| 161 |
|
---|
| 162 | /** Render a list of scenenodes
|
---|
| 163 | */
|
---|
[1320] | 164 | //virtual void _renderNodes(const BvhRenderableList& nodelist, Camera * cam,
|
---|
[1318] | 165 | // bool onlyShadowCasters, int leavePassesInQueue);
|
---|
[1320] | 166 | virtual void _renderNode(BvHierarchy::NodePtr node, Camera * cam,
|
---|
[1318] | 167 | bool onlyShadowCasters, int leavePassesInQueue);
|
---|
| 168 |
|
---|
| 169 | /** Sets the visibility manager.
|
---|
| 170 | @param visManager the visibility manager
|
---|
| 171 | */
|
---|
| 172 | void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
|
---|
| 173 | /** See set.
|
---|
| 174 | */
|
---|
| 175 | GtpVisibility::VisibilityManager *getVisibilityManager();
|
---|
| 176 |
|
---|
| 177 | /** Returns pointer to visibility manager.
|
---|
| 178 | */
|
---|
| 179 | GtpVisibility::VisibilityManager *GetVisibilityManager();
|
---|
| 180 |
|
---|
| 181 | /** Returns hierarchy interface.
|
---|
| 182 | */
|
---|
[1320] | 183 | BvHierarchyInterface *GetHierarchyInterface();
|
---|
[1318] | 184 |
|
---|
| 185 | protected:
|
---|
| 186 | /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
|
---|
| 187 | */
|
---|
| 188 | void InitDepthPass();
|
---|
| 189 | /** Creates material for item buffer.
|
---|
| 190 | */
|
---|
| 191 | void InitItemBufferPass();
|
---|
| 192 | /** Fills render queue so that a visualization can be rendered.
|
---|
| 193 | */
|
---|
| 194 | void PrepareVisualization(Camera *cam);
|
---|
| 195 | /** Initialises necessary parameters for hierarchical visibility culling.
|
---|
| 196 | */
|
---|
| 197 | void InitVisibilityCulling(Camera *cam);
|
---|
| 198 |
|
---|
| 199 | /** Writes out stats into the Ogre log file.
|
---|
| 200 | */
|
---|
| 201 | void WriteLog();
|
---|
| 202 |
|
---|
| 203 | /************************************************************************/
|
---|
| 204 | /* Functions for PVS */
|
---|
| 205 | /************************************************************************/
|
---|
| 206 | /** Loads / unloads pvs of the view cell to set the visibility in the scene.
|
---|
| 207 | */
|
---|
| 208 | void applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
|
---|
| 209 |
|
---|
| 210 | /** updates pvs in current frame.
|
---|
| 211 | */
|
---|
| 212 | void updatePvs(Camera *cam);
|
---|
| 213 |
|
---|
| 214 | /** Sets all objects invisible.
|
---|
| 215 | */
|
---|
| 216 | void SetObjectsVisible(const bool visible);
|
---|
| 217 |
|
---|
| 218 | /************************************************************************/
|
---|
| 219 | /* CHC-specific options & members */
|
---|
| 220 | /************************************************************************/
|
---|
| 221 | // pointer to the visibility manager
|
---|
| 222 | GtpVisibility::VisibilityManager *mVisibilityManager;
|
---|
| 223 |
|
---|
| 224 | // the hierarchy interface for CHC
|
---|
[1320] | 225 | BvHierarchyInterface *mHierarchyInterface;
|
---|
[1318] | 226 |
|
---|
| 227 | // if hierarchical culling is currently in use
|
---|
| 228 | bool mIsHierarchicalCulling;
|
---|
| 229 |
|
---|
| 230 | // if a visualization of the hierarchical culling is shown
|
---|
| 231 | bool mShowVisualization;
|
---|
| 232 |
|
---|
| 233 | // if the culled nodes are indicated in the visualization
|
---|
| 234 | bool mVisualizeCulledNodes;
|
---|
| 235 |
|
---|
| 236 | // consecutive number for sub-entities
|
---|
| 237 | int mCurrentEntityId;
|
---|
| 238 |
|
---|
| 239 | // flag for passes which should not be deleted from queue during first traversal
|
---|
| 240 | int mLeavePassesInQueue;
|
---|
| 241 |
|
---|
| 242 | // if symbols for the nodes are shown in the visualization
|
---|
| 243 | bool mRenderNodesForViz;
|
---|
| 244 | // if content of the nodes is shown in the visualization
|
---|
| 245 | bool mRenderNodesContentForViz;
|
---|
| 246 | /// render transparents after the hierarchical traversal
|
---|
| 247 | bool mDelayRenderTransparents;
|
---|
| 248 |
|
---|
| 249 | // if transparent object are considered for item buffer visibility
|
---|
| 250 | bool mRenderTransparentsForItemBuffer;
|
---|
| 251 | // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
|
---|
| 252 | bool mExecuteVertexProgramForAllPasses;
|
---|
| 253 |
|
---|
| 254 | // the depth pass (no lighting, just filling the depth buffer)
|
---|
| 255 | Pass *mDepthPass;
|
---|
| 256 | // use a depth pass (i.e., fill only the depth buffer in the first pass)
|
---|
| 257 | bool mUseDepthPass;
|
---|
| 258 | // flag indicating if we currently render the depth pass
|
---|
| 259 | bool mIsDepthPassPhase;
|
---|
| 260 | // if depth write should be enabled
|
---|
| 261 | bool mEnableDepthWrite;
|
---|
| 262 | // if transparents are skipped during rendering
|
---|
| 263 | bool mSkipTransparents;
|
---|
| 264 | // the item buffer pass (render items color-coded)
|
---|
| 265 | Pass *mItemBufferPass;
|
---|
| 266 | // if we use an item buffer for rendering (i.e., object ids as color codes
|
---|
| 267 | bool mUseItemBuffer;
|
---|
| 268 | // if we currently render the item buffer
|
---|
| 269 | bool mIsItemBufferPhase;
|
---|
| 270 | // delete or clear the renderqueue after each rame?
|
---|
| 271 | bool mDeleteQueueAfterRendering;
|
---|
| 272 |
|
---|
| 273 | // remember visited scene nodes for viz
|
---|
[1320] | 274 | BvHierarchy::NodeList mVisibleNodes;
|
---|
[1318] | 275 |
|
---|
[1595] | 276 |
|
---|
[1318] | 277 | /************************************************************************/
|
---|
[1595] | 278 | /* Bvh specific options & members */
|
---|
[1318] | 279 | /************************************************************************/
|
---|
[1595] | 280 |
|
---|
| 281 |
|
---|
[1320] | 282 | // maximum depth of the BvHierarchy
|
---|
[1318] | 283 | int mMaxDepth;
|
---|
| 284 |
|
---|
[1320] | 285 | // the BvHierarchy which holds the scene
|
---|
| 286 | BvHierarchy *mBvHierarchy;
|
---|
[1318] | 287 |
|
---|
[1320] | 288 | // if bounding boxes of BvHierarchy nodes are shown
|
---|
[1318] | 289 | bool mShowBoxes;
|
---|
| 290 | // bounding boxes of kd nodes will be highlighted on this level of the kd tree
|
---|
| 291 | int mHiLiteLevel;
|
---|
| 292 | // if all bounding boxes shall be displayed, not only the highlighted level
|
---|
| 293 | bool mShowAllBoxes;
|
---|
[1320] | 294 | // visualize BvHierarchy nodes or bounding boxes of objects in nodes
|
---|
[1318] | 295 | bool mShowNodes;
|
---|
| 296 |
|
---|
| 297 | // vis mode
|
---|
| 298 | bool mEnhancedVisiblity;
|
---|
| 299 |
|
---|
| 300 | // the method/algorithm used when rendering the scene
|
---|
[1320] | 301 | BvHierarchy::RenderMethod mRenderMethod;
|
---|
[1318] | 302 |
|
---|
| 303 | // the method of building the tree
|
---|
[1320] | 304 | BvHierarchy::BuildMethod mBuildMethod;
|
---|
[1318] | 305 |
|
---|
| 306 | /************************************************************************/
|
---|
| 307 | /* PVS specific options and members */
|
---|
| 308 | /************************************************************************/
|
---|
| 309 |
|
---|
| 310 | // The view cell manager
|
---|
| 311 | GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
|
---|
| 312 |
|
---|
| 313 | /// Used to assign Ogre meshes to view cell entries.
|
---|
| 314 | GtpVisibilityPreprocessor::ObjectContainer mObjects;
|
---|
| 315 |
|
---|
| 316 | GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
|
---|
| 317 | GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
|
---|
| 318 |
|
---|
| 319 | /// If view cells are loaded.
|
---|
| 320 | bool mViewCellsLoaded;
|
---|
| 321 |
|
---|
| 322 | /// If view cells are used.
|
---|
| 323 | bool mUseViewCells;
|
---|
| 324 |
|
---|
| 325 | /// if the view cells are filtered
|
---|
| 326 | bool mUseVisibilityFilter;
|
---|
| 327 | };
|
---|
| 328 |
|
---|
| 329 |
|
---|
| 330 |
|
---|
[1320] | 331 | /// Factory for BvHierarchySceneManager
|
---|
| 332 | class BvHierarchySceneManagerFactory: public SceneManagerFactory
|
---|
[1318] | 333 | {
|
---|
| 334 | protected:
|
---|
| 335 | void initMetaData(void) const;
|
---|
| 336 | GtpVisibility::VisibilityManager *visManager;
|
---|
| 337 | public:
|
---|
| 338 | BvHierarchySceneManagerFactory(GtpVisibility::VisibilityManager * vm)
|
---|
| 339 | {
|
---|
| 340 | visManager = vm;
|
---|
[1320] | 341 | }
|
---|
[1318] | 342 | ~BvHierarchySceneManagerFactory(void) {};
|
---|
| 343 | /// Factory type name
|
---|
| 344 | static const String FACTORY_TYPE_NAME;
|
---|
| 345 | SceneManager* createInstance(const String& instanceName);
|
---|
| 346 | void destroyInstance(SceneManager* instance);
|
---|
| 347 | };
|
---|
| 348 |
|
---|
| 349 | } // namespace Ogre
|
---|
| 350 |
|
---|
[1320] | 351 | #endif // _BvHierarchySceneManager_H__ |
---|