/* ----------------------------------------------------------------------------- This source file is part of the GameTools Project http://www.gametools.org Author: Martin Szydlowski ----------------------------------------------------------------------------- */ #ifndef _BvHierarchySceneManager_H__ #define _BvHierarchySceneManager_H__ #include #include #include #include "OgreBvHierarchy.h" #include "OgreBvHierarchyCamera.h" #include "OgreBvHierarchyInterface.h" #define BvHierarchy_MAX_DEPTH 12 namespace Ogre { class BvHierarchySceneNode; class BvHierarchySceneManager : public SceneManager { public: BvHierarchySceneManager(const String& name, GtpVisibility::VisibilityManager *vm); ~BvHierarchySceneManager(void); virtual const String& getTypeName(void) const; //typedef std::list NodeList; //typedef std::list BoxList; /************************************************************************/ /* Functions overridden form SceneManager for BvHierarchy */ /************************************************************************/ /** Override from Scenemanager to create Camera as instance of BvHierarchyCamera */ virtual Camera* createCamera(const String& name); /** Override from SceneManager to create SceneNodes as instance of BvHierarchySceneNode */ virtual SceneNode* createSceneNode(void); /** Override from SceneManager to create SceneNodes as instance of BvHierarchySceneNode */ virtual SceneNode* createSceneNode(const String& name); /** Override from Scenemanager, employ kd-tree based culling or CHC */ virtual void _findVisibleObjects(Camera *cam, bool onlyShadowCasters); virtual bool setOption(const String& strKey, const void* pValue); virtual bool getOption(const String& strKey, void* pDestValue); bool getOptionValues(const String & key, StringVector &refValueList); bool getOptionKeys(StringVector &refKeys); /** Overide from scene manager to destroy BvHierarchy properly (before the scene graph is destroyed) */ virtual void clearScene(); /************************************************************************/ /* Functions overridden from SceneManager for CHC */ /************************************************************************/ /** Override from SceneManager so that sub entities can be assigned an id for item buffer. */ Entity* createEntity(const String& entityName, const String& meshName); /** Override from scene manager to set up culling manager */ virtual void _updateSceneGraph(Camera* cam); /** Override from SceneManager, employ normal rendering or CHC */ virtual void _renderVisibleObjects(); /** Override pass so we can do the z-fail pass. */ virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false); /** Render a queue group. Override so we can handle delayed rendering of transparent objects */ void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om); /** Override from scene manager */ void _renderQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om); /** Override from SceneManager so we can skip all but first pass for depth pass. */ bool validatePassForRendering(Pass* pass); /** Override from SceneManager because idontknow */ void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om); void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om); /************************************************************************/ /* Functions which are specific to the BvHierarchy */ /************************************************************************/ /** Update the BvHierarchy with the node (more or less disabled now) */ virtual void _updateNode(BvHierarchySceneNode *node); // TODO: /** Show or hide the bounding boxes of BvHierarchy nodes - obsolete, use options */ virtual void setShowBoxes(bool showboxes); /** Tell if show boxes is enabled - obsolete, use options */ virtual bool getShowBoxes(void) const; /** Recurses the BvHierarchy, adding any nodes intersecting with the box/sphere/volume/ray into the given list. It ignores the exclude scene node. */ void findNodesIn( const AxisAlignedBox &box, std::list < SceneNode * > &list, SceneNode *exclude = 0 ) { if (mBvHierarchy) mBvHierarchy->findNodesIn(box, list, exclude); } void findNodesIn( const Sphere &sphere, std::list < SceneNode * > &list, SceneNode *exclude = 0 ) { if (mBvHierarchy) mBvHierarchy->findNodesIn(sphere, list, exclude); } void findNodesIn( const PlaneBoundedVolume &volume, std::list < SceneNode * > &list, SceneNode *exclude=0 ) { if (mBvHierarchy) mBvHierarchy->findNodesIn(volume, list, exclude); } void findNodesIn( const Ray &ray, std::list < SceneNode * > &list, SceneNode *exclude=0 ) { if (mBvHierarchy) mBvHierarchy->findNodesIn(ray, list, exclude); } /************************************************************************/ /* Functions for PVS */ /************************************************************************/ /** Loads view cells for this particular scene. */ bool LoadViewCells(const String &filename); /************************************************************************/ /* Functions for CHC */ /************************************************************************/ /** Render a list of scenenodes */ //virtual void _renderNodes(const BvhRenderableList& nodelist, Camera * cam, // bool onlyShadowCasters, int leavePassesInQueue); virtual void _renderNode(BvHierarchy::NodePtr node, Camera * cam, bool onlyShadowCasters, int leavePassesInQueue); /** Sets the visibility manager. @param visManager the visibility manager */ void setVisibilityManager(GtpVisibility::VisibilityManager *visManager); /** See set. */ GtpVisibility::VisibilityManager *getVisibilityManager(); /** Returns pointer to visibility manager. */ GtpVisibility::VisibilityManager *GetVisibilityManager(); /** Returns hierarchy interface. */ BvHierarchyInterface *GetHierarchyInterface(); protected: /** Creates material for depth pass, e.g., a pass that only fills the depth buffer. */ void InitDepthPass(); /** Creates material for item buffer. */ void InitItemBufferPass(); /** Fills render queue so that a visualization can be rendered. */ void PrepareVisualization(Camera *cam); /** Initialises necessary parameters for hierarchical visibility culling. */ void InitVisibilityCulling(Camera *cam); /** Writes out stats into the Ogre log file. */ void WriteLog(); /************************************************************************/ /* Functions for PVS */ /************************************************************************/ /** Loads / unloads pvs of the view cell to set the visibility in the scene. */ void applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load); /** updates pvs in current frame. */ void updatePvs(Camera *cam); /** Sets all objects invisible. */ void SetObjectsVisible(const bool visible); /************************************************************************/ /* CHC-specific options & members */ /************************************************************************/ // pointer to the visibility manager GtpVisibility::VisibilityManager *mVisibilityManager; // the hierarchy interface for CHC BvHierarchyInterface *mHierarchyInterface; // if hierarchical culling is currently in use bool mIsHierarchicalCulling; // if a visualization of the hierarchical culling is shown bool mShowVisualization; // if the culled nodes are indicated in the visualization bool mVisualizeCulledNodes; // consecutive number for sub-entities int mCurrentEntityId; // flag for passes which should not be deleted from queue during first traversal int mLeavePassesInQueue; // if symbols for the nodes are shown in the visualization bool mRenderNodesForViz; // if content of the nodes is shown in the visualization bool mRenderNodesContentForViz; /// render transparents after the hierarchical traversal bool mDelayRenderTransparents; // if transparent object are considered for item buffer visibility bool mRenderTransparentsForItemBuffer; // Always execute the vertex program of a pass, e.g., for the depth pass or item buffer bool mExecuteVertexProgramForAllPasses; // the depth pass (no lighting, just filling the depth buffer) Pass *mDepthPass; // use a depth pass (i.e., fill only the depth buffer in the first pass) bool mUseDepthPass; // flag indicating if we currently render the depth pass bool mIsDepthPassPhase; // if depth write should be enabled bool mEnableDepthWrite; // if transparents are skipped during rendering bool mSkipTransparents; // the item buffer pass (render items color-coded) Pass *mItemBufferPass; // if we use an item buffer for rendering (i.e., object ids as color codes bool mUseItemBuffer; // if we currently render the item buffer bool mIsItemBufferPhase; // delete or clear the renderqueue after each rame? bool mDeleteQueueAfterRendering; // remember visited scene nodes for viz BvHierarchy::NodeList mVisibleNodes; /************************************************************************/ /* Bvh specific options & members */ /************************************************************************/ // maximum depth of the BvHierarchy int mMaxDepth; // the BvHierarchy which holds the scene BvHierarchy *mBvHierarchy; // if bounding boxes of BvHierarchy nodes are shown bool mShowBoxes; // bounding boxes of kd nodes will be highlighted on this level of the kd tree int mHiLiteLevel; // if all bounding boxes shall be displayed, not only the highlighted level bool mShowAllBoxes; // visualize BvHierarchy nodes or bounding boxes of objects in nodes bool mShowNodes; // vis mode bool mEnhancedVisiblity; // the method/algorithm used when rendering the scene BvHierarchy::RenderMethod mRenderMethod; // the method of building the tree BvHierarchy::BuildMethod mBuildMethod; /************************************************************************/ /* PVS specific options and members */ /************************************************************************/ // The view cell manager GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager; /// Used to assign Ogre meshes to view cell entries. GtpVisibilityPreprocessor::ObjectContainer mObjects; GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell; GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell; /// If view cells are loaded. bool mViewCellsLoaded; /// If view cells are used. bool mUseViewCells; /// if the view cells are filtered bool mUseVisibilityFilter; }; /// Factory for BvHierarchySceneManager class BvHierarchySceneManagerFactory: public SceneManagerFactory { protected: void initMetaData(void) const; GtpVisibility::VisibilityManager *visManager; public: BvHierarchySceneManagerFactory(GtpVisibility::VisibilityManager * vm) { visManager = vm; } ~BvHierarchySceneManagerFactory(void) {}; /// Factory type name static const String FACTORY_TYPE_NAME; SceneManager* createInstance(const String& instanceName); void destroyInstance(SceneManager* instance); }; } // namespace Ogre #endif // _BvHierarchySceneManager_H__