#ifndef _OcclusionCullingSceneManager_H__ #define _OcclusionCullingSceneManager_H__ #include #include #include #include #include #include #include "OgreOctreeHierarchyInterface.h" #include "OgrePlatformQueryManager.h" #include "VisibilityManager.h" #include "Containers.h" #include "ViewCellsManager.h" namespace Ogre { /** This class extends the terrain scene manager, using occlusion queries for visibility culling. */ class __declspec(dllexport) OcclusionCullingSceneManager: public TerrainSceneManager { public: OcclusionCullingSceneManager(const String& name, GtpVisibility::VisibilityManager *visManager); ~OcclusionCullingSceneManager(); void _renderVisibleObjects(); void _findVisibleObjects(Camera* cam, bool onlyShadowCasters); void _updateSceneGraph(Camera* cam); /** Sets the given option for the SceneManager @remarks Options are: "Algorithm", int *; */ virtual bool setOption(const String &, const void *); /** Gets the given option for the Scene VisibilityManager. @remarks See setOption */ virtual bool getOption(const String &, void *); bool getOptionValues(const String & key, StringVector &refValueList); bool getOptionKeys(StringVector &refKeys); /** Sets the visibility manager. @param visManager the visibility manager */ void setVisibilityManager(GtpVisibility::VisibilityManager *visManager); /** See set. */ GtpVisibility::VisibilityManager *getVisibilityManager(); /** Render a queue group. Override so we can handle delayed rendering of transparent objects */ void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om); /** Writes out stats into the Ogre log file. */ void WriteLog(); /** Override pass so we can do the z-fail pass. */ virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false); /** Override from SceneManager so we can skip all but first pass for depth pass. */ bool validatePassForRendering(Pass* pass); #ifdef ITEM_BUFFER void RenderItemBuffer(RenderPriorityGroup* pGroup); void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass); #endif // ITEM_BUFFER void _renderQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om); /** Override from SceneManager so that sub entities can be assigned an id for item buffer. */ Entity* createEntity(const String& entityName, const String& meshName); /** Returns pointer to visibility manager. */ GtpVisibility::VisibilityManager *GetVisibilityManager(); /** Returns hierarchy interface. */ OctreeHierarchyInterface *GetHierarchyInterface(); /** Inherited from scene manager. Neccesary to draw terrain properly. */ void endFrame(); void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om); void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup, QueuedRenderableCollection::OrganisationMode om); /** Override standard function so octree boxes are always of equal side length. This has advantages for CHC, because terrain tiles are in different octree nodes and can be culled. msz: Modified to reflect changes in Ogre::TerrainSceneManager */ #if 1 virtual void setWorldGeometry(DataStreamPtr& stream, const String& typeName); #endif /** Loads view cells for this particular scene. */ bool LoadViewCells(const String &filename); 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); /** 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); /** Creates view cells geometry from the loaded view cells. */ void CreateViewCellsGeometry(); void VisualizeViewCells(const bool visualize); bool LoadSceneIV(const String &filename, SceneNode *root, const int index); bool LoadScene(const String &filename); void loadConfig(DataStreamPtr& stream); ////////////////////////////////////////// /// the interface to the scene hierarchy. OctreeHierarchyInterface *mHierarchyInterface; /// manages all visibility options GtpVisibility::VisibilityManager *mVisibilityManager; /// if a visualization of the hierarchical culling is shown bool mShowVisualization; /// if the culled nodes are indicated in the visualization bool mVisualizeCulledNodes; /// 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; /// 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 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; /// if depth write should be enabled bool mEnableDepthWrite; /// if transparents are skipped during rendering bool mSkipTransparents; /// the depth pass (no lighting, just filling the depth buffer) Pass *mDepthPass; /// the pass for item buffer setting a color id Pass *mItemBufferPass; /// flag for passes which should not be deleted from queue during first traversal int mLeavePassesInQueue; /// 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; /// if hierarchical culling is currently in use bool mIsHierarchicalCulling; /// do we use preprocessed visibility bool mViewCellsLoaded; /// the view cells manager handling the preprocesor stuff 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 used. bool mUseViewCells; /// if view cells visualization should be shown bool mShowViewCells; /// if the view cells are filtered bool mUseVisibilityFilter; bool mDeleteQueueAfterRendering; // normal terrain rendering bool mNormalExecution; // helper variable to provide sequential numbering for sub-entities int mCurrentEntityId; typedef map MovableMap; /// hash table for view cells geometry MovableMap mViewCellsGeometry; bool mViewCellsGeometryLoaded; string mViewCellsFilename; string mFilename; bool mShowTerrain; }; /** Factory for VisibilityOctreeSceneManager. */ class OcclusionCullingSceneManagerFactory : public SceneManagerFactory { protected: typedef std::vector TerrainPageSources; TerrainPageSources mTerrainPageSources; void initMetaData(void) const; GtpVisibility::VisibilityManager *visManager; public: OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm) { visManager = vm; } /// Factory type name static const String FACTORY_TYPE_NAME; SceneManager* createInstance(const String& instanceName); void destroyInstance(SceneManager* instance); }; } // namespace Ogre #endif // OcclusionCullingSceneManager_H