[675] | 1 | #ifndef _OcclusionCullingSceneManager_H__
|
---|
| 2 | #define _OcclusionCullingSceneManager_H__
|
---|
| 3 |
|
---|
| 4 | #include <OgreSceneNode.h>
|
---|
| 5 | #include <OgreTerrainSceneManager.h>
|
---|
| 6 | #include <OgreOctreeNode.h>
|
---|
| 7 | #include <OgreOctreeCamera.h>
|
---|
| 8 | #include <OgrePrerequisites.h>
|
---|
[897] | 9 | #include <OgreMovableObject.h>
|
---|
[675] | 10 | #include "OgreOctreeHierarchyInterface.h"
|
---|
| 11 | #include "OgrePlatformQueryManager.h"
|
---|
| 12 | #include "VisibilityManager.h"
|
---|
[897] | 13 | #include "Containers.h"
|
---|
[828] | 14 | #include "ViewCellsManager.h"
|
---|
[675] | 15 |
|
---|
| 16 | namespace Ogre {
|
---|
| 17 |
|
---|
| 18 | /**
|
---|
| 19 | This class extends the terrain scene manager,
|
---|
| 20 | using occlusion queries for visibility culling.
|
---|
| 21 | */
|
---|
| 22 | class __declspec(dllexport) OcclusionCullingSceneManager: public TerrainSceneManager
|
---|
| 23 | {
|
---|
| 24 | public:
|
---|
[897] | 25 | OcclusionCullingSceneManager(const String& name, GtpVisibility::VisibilityManager *visManager);
|
---|
[675] | 26 | ~OcclusionCullingSceneManager();
|
---|
| 27 |
|
---|
| 28 | void _renderVisibleObjects();
|
---|
| 29 | void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
|
---|
| 30 | void _updateSceneGraph(Camera* cam);
|
---|
| 31 |
|
---|
| 32 | /** Sets the given option for the SceneManager
|
---|
| 33 | @remarks Options are: "Algorithm", int *;
|
---|
| 34 | */
|
---|
| 35 |
|
---|
| 36 | virtual bool setOption(const String &, const void *);
|
---|
| 37 | /** Gets the given option for the Scene VisibilityManager.
|
---|
| 38 | @remarks
|
---|
| 39 | See setOption
|
---|
| 40 | */
|
---|
| 41 | virtual bool getOption(const String &, void *);
|
---|
| 42 |
|
---|
| 43 | bool getOptionValues(const String & key, StringVector &refValueList);
|
---|
| 44 | bool getOptionKeys(StringVector &refKeys);
|
---|
| 45 |
|
---|
| 46 | /** Sets the visibility manager.
|
---|
| 47 | @param visManager the visibility manager
|
---|
| 48 | */
|
---|
| 49 | void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
|
---|
| 50 | /** See set.
|
---|
| 51 | */
|
---|
| 52 | GtpVisibility::VisibilityManager *getVisibilityManager();
|
---|
| 53 |
|
---|
[925] | 54 | /** Render a queue group.
|
---|
[675] | 55 | Override so we can handle delayed rendering of transparent objects
|
---|
| 56 | */
|
---|
[925] | 57 | void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 58 | QueuedRenderableCollection::OrganisationMode om);
|
---|
[675] | 59 |
|
---|
| 60 | /** Writes out stats into the Ogre log file.
|
---|
| 61 | */
|
---|
| 62 | void WriteLog();
|
---|
| 63 |
|
---|
| 64 | /** Override pass so we can do the z-fail pass.
|
---|
| 65 | */
|
---|
[1221] | 66 | virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
|
---|
[675] | 67 |
|
---|
| 68 | /** Override from SceneManager so we can skip all but first pass for depth pass.
|
---|
| 69 | */
|
---|
| 70 | bool validatePassForRendering(Pass* pass);
|
---|
[897] | 71 | #ifdef ITEM_BUFFER
|
---|
[675] | 72 | void RenderItemBuffer(RenderPriorityGroup* pGroup);
|
---|
| 73 | void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass);
|
---|
[897] | 74 | #endif // ITEM_BUFFER
|
---|
| 75 | void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 76 | QueuedRenderableCollection::OrganisationMode om);
|
---|
[675] | 77 |
|
---|
| 78 | /** Override from SceneManager so that sub entities can be assigned an id for item buffer.
|
---|
| 79 | */
|
---|
| 80 | Entity* createEntity(const String& entityName, const String& meshName);
|
---|
| 81 |
|
---|
| 82 | /** Returns pointer to visibility manager.
|
---|
| 83 | */
|
---|
| 84 | GtpVisibility::VisibilityManager *GetVisibilityManager();
|
---|
| 85 |
|
---|
| 86 | /** Returns hierarchy interface.
|
---|
| 87 | */
|
---|
| 88 | OctreeHierarchyInterface *GetHierarchyInterface();
|
---|
| 89 |
|
---|
[897] | 90 | /** Inherited from scene manager. Neccesary to draw terrain properly.
|
---|
[675] | 91 | */
|
---|
| 92 | void endFrame();
|
---|
| 93 |
|
---|
[897] | 94 | void renderAdditiveStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 95 | QueuedRenderableCollection::OrganisationMode om);
|
---|
| 96 | void renderModulativeStencilShadowedQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 97 | QueuedRenderableCollection::OrganisationMode om);
|
---|
[931] | 98 |
|
---|
[675] | 99 | /** Override standard function so octree boxes are always of equal side length.
|
---|
| 100 | This has advantages for CHC, because terrain tiles are in different octree nodes
|
---|
| 101 | and can be culled.
|
---|
[897] | 102 | msz: Modified to reflect changes in Ogre::TerrainSceneManager
|
---|
[675] | 103 | */
|
---|
[925] | 104 | #if 1
|
---|
[897] | 105 | virtual void setWorldGeometry( DataStreamPtr& stream, const String& typeName );
|
---|
[925] | 106 | #endif
|
---|
[897] | 107 |
|
---|
[828] | 108 | /** Loads view cells for this particular scene.
|
---|
| 109 | */
|
---|
[938] | 110 | bool LoadViewCells(const String &filename);
|
---|
[828] | 111 |
|
---|
[675] | 112 | protected:
|
---|
| 113 |
|
---|
| 114 | /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
|
---|
| 115 | */
|
---|
| 116 | void InitDepthPass();
|
---|
| 117 | /** Creates material for item buffer.
|
---|
| 118 | */
|
---|
| 119 | void InitItemBufferPass();
|
---|
| 120 | /** Fills render queue so that a visualization can be rendered.
|
---|
| 121 | */
|
---|
| 122 | void PrepareVisualization(Camera *cam);
|
---|
| 123 | /** Initialises necessary parameters for hierarchical visibility culling.
|
---|
| 124 | */
|
---|
| 125 | void InitVisibilityCulling(Camera *cam);
|
---|
[903] | 126 | /** Loads / unloads pvs of the view cell to set the visibility in the scene.
|
---|
| 127 | */
|
---|
| 128 | void applyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
|
---|
| 129 |
|
---|
| 130 | /** updates pvs in current frame.
|
---|
| 131 | */
|
---|
| 132 | void updatePvs(Camera *cam);
|
---|
| 133 |
|
---|
| 134 | /** Sets all objects invisible.
|
---|
| 135 | */
|
---|
| 136 | void SetObjectsVisible(const bool visible);
|
---|
| 137 |
|
---|
[1221] | 138 |
|
---|
| 139 | //////////////////////////////////////////
|
---|
| 140 |
|
---|
[675] | 141 | /// the interface to the scene hierarchy.
|
---|
| 142 | OctreeHierarchyInterface *mHierarchyInterface;
|
---|
| 143 | /// manages all visibility options
|
---|
| 144 | GtpVisibility::VisibilityManager *mVisibilityManager;
|
---|
| 145 |
|
---|
| 146 | /// if a visualization of the hierarchical culling is shown
|
---|
| 147 | bool mShowVisualization;
|
---|
| 148 |
|
---|
| 149 | /// if the culled nodes are indicated in the visualization
|
---|
| 150 | bool mVisualizeCulledNodes;
|
---|
| 151 |
|
---|
| 152 | /// if symbols for the nodes are shown in the visualization
|
---|
| 153 | bool mRenderNodesForViz;
|
---|
| 154 | /// if content of the nodes is shown in the visualization
|
---|
| 155 | bool mRenderNodesContentForViz;
|
---|
| 156 |
|
---|
[903] | 157 | /// render transparents after the hierarchical traversal
|
---|
[675] | 158 | bool mDelayRenderTransparents;
|
---|
| 159 |
|
---|
[903] | 160 | /// use a depth pass (i.e., fill only the depth buffer in the first pass)
|
---|
[675] | 161 | bool mUseDepthPass;
|
---|
[903] | 162 | /// flag indicating if we currently render the depth pass
|
---|
[675] | 163 | bool mIsDepthPassPhase;
|
---|
| 164 |
|
---|
| 165 | /// if we use an item buffer for rendering (i.e., object ids as color codes
|
---|
| 166 | bool mUseItemBuffer;
|
---|
| 167 | /// if we currently render the item buffer
|
---|
| 168 | bool mIsItemBufferPhase;
|
---|
| 169 |
|
---|
| 170 | /// if depth write should be enabled
|
---|
| 171 | bool mEnableDepthWrite;
|
---|
| 172 | /// if transparents are skipped during rendering
|
---|
| 173 | bool mSkipTransparents;
|
---|
| 174 |
|
---|
| 175 | /// the depth pass (no lighting, just filling the depth buffer)
|
---|
| 176 | Pass *mDepthPass;
|
---|
| 177 | Pass *mItemBufferPass;
|
---|
| 178 |
|
---|
| 179 | int mCurrentEntityId;
|
---|
| 180 | /// flag for passes which should not be deleted from queue during first traversal
|
---|
| 181 | int mLeavePassesInQueue;
|
---|
| 182 |
|
---|
[868] | 183 |
|
---|
[675] | 184 | /// if transparent object are considered for item buffer visibility
|
---|
| 185 | bool mRenderTransparentsForItemBuffer;
|
---|
| 186 | /// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
|
---|
| 187 | bool mExecuteVertexProgramForAllPasses;
|
---|
[868] | 188 |
|
---|
[863] | 189 | /// if hierarchical culling is currently in use
|
---|
[675] | 190 | bool mIsHierarchicalCulling;
|
---|
[828] | 191 |
|
---|
[903] | 192 | bool mViewCellsLoaded;
|
---|
[863] | 193 | GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
|
---|
[903] | 194 |
|
---|
| 195 |
|
---|
| 196 | /// Used to assign Ogre meshes to view cell entries.
|
---|
| 197 | GtpVisibilityPreprocessor::ObjectContainer mObjects;
|
---|
| 198 |
|
---|
| 199 | GtpVisibilityPreprocessor::ViewCell *mElementaryViewCell;
|
---|
| 200 | GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
|
---|
| 201 |
|
---|
| 202 | /// If view cells are used.
|
---|
| 203 | bool mUseViewCells;
|
---|
| 204 |
|
---|
| 205 | /// if the view cells are filtered
|
---|
| 206 | bool mUseVisibilityFilter;
|
---|
[1251] | 207 |
|
---|
| 208 | bool mDeleteQueueAfterRendering;
|
---|
[1276] | 209 |
|
---|
| 210 | // normal terrain rendering
|
---|
| 211 | bool mNormalExecution;
|
---|
[675] | 212 | };
|
---|
| 213 |
|
---|
[903] | 214 | /// Factory for VisibilityOctreeSceneManager
|
---|
| 215 | class OcclusionCullingSceneManagerFactory : public SceneManagerFactory
|
---|
| 216 | {
|
---|
| 217 | protected:
|
---|
[925] | 218 | typedef std::vector<TerrainPageSource*> TerrainPageSources;
|
---|
| 219 | TerrainPageSources mTerrainPageSources;
|
---|
[903] | 220 | void initMetaData(void) const;
|
---|
| 221 | GtpVisibility::VisibilityManager *visManager;
|
---|
| 222 | public:
|
---|
| 223 | OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
|
---|
| 224 | {
|
---|
| 225 | visManager = vm;
|
---|
| 226 | }
|
---|
[925] | 227 |
|
---|
[903] | 228 | /// Factory type name
|
---|
| 229 | static const String FACTORY_TYPE_NAME;
|
---|
| 230 | SceneManager* createInstance(const String& instanceName);
|
---|
| 231 | void destroyInstance(SceneManager* instance);
|
---|
| 232 | };
|
---|
| 233 |
|
---|
[675] | 234 | } // namespace Ogre
|
---|
| 235 |
|
---|
[903] | 236 | #endif // OcclusionCullingSceneManager_H |
---|