[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"
|
---|
[2183] | 15 | #include "VisibilityInfo.h"
|
---|
[2280] | 16 | #include "VisibilityMesh.h"
|
---|
[675] | 17 |
|
---|
[2123] | 18 |
|
---|
| 19 | namespace GtpVisibilityPreprocessor {
|
---|
| 20 | class Intersectable;
|
---|
| 21 | }
|
---|
| 22 |
|
---|
| 23 | class ObjReader;
|
---|
| 24 |
|
---|
[2183] | 25 |
|
---|
[675] | 26 | namespace Ogre {
|
---|
| 27 |
|
---|
[1593] | 28 |
|
---|
[2280] | 29 | /** This class extends the terrain scene manager, using occlusion queries for
|
---|
| 30 | visibility culling.
|
---|
[675] | 31 | */
|
---|
| 32 | class __declspec(dllexport) OcclusionCullingSceneManager: public TerrainSceneManager
|
---|
| 33 | {
|
---|
| 34 | public:
|
---|
[2123] | 35 | OcclusionCullingSceneManager(const String& name,
|
---|
| 36 | GtpVisibility::VisibilityManager *visManager);
|
---|
[675] | 37 | ~OcclusionCullingSceneManager();
|
---|
| 38 |
|
---|
| 39 | void _renderVisibleObjects();
|
---|
[2164] | 40 | void myFindVisibleObjects(Camera* cam, bool onlyShadowCasters);
|
---|
[675] | 41 | void _updateSceneGraph(Camera* cam);
|
---|
| 42 |
|
---|
| 43 | /** Sets the given option for the SceneManager
|
---|
| 44 | @remarks Options are: "Algorithm", int *;
|
---|
| 45 | */
|
---|
| 46 |
|
---|
| 47 | virtual bool setOption(const String &, const void *);
|
---|
| 48 | /** Gets the given option for the Scene VisibilityManager.
|
---|
| 49 | @remarks
|
---|
| 50 | See setOption
|
---|
| 51 | */
|
---|
| 52 | virtual bool getOption(const String &, void *);
|
---|
| 53 |
|
---|
| 54 | bool getOptionValues(const String & key, StringVector &refValueList);
|
---|
| 55 | bool getOptionKeys(StringVector &refKeys);
|
---|
| 56 |
|
---|
| 57 | /** Sets the visibility manager.
|
---|
| 58 | @param visManager the visibility manager
|
---|
| 59 | */
|
---|
| 60 | void setVisibilityManager(GtpVisibility::VisibilityManager *visManager);
|
---|
| 61 | /** See set.
|
---|
| 62 | */
|
---|
| 63 | GtpVisibility::VisibilityManager *getVisibilityManager();
|
---|
| 64 |
|
---|
[925] | 65 | /** Render a queue group.
|
---|
[675] | 66 | Override so we can handle delayed rendering of transparent objects
|
---|
| 67 | */
|
---|
[925] | 68 | void renderBasicQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
| 69 | QueuedRenderableCollection::OrganisationMode om);
|
---|
[675] | 70 |
|
---|
| 71 | /** Writes out stats into the Ogre log file.
|
---|
| 72 | */
|
---|
| 73 | void WriteLog();
|
---|
| 74 |
|
---|
| 75 | /** Override pass so we can do the z-fail pass.
|
---|
| 76 | */
|
---|
[1221] | 77 | virtual const Pass* _setPass(const Pass* pass, bool evenIfSuppressed = false);
|
---|
[675] | 78 |
|
---|
| 79 | /** Override from SceneManager so we can skip all but first pass for depth pass.
|
---|
| 80 | */
|
---|
| 81 | bool validatePassForRendering(Pass* pass);
|
---|
[2123] | 82 |
|
---|
[897] | 83 | #ifdef ITEM_BUFFER
|
---|
[675] | 84 | void RenderItemBuffer(RenderPriorityGroup* pGroup);
|
---|
| 85 | void RenderSingleObjectForItemBuffer(Renderable *rend, Pass *pass);
|
---|
[897] | 86 | #endif // ITEM_BUFFER
|
---|
[2123] | 87 |
|
---|
[897] | 88 | void _renderQueueGroupObjects(RenderQueueGroup* pGroup,
|
---|
[2123] | 89 | QueuedRenderableCollection::OrganisationMode om);
|
---|
[675] | 90 |
|
---|
[2123] | 91 | /** Override from SceneManager so that sub entities can be assigned
|
---|
| 92 | an id for item buffer.
|
---|
[675] | 93 | */
|
---|
| 94 | Entity* createEntity(const String& entityName, const String& meshName);
|
---|
| 95 |
|
---|
| 96 | /** Returns pointer to visibility manager.
|
---|
| 97 | */
|
---|
| 98 | GtpVisibility::VisibilityManager *GetVisibilityManager();
|
---|
| 99 |
|
---|
| 100 | /** Returns hierarchy interface.
|
---|
| 101 | */
|
---|
| 102 | OctreeHierarchyInterface *GetHierarchyInterface();
|
---|
| 103 |
|
---|
[897] | 104 | /** Inherited from scene manager. Neccesary to draw terrain properly.
|
---|
[675] | 105 | */
|
---|
| 106 | void endFrame();
|
---|
| 107 |
|
---|
[2123] | 108 | void renderAdditiveStencilShadowedQueueGroupObjects(
|
---|
| 109 | RenderQueueGroup* pGroup,
|
---|
| 110 | QueuedRenderableCollection::OrganisationMode om);
|
---|
| 111 | void renderModulativeStencilShadowedQueueGroupObjects(
|
---|
| 112 | RenderQueueGroup* pGroup,
|
---|
| 113 | QueuedRenderableCollection::OrganisationMode om);
|
---|
[931] | 114 |
|
---|
[675] | 115 | /** Override standard function so octree boxes are always of equal side length.
|
---|
| 116 | This has advantages for CHC, because terrain tiles are in different octree nodes
|
---|
| 117 | and can be culled.
|
---|
[897] | 118 | msz: Modified to reflect changes in Ogre::TerrainSceneManager
|
---|
[675] | 119 | */
|
---|
[925] | 120 | #if 1
|
---|
[1816] | 121 | virtual void setWorldGeometry(DataStreamPtr& stream, const String& typeName);
|
---|
[925] | 122 | #endif
|
---|
[897] | 123 |
|
---|
[828] | 124 | /** Loads view cells for this particular scene.
|
---|
| 125 | */
|
---|
[938] | 126 | bool LoadViewCells(const String &filename);
|
---|
[828] | 127 |
|
---|
[2171] | 128 | void RenderDepthForQuery(Camera* camera, Viewport* vp);
|
---|
| 129 |
|
---|
[2183] | 130 | void _findVisibleObjects(Camera* cam, bool onlyShadowCasters);
|
---|
| 131 |
|
---|
[675] | 132 | protected:
|
---|
| 133 |
|
---|
[2123] | 134 | void MailPvsObjects();
|
---|
| 135 | void RenderPvsEntry(GtpVisibilityPreprocessor::Intersectable *obj);
|
---|
| 136 | void SetObjectVisible(GtpVisibilityPreprocessor::Intersectable *entry,
|
---|
| 137 | const bool visible);
|
---|
[2171] | 138 |
|
---|
[2123] | 139 | void ShowViewCellsGeometry();
|
---|
| 140 |
|
---|
[675] | 141 | /** Creates material for depth pass, e.g., a pass that only fills the depth buffer.
|
---|
| 142 | */
|
---|
| 143 | void InitDepthPass();
|
---|
| 144 | /** Creates material for item buffer.
|
---|
| 145 | */
|
---|
| 146 | void InitItemBufferPass();
|
---|
| 147 | /** Fills render queue so that a visualization can be rendered.
|
---|
| 148 | */
|
---|
| 149 | void PrepareVisualization(Camera *cam);
|
---|
| 150 | /** Initialises necessary parameters for hierarchical visibility culling.
|
---|
| 151 | */
|
---|
| 152 | void InitVisibilityCulling(Camera *cam);
|
---|
[903] | 153 | /** Loads / unloads pvs of the view cell to set the visibility in the scene.
|
---|
| 154 | */
|
---|
[1593] | 155 | void ApplyViewCellPvs(GtpVisibilityPreprocessor::ViewCell *vc, const bool load);
|
---|
[903] | 156 |
|
---|
| 157 | /** updates pvs in current frame.
|
---|
| 158 | */
|
---|
[1593] | 159 | void UpdatePvs(Camera *cam);
|
---|
[903] | 160 |
|
---|
| 161 | /** Sets all objects invisible.
|
---|
| 162 | */
|
---|
| 163 | void SetObjectsVisible(const bool visible);
|
---|
| 164 |
|
---|
[1593] | 165 | /** Creates view cells geometry from the loaded view cells.
|
---|
| 166 | */
|
---|
| 167 | void CreateViewCellsGeometry();
|
---|
[1602] | 168 | void VisualizeViewCells(const bool visualize);
|
---|
[1593] | 169 |
|
---|
[2119] | 170 | /** Load an iv scene.
|
---|
| 171 | */
|
---|
[1816] | 172 | bool LoadSceneIV(const String &filename,
|
---|
| 173 | SceneNode *root,
|
---|
| 174 | const int index);
|
---|
| 175 |
|
---|
[2119] | 176 | /** Load obj scene.
|
---|
| 177 | */
|
---|
| 178 | bool LoadSceneObj(const String &filename,
|
---|
| 179 | const String &viewCellsFile,
|
---|
| 180 | SceneNode *root);
|
---|
[1816] | 181 |
|
---|
[2119] | 182 | /** Load a scene.
|
---|
| 183 | */
|
---|
[2160] | 184 | bool LoadScene(const String &filename,
|
---|
| 185 | const String &viewCellsFilename);
|
---|
[2119] | 186 |
|
---|
[1816] | 187 | void loadConfig(DataStreamPtr& stream);
|
---|
| 188 |
|
---|
[2254] | 189 | void RenderHierarchicalCulling(const bool fillRenderQueue = true);
|
---|
[2160] | 190 |
|
---|
| 191 | void _renderScene(Camera* camera, Viewport* vp, bool includeOverlays);
|
---|
| 192 |
|
---|
[2255] | 193 | int QueryVisibleObjectsExact(Camera *camera,
|
---|
| 194 | Viewport* vp,
|
---|
| 195 | const bool fromPoint,
|
---|
| 196 | const bool nodeVisibility);
|
---|
[2171] | 197 |
|
---|
[2280] | 198 | void AddVisibleMeshGeometryToQueue(const MeshInfoContainer &visibleGeometry,
|
---|
[2254] | 199 | Camera *cam);
|
---|
[2280] | 200 |
|
---|
| 201 | void AddVisibleNodeGeometryToQueue(const NodeInfoContainer &visibleNodes,
|
---|
[2254] | 202 | Camera *cam);
|
---|
[2183] | 203 |
|
---|
[1221] | 204 | //////////////////////////////////////////
|
---|
| 205 |
|
---|
[675] | 206 | /// the interface to the scene hierarchy.
|
---|
| 207 | OctreeHierarchyInterface *mHierarchyInterface;
|
---|
[1593] | 208 |
|
---|
[675] | 209 | /// manages all visibility options
|
---|
| 210 | GtpVisibility::VisibilityManager *mVisibilityManager;
|
---|
| 211 |
|
---|
| 212 | /// if a visualization of the hierarchical culling is shown
|
---|
| 213 | bool mShowVisualization;
|
---|
| 214 |
|
---|
| 215 | /// if the culled nodes are indicated in the visualization
|
---|
| 216 | bool mVisualizeCulledNodes;
|
---|
| 217 |
|
---|
| 218 | /// if symbols for the nodes are shown in the visualization
|
---|
| 219 | bool mRenderNodesForViz;
|
---|
| 220 | /// if content of the nodes is shown in the visualization
|
---|
| 221 | bool mRenderNodesContentForViz;
|
---|
| 222 |
|
---|
[2360] | 223 | bool mRenderPvsForViz;
|
---|
| 224 |
|
---|
[903] | 225 | /// render transparents after the hierarchical traversal
|
---|
[675] | 226 | bool mDelayRenderTransparents;
|
---|
| 227 |
|
---|
[903] | 228 | /// use a depth pass (i.e., fill only the depth buffer in the first pass)
|
---|
[675] | 229 | bool mUseDepthPass;
|
---|
[903] | 230 | /// flag indicating if we currently render the depth pass
|
---|
[675] | 231 | bool mIsDepthPassPhase;
|
---|
| 232 |
|
---|
| 233 | /// if we use an item buffer for rendering (i.e., object ids as color codes
|
---|
| 234 | bool mUseItemBuffer;
|
---|
| 235 | /// if we currently render the item buffer
|
---|
| 236 | bool mIsItemBufferPhase;
|
---|
| 237 |
|
---|
| 238 | /// if depth write should be enabled
|
---|
| 239 | bool mEnableDepthWrite;
|
---|
| 240 | /// if transparents are skipped during rendering
|
---|
| 241 | bool mSkipTransparents;
|
---|
| 242 |
|
---|
| 243 | /// the depth pass (no lighting, just filling the depth buffer)
|
---|
| 244 | Pass *mDepthPass;
|
---|
[1593] | 245 | /// the pass for item buffer setting a color id
|
---|
[675] | 246 | Pass *mItemBufferPass;
|
---|
| 247 |
|
---|
| 248 | /// flag for passes which should not be deleted from queue during first traversal
|
---|
| 249 | int mLeavePassesInQueue;
|
---|
| 250 |
|
---|
| 251 | /// if transparent object are considered for item buffer visibility
|
---|
| 252 | bool mRenderTransparentsForItemBuffer;
|
---|
| 253 | /// Always execute the vertex program of a pass, e.g., for the depth pass or item buffer
|
---|
| 254 | bool mExecuteVertexProgramForAllPasses;
|
---|
[863] | 255 | /// if hierarchical culling is currently in use
|
---|
[675] | 256 | bool mIsHierarchicalCulling;
|
---|
[828] | 257 |
|
---|
[1593] | 258 | /// do we use preprocessed visibility
|
---|
[903] | 259 | bool mViewCellsLoaded;
|
---|
[1593] | 260 | /// the view cells manager handling the preprocesor stuff
|
---|
[863] | 261 | GtpVisibilityPreprocessor::ViewCellsManager *mViewCellsManager;
|
---|
[903] | 262 | /// Used to assign Ogre meshes to view cell entries.
|
---|
| 263 | GtpVisibilityPreprocessor::ObjectContainer mObjects;
|
---|
| 264 |
|
---|
[2502] | 265 | /// the currently visible view cell
|
---|
[903] | 266 | GtpVisibilityPreprocessor::ViewCell *mCurrentViewCell;
|
---|
| 267 |
|
---|
[2502] | 268 | /// If view cells + PVS is used for rendering.
|
---|
[903] | 269 | bool mUseViewCells;
|
---|
| 270 |
|
---|
[1606] | 271 | /// if view cells visualization should be shown
|
---|
| 272 | bool mShowViewCells;
|
---|
| 273 |
|
---|
[2502] | 274 | /// if render queue should be flushed occasionally
|
---|
[1251] | 275 | bool mDeleteQueueAfterRendering;
|
---|
[1276] | 276 |
|
---|
| 277 | // normal terrain rendering
|
---|
| 278 | bool mNormalExecution;
|
---|
[1593] | 279 |
|
---|
| 280 | // helper variable to provide sequential numbering for sub-entities
|
---|
| 281 | int mCurrentEntityId;
|
---|
| 282 |
|
---|
[1616] | 283 | typedef map<int, MovableObject *> MovableMap;
|
---|
[1593] | 284 |
|
---|
| 285 | /// hash table for view cells geometry
|
---|
[1616] | 286 | MovableMap mViewCellsGeometry;
|
---|
| 287 |
|
---|
| 288 | bool mViewCellsGeometryLoaded;
|
---|
[1816] | 289 |
|
---|
[1823] | 290 | string mViewCellsFilename;
|
---|
| 291 | string mFilename;
|
---|
| 292 |
|
---|
[1816] | 293 | bool mShowTerrain;
|
---|
[2123] | 294 |
|
---|
[2145] | 295 | int mFlushRate;
|
---|
| 296 | int mCurrentFrame;
|
---|
| 297 |
|
---|
[2255] | 298 | int mQueryMode;
|
---|
| 299 |
|
---|
| 300 | enum {EXACT_QUERIES, NODE_QUERIES, APPROXIMATE_QUERIES};
|
---|
| 301 |
|
---|
[2123] | 302 | ObjReader *mObjReader;
|
---|
[2184] | 303 |
|
---|
[2254] | 304 | bool mUseVisibilityQueries;
|
---|
| 305 |
|
---|
| 306 | bool mUseFromPointQueries;
|
---|
| 307 |
|
---|
[2255] | 308 | bool mResetMaterialForQueries;
|
---|
[675] | 309 | };
|
---|
| 310 |
|
---|
[1593] | 311 |
|
---|
| 312 | /** Factory for VisibilityOctreeSceneManager.
|
---|
| 313 | */
|
---|
[903] | 314 | class OcclusionCullingSceneManagerFactory : public SceneManagerFactory
|
---|
| 315 | {
|
---|
| 316 | protected:
|
---|
[925] | 317 | typedef std::vector<TerrainPageSource*> TerrainPageSources;
|
---|
| 318 | TerrainPageSources mTerrainPageSources;
|
---|
[903] | 319 | void initMetaData(void) const;
|
---|
| 320 | GtpVisibility::VisibilityManager *visManager;
|
---|
| 321 | public:
|
---|
| 322 | OcclusionCullingSceneManagerFactory(GtpVisibility::VisibilityManager *vm)
|
---|
| 323 | {
|
---|
| 324 | visManager = vm;
|
---|
| 325 | }
|
---|
[925] | 326 |
|
---|
[903] | 327 | /// Factory type name
|
---|
| 328 | static const String FACTORY_TYPE_NAME;
|
---|
| 329 | SceneManager* createInstance(const String& instanceName);
|
---|
| 330 | void destroyInstance(SceneManager* instance);
|
---|
| 331 | };
|
---|
| 332 |
|
---|
[675] | 333 | } // namespace Ogre
|
---|
| 334 |
|
---|
[903] | 335 | #endif // OcclusionCullingSceneManager_H |
---|