Changeset 22
- Timestamp:
- 03/21/05 01:59:03 (20 years ago)
- Location:
- trunk/VUT
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCulling.vcproj
r18 r22 22 22 Optimization="0" 23 23 AdditionalIncludeDirectories=""$(OGRE_PATH)\Dependencies\include";"$(OGRE_PATH)\OgreMain\include";"$(OGRE_PATH)\Samples\Common\include";"$(OGRE_PATH)\Dependencies\include\CEGUI";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include"" 24 PreprocessorDefinitions="_WINDOWS ,_STLP_USE_DYNAMIC_LIB,OGRE_LIBRARY_IMPORTS,_DEBUG,WIN32,_STLP_DEBUG"24 PreprocessorDefinitions="_WINDOWS;_STLP_USE_DYNAMIC_LIB;OGRE_LIBRARY_IMPORTS;_DEBUG;WIN32;_STLP_DEBUG;OGRE_COHERENT_OCCLUSION_CULLING" 25 25 MinimalRebuild="TRUE" 26 26 BasicRuntimeChecks="3" -
trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h
r21 r22 28 28 29 29 typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue; 30 30 typedef queue<SceneNode *> QueryQueue; 31 31 /** 32 32 Class which implements a scene mangager which uses occlusion queries for culling occluded objects … … 36 36 public: 37 37 enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES}; 38 38 39 39 OcclusionCullingSceneManager(); 40 ~OcclusionCullingSceneManager(); 40 41 41 42 /** Overriden from SceneManager. */ 42 43 void _renderVisibleObjects(void); 43 44 void _findVisibleObjects(Camera* cam, bool onlyShadowCasters); 44 45 void _updateSceneGraph(Camera* cam); 46 45 47 protected: 48 enum {MODE_QUERY, MODE_RENDER}; 46 49 50 int isLeaf(SceneNode *node); 51 int countSceneNodes(SceneNode *node); 47 52 void renderZPass(); 48 53 void traverseNode(SceneNode *node); 49 void renderSceneNode(SceneNode *node); 50 void switchMode(bool switch2QueryMode); 54 /** Renders current node */ 55 void render(SceneNode *node); 56 /** Sets rendering mode, e.g. query mode or render mode*/ 57 void setRenderingMode(int mode); 51 58 59 /** Renders the scene with view frustum culling only. */ 60 void renderCullFrustum(); 61 /** Renders the scene with the hierarchical stop and wait algorithm. */ 52 62 void renderStopAndWait(); 53 /** renders the scene with view frustum culling only */ 54 void renderCullFrustum(); 63 /** Renders the scene with the coherent hierarchical algorithm and the query queye. */ 64 void renderCoherentWithQueue(); 65 /** Issue a occlusion query for this node. */ 66 void issueOcclusionQuery(SceneNode *node, bool wasVisible); 67 /** Pulls up the visibility from the child nodes. */ 68 void pullUpVisibility(SceneNode *node); 55 69 56 void issueOcclusionQuery(SceneNode *node, bool wasVisible);70 void deleteQueries(); 57 71 58 72 /** we use a priority queue rather than a renderstack */ 59 73 PriorityQueue *mDistanceQueue; 60 // RenderQueue* mDistanceQueue;61 74 62 int mFrameID; 63 int mVisibilityThreshold; 75 unsigned int mFrameID; 76 unsigned int mVisibilityThreshold; 77 unsigned int mNumSceneNodes; 64 78 int mCurrentTestIdx; 65 bool mIsQueryMode;66 79 int mQueryMode; 80 67 81 std::vector<HardwareOcclusionQuery *> mOcclusionQueries; 68 82 }; -
trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj
r18 r22 21 21 Optimization="0" 22 22 AdditionalIncludeDirectories=""$(OGRE_PATH)\Samples\Common\include";"$(OGRE_PATH)\Dependencies\include\CEGUI";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\include";"$(OGRE_PATH)\OgreMain\include";"$(OGRE_PATH)\Dependencies\include";..\include" 23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PLUGIN_OCCLUSIONCULLINGSCENEMANAGER_EXPORTS "23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PLUGIN_OCCLUSIONCULLINGSCENEMANAGER_EXPORTS;OGRE_COHERENT_OCCLUSION_CULLING" 24 24 MinimalRebuild="TRUE" 25 25 BasicRuntimeChecks="3" -
trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp
r21 r22 13 13 OcclusionCullingSceneManager::OcclusionCullingSceneManager(): 14 14 mFrameID(1), mDistanceQueue(NULL), mVisibilityThreshold(0), mCurrentTestIdx(0), 15 m IsQueryMode(false)15 mQueryMode(MODE_RENDER), mNumSceneNodes(0) 16 16 { 17 17 } 18 18 //----------------------------------------------------------------------- 19 19 void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters) 20 20 { 21 21 // empty because we have to find in _renderVisibleObjects 22 22 } 23 23 //----------------------------------------------------------------------- 24 OcclusionCullingSceneManager::~OcclusionCullingSceneManager() 25 { 26 deleteQueries(); 27 SceneManager::~SceneManager(); 28 } 24 29 //----------------------------------------------------------------------- 25 30 void OcclusionCullingSceneManager::_renderVisibleObjects(void) 26 31 { 27 32 mDistanceQueue = new PriorityQueue(myless<SceneNode *>(mCameraInProgress)); 33 28 34 mDistanceQueue->push(mSceneRoot); 29 35 //renderZPass(); 30 renderCullFrustum(); 36 //renderCullFrustum(); 37 renderCoherentWithQueue(); 31 38 delete mDistanceQueue; 32 //mDestRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS); 33 //SceneManager::_renderVisibleObjects(); 34 //mDestRenderSystem->_setDepthBufferParams(); 35 //mDistanceQueue.push(mSceneRoot); 36 //Preprocess(); 37 38 //renderCullFrustum(); 39 40 //mFrameID ++; 41 //ResetQueries(); 42 } 43 39 40 /*mDestRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS); 41 SceneManager::_renderVisibleObjects(); 42 mDestRenderSystem->_setDepthBufferParams(); 43 mDistanceQueue.push(mSceneRoot); 44 Preprocess(); 45 //ResetQueries(); 46 */ 47 48 mFrameID ++; 49 } 44 50 //----------------------------------------------------------------------- 45 51 void OcclusionCullingSceneManager::renderZPass() … … 47 53 traverseNode(mSceneRoot); 48 54 } 49 55 //----------------------------------------------------------------------- 56 void OcclusionCullingSceneManager::renderCoherentWithQueue() 57 { 58 QueryQueue queryQueue; 59 60 //-- PART 1: process finished occlusion queries 61 while(!mDistanceQueue->empty() || !queryQueue.empty()) 62 { 63 while(!queryQueue.empty() && 64 (queryQueue.front()->getOcclusionQuery()->resultAvailable() || mDistanceQueue->empty())) 65 { 66 SceneNode *node = queryQueue.front(); 67 queryQueue.pop(); 68 69 // wait until result available 70 unsigned int visiblePixels; 71 node->getOcclusionQuery()->pullOcclusionQuery(&visiblePixels); 72 73 if(visiblePixels > mVisibilityThreshold) 74 { 75 pullUpVisibility(node); 76 traverseNode(node); 77 } 78 } 79 80 //-- PART 2: hierarchical traversal 81 if(!mDistanceQueue->empty()) 82 { 83 SceneNode *node = mDistanceQueue->top(); 84 85 mDistanceQueue->pop(); 86 87 if(mCameraInProgress->isVisible(node->_getWorldAABB())) 88 { 89 // identify previously visible nodes 90 bool wasVisible = node->isNodeVisible() && (node->lastVisited() == mFrameID - 1); 91 92 // identify nodes that we cannot skip queries for 93 bool leafOrWasInvisible = !wasVisible || isLeaf(node); 94 95 // reset node's visibility classification 96 node->setVisible(false); 97 98 // update node's visited flag 99 node->setLastVisited(mFrameID); 100 101 // skip testing previously visible interior nodes 102 if(leafOrWasInvisible) 103 { 104 issueOcclusionQuery(node, wasVisible); 105 queryQueue.push(node); 106 } 107 108 // always traverse a node if it was visible 109 if(wasVisible) 110 traverseNode(node); 111 } 112 } 113 } 114 } 50 115 //----------------------------------------------------------------------- 51 116 void OcclusionCullingSceneManager::renderCullFrustum() … … 67 132 traverseNode(node); 68 133 } 69 //else 70 //MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL); 71 } 72 } 73 74 134 } 135 } 75 136 //----------------------------------------------------------------------- 76 137 void OcclusionCullingSceneManager::renderStopAndWait() … … 81 142 mDistanceQueue->pop(); 82 143 83 // interesting for the visualization , so rest and set144 // interesting for the visualization 84 145 //node->SetVisible(false); 146 node->setLastVisited(15); 85 147 86 148 if(mCameraInProgress->isVisible(node->_getWorldAABB())) … … 100 162 } 101 163 } 102 164 //----------------------------------------------------------------------- 103 165 void OcclusionCullingSceneManager::issueOcclusionQuery(SceneNode *node, bool wasVisible) 104 166 { … … 107 169 108 170 // change state so the bounding box gets not actually rendered on the screen 109 switchMode(false); 110 node->_addBoundingBoxToQueue(getRenderQueue()); 171 setRenderingMode(MODE_QUERY); 172 //HACK: too slow 173 node->_addBoundingBoxToQueue(getRenderQueue()); 111 174 SceneManager::_renderVisibleObjects(); 112 175 getRenderQueue()->clear(); 113 switchMode(true); 114 176 /* static RenderOperation ro; 177 node->getRenderOperation(ro); 178 ro.srcRenderable = node; 179 mDestRenderSystem->_render(ro); */ 180 115 181 mOcclusionQueries[mCurrentTestIdx++]->endOcclusionQuery(); 116 182 } 117 183 118 119 //----------------------------------------------------------------------- 120 void OcclusionCullingSceneManager::switchMode(bool switch2QueryMode) 184 //----------------------------------------------------------------------- 185 void OcclusionCullingSceneManager::setRenderingMode(int mode) 121 186 { 122 // boolean used toavoid unnecessary state changes123 if( switch2QueryMode != mIsQueryMode)124 { 125 mDestRenderSystem->_setColourBufferWriteEnabled(switch2QueryMode,126 switch2QueryMode, switch2QueryMode, switch2QueryMode); 127 mDestRenderSystem->_set DepthBufferWriteEnabled(switch2QueryMode);128 mDestRenderSystem->setLightingEnabled(switch2QueryMode);129 m IsQueryMode = switch2QueryMode;130 }131 }132 133 187 // avoid unnecessary state changes 188 if(mode != mQueryMode) 189 { 190 bool enabled = (mode == MODE_RENDER); 191 192 mDestRenderSystem->_setColourBufferWriteEnabled(enabled, 193 enabled, enabled, enabled); 194 mDestRenderSystem->_setDepthBufferWriteEnabled(enabled); 195 mDestRenderSystem->setLightingEnabled(enabled); 196 mQueryMode = mode; 197 } 198 } 134 199 //----------------------------------------------------------------------- 135 200 void OcclusionCullingSceneManager::traverseNode(SceneNode *node) 136 201 { 137 if( node->numChildren() == 0) // reached leaf138 { 139 render SceneNode(node);202 if(isLeaf(node)) // reached leaf 203 { 204 render(node); 140 205 } 141 206 else // internal node: add children to priority queue for further processing 142 207 { 143 208 Node::ChildNodeIterator it = node->getChildIterator(); 144 char str[100]; sprintf(str, "number of children: %d", node->numChildren()); 145 209 146 210 while (it.hasMoreElements()) 147 211 { … … 151 215 } 152 216 } 153 154 /* 155 static RenderOperation ro; 156 node->getRenderOperation(ro); 157 ro.srcRenderable = node; 158 mDestRenderSystem->_render(ro); 159 Pass pass(); 160 renderSingleObject(node, &pass, true); 161 */ 162 } 163 164 void OcclusionCullingSceneManager::renderSceneNode(SceneNode *node) 165 { 217 } 218 //----------------------------------------------------------------------- 219 void OcclusionCullingSceneManager::render(SceneNode *node) 220 { 221 setRenderingMode(MODE_RENDER); 222 223 //HACK (too slow) 166 224 node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false, 167 225 mDisplayNodes, false); … … 169 227 getRenderQueue()->clear(); 170 228 } 229 //----------------------------------------------------------------------- 230 void OcclusionCullingSceneManager::_updateSceneGraph(Camera* cam) 231 { 232 int numnodes = countSceneNodes(mSceneRoot); 233 //char str[100]; sprintf(str, "number: %d", mNumSceneNodes); 234 //MessageBox( NULL, str, "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL); 235 236 //-- initialise occlusion queries. 237 if(numnodes != mNumSceneNodes) 238 { 239 mNumSceneNodes = numnodes; 240 241 deleteQueries(); 242 243 for(int i=0; i < mNumSceneNodes; i++) 244 { 245 HardwareOcclusionQuery *hw = mDestRenderSystem->createHardwareOcclusionQuery(); 246 mOcclusionQueries.push_back(hw); 247 } 248 } 249 250 SceneManager::_updateSceneGraph(cam); 251 } 252 //----------------------------------------------------------------------- 253 int OcclusionCullingSceneManager::countSceneNodes(SceneNode *node) 254 { 255 int num = 1; 256 if(isLeaf(node)) 257 { 258 return num; 259 } 260 261 Node::ChildNodeIterator it = node->getChildIterator(); 262 263 while (it.hasMoreElements()) 264 { 265 SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext()); 266 num += countSceneNodes(sceneChild); 267 } 268 269 return num; 270 } 271 //----------------------------------------------------------------------- 272 int OcclusionCullingSceneManager::isLeaf(SceneNode *node) 273 { 274 return (node->numChildren() == 0); 275 } 276 //----------------------------------------------------------------------- 277 void OcclusionCullingSceneManager::pullUpVisibility(SceneNode *node) 278 { 279 while(node && !node->isNodeVisible()) 280 { 281 node->setNodeVisible(true); 282 node = static_cast<SceneNode *>(node->getParent()); 283 } 284 } 285 //----------------------------------------------------------------------- 286 void OcclusionCullingSceneManager::deleteQueries() 287 { 288 for(int i=0; i < mNumSceneNodes; i++) 289 delete mOcclusionQueries[i]; 290 291 mOcclusionQueries.clear(); 292 } 171 293 } -
trunk/VUT/chcdemo/RenderTraverser.h
r10 r22 47 47 // several statistics for a rendering pass 48 48 long GetRenderTime(); 49 int 49 int GetNumTraversedNodes(); 50 50 int GetNumQueryCulledNodes(); 51 51 int GetNumFrustumCulledNodes();
Note: See TracChangeset
for help on using the changeset viewer.