Changeset 32
- Timestamp:
- 03/29/05 08:21:37 (20 years ago)
- Location:
- trunk/VUT/OcclusionCullingSceneManager
- Files:
-
- 4 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCulling.vcproj
r29 r32 34 34 <Tool 35 35 Name="VCLinkerTool" 36 AdditionalDependencies="OGREMain_d.LIB CEGUIBase_d.lib OgreGUIRenderer_d.lib "36 AdditionalDependencies="OGREMain_d.LIB CEGUIBase_d.lib OgreGUIRenderer_d.lib Plugin_OctreeSceneManager.lib" 37 37 OutputFile="$(OGRE_PATH)/Samples/Common/bin/Debug/TestCulling.exe" 38 38 LinkIncremental="2" 39 AdditionalLibraryDirectories=""$(OGRE_PATH)\Dependencies\Lib\Debug";"$(OGRE_PATH)\OgreMain\Lib\Debug";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib" "39 AdditionalLibraryDirectories=""$(OGRE_PATH)\Dependencies\Lib\Debug";"$(OGRE_PATH)\OgreMain\Lib\Debug";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib";"$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)"" 40 40 GenerateDebugInformation="TRUE" 41 41 ProgramDatabaseFile="$(OutDir)/TestCulling.pdb" -
trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.cpp
r31 r32 106 106 mRotateSpeed *= 2; 107 107 108 mCurrentAlgorithm = OcclusionCullingSceneManager::RENDER_COHERENT; 108 mCurrentAlgorithm = OcclusionCullingSceneTraverser::RENDER_COHERENT; 109 mThreshold = 0; 109 110 110 111 // Register this so that we get mouse events. … … 121 122 mQueryCulledNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/QueryCulledNodesInfo"); 122 123 mTraversedNodesInfo = OverlayManager::getSingleton().getOverlayElement("Example/Occlusion/TraversedNodesInfo"); 123 124 //mMaterialInfo = OverlayManager::getSingleton().getOverlayElement("Example/Shadows/MaterialInfo"); 125 //mInfo = OverlayManager::getSingleton().getOverlayElement("Example/Shadows/Info"); 126 124 127 125 mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]); 128 mThresholdInfo->setCaption(": dfddfdffdfd0");126 mThresholdInfo->setCaption(": 0"); 129 127 mFrustumCulledNodesInfo->setCaption(": 0"); 130 128 mQueryCulledNodesInfo->setCaption(": 0"); … … 191 189 bool MouseQueryListener::frameEnded(const FrameEvent& evt) 192 190 { 191 if (mShutdownRequested) 192 return false; 193 193 194 if (timeDelay >= 0) 194 195 timeDelay -= evt.timeSinceLastFrame; 195 196 196 KEY_PRESSED(KC_O, 1, changeAlgorithm()); 197 //KEY_PRESSED(KC_T, 1, changeAlgorithm()); 197 KEY_PRESSED(KC_SPACE, 0.3, changeAlgorithm()); 198 199 KEY_PRESSED(KC_SUBTRACT, 0.3, changeThreshold(-10)); 200 KEY_PRESSED(KC_ADD, 0, changeThreshold(10)); 201 //KEY_PRESSED(KC_T, 1, change); 198 202 199 203 changeStats(); … … 202 206 } 203 207 //----------------------------------------------------------------------- 208 void MouseQueryListener::changeThreshold(int incr) 209 { 210 mThreshold += incr; if(mThreshold < 0) mThreshold = 0; 211 212 char str[100]; sprintf(str,": %d", mThreshold); 213 214 mSceneMgr->setOption("Threshold", &mThreshold); 215 mThresholdInfo->setCaption(str); 216 } 217 //----------------------------------------------------------------------- 204 218 void MouseQueryListener::changeAlgorithm() 205 219 { 206 mCurrentAlgorithm = ++mCurrentAlgorithm % OcclusionCullingScene Manager::NUM_RENDERMODES;220 mCurrentAlgorithm = ++mCurrentAlgorithm % OcclusionCullingSceneTraverser::NUM_RENDERMODES; 207 221 208 222 mAlgorithmInfo->setCaption(": " + mCurrentAlgorithmCaptions[mCurrentAlgorithm]); … … 214 228 unsigned int opt = 0; 215 229 char str[100]; 216 mSceneMgr->getOption("Threshold", &opt); sprintf(str,"%d",opt);mThresholdInfo->setCaption(str); 217 mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,"%d",opt); mFrustumCulledNodesInfo->setCaption(str); 218 mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,"%d",opt);mQueryCulledNodesInfo->setCaption(str); 219 mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,"%d",opt);mTraversedNodesInfo->setCaption(str); 230 231 mSceneMgr->getOption("NumFrustumCulledNodes", &opt); sprintf(str,": %d", opt); 232 mFrustumCulledNodesInfo->setCaption(str); 233 234 mSceneMgr->getOption("NumQueryCulledNodes", &opt); sprintf(str,": %d", opt); 235 mQueryCulledNodesInfo->setCaption(str); 236 237 mSceneMgr->getOption("NumTraversedNodes", &opt); sprintf(str,": %d", opt); 238 mTraversedNodesInfo->setCaption(str); 239 } 240 //----------------------------------------------------------------------- 241 void MouseQueryListener::keyPressed(KeyEvent* e) 242 { 243 if(e->getKey() == KC_ESCAPE) 244 { 245 mShutdownRequested = true; 246 e->consume(); 247 return; 248 } 249 250 CEGUI::System::getSingleton().injectKeyDown(e->getKey()); 251 CEGUI::System::getSingleton().injectChar(e->getKeyChar()); 252 e->consume(); 253 } 254 //----------------------------------------------------------------------- 255 void MouseQueryListener::keyReleased(KeyEvent* e) 256 { 257 CEGUI::System::getSingleton().injectKeyUp(e->getKey()); 258 e->consume(); 259 } 260 //----------------------------------------------------------------------- 261 void MouseQueryListener::keyClicked(KeyEvent* e) 262 { 263 // Do nothing 264 e->consume(); 220 265 } 221 266 //----------------------------------------------------------------------- -
trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h
r30 r32 6 6 #include "ExampleApplication.h" 7 7 #include "OgreOcclusionCullingSceneManager.h" 8 #include "OgreOcclusionCullingSceneTraverser.h" 8 9 9 10 Real timeDelay = 0; … … 17 18 } 18 19 19 String mCurrentAlgorithmCaptions[OcclusionCullingScene Manager::NUM_RENDERMODES] =20 String mCurrentAlgorithmCaptions[OcclusionCullingSceneTraverser::NUM_RENDERMODES] = 20 21 { 21 22 "Cull Frustum", … … 53 54 // This is when the mouse is clicked, held and dragged. 54 55 virtual void mouseDragged (MouseEvent *e); 55 /*56 void keyPressed(KeyEvent* e)57 {58 if(e->getKey() == KC_ESCAPE)59 {60 mShutdownRequested = true;61 e->consume();62 return;63 }64 56 65 CEGUI::System::getSingleton().injectKeyDown(e->getKey()); 66 CEGUI::System::getSingleton().injectChar(e->getKeyChar()); 67 e->consume(); 68 } 57 void keyPressed(KeyEvent* e); 69 58 70 void keyReleased(KeyEvent* e) 71 { 72 CEGUI::System::getSingleton().injectKeyUp(e->getKey()); 73 e->consume(); 74 } 75 void keyClicked(KeyEvent* e) 76 { 77 // Do nothing 78 e->consume(); 79 } 59 void keyReleased(KeyEvent* e); 60 void keyClicked(KeyEvent* e); 80 61 81 bool frameEnded(const FrameEvent& evt)82 {83 if (mShutdownRequested)84 return false;85 else86 return ExampleFrameListener::frameEnded(evt);87 }88 */89 62 void changeAlgorithm(); 63 void changeThreshold(int incr); 90 64 void changeStats(); 91 65 … … 96 70 CEGUI::Renderer *mGUIRenderer; // cegui renderer 97 71 SceneNode* mShipNode; 98 //bool mShutdownRequested;72 bool mShutdownRequested; 99 73 int mCurrentAlgorithm; 100 74 int mThreshold; 75 101 76 OverlayElement *mAlgorithmInfo; 102 77 OverlayElement *mThresholdInfo; … … 113 88 /*TestCullingApplication() 114 89 { 115 116 90 }*/ 117 91 … … 148 122 149 123 }*/ 150 151 152 153 124 }; 154 125 -
trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h
r30 r32 4 4 #include "OgreSceneNode.h" 5 5 #include "OgreSceneManager.h" 6 #include "OgreOcclusionCullingSceneTraverser.h" 6 7 #include "OgrePrerequisites.h" 7 8 #include "OgreSolidHalfBoundingBox.h" … … 11 12 12 13 namespace Ogre { 13 /** 14 This class implements the compare operator for the priority queue. 15 a lower distance has a higher value in the queue 16 */ 17 template <typename T> class myless 18 { 19 public: 20 myless(Camera *cam) { mCamera = cam; } 21 //bool operator() (HierarchyNode *v1, HierarchyNode *v2) const 22 bool operator() (T v1, T v2) const 23 { 24 return v1->getSquaredViewDepth(mCamera) > v2->getSquaredViewDepth(mCamera); 25 } 26 private: 27 Camera *mCamera; 28 }; 29 30 typedef pair<SceneNode *, HardwareOcclusionQuery *> query_pair; 31 typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue; 32 typedef queue<query_pair> QueryQueue; 14 33 15 /** 34 16 Class which implements a scene mangager which uses occlusion queries for culling occluded objects … … 38 20 public: 39 21 OcclusionCullingSceneManager(); 40 ~OcclusionCullingSceneManager();22 //~OcclusionCullingSceneManager(); 41 23 42 enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};43 44 24 /** Overriden from SceneManager. Renders the scene with the specified algorithm 45 25 /** … … 69 49 70 50 protected: 71 enum {MODE_QUERY, MODE_RENDER}; 72 73 bool isLeaf(SceneNode *node); 74 unsigned int countSceneNodes(SceneNode *node); 75 void renderZPass(); 76 void traverseNode(SceneNode *node); 77 /** Renders current node */ 78 void render(SceneNode *node); 79 /** Sets rendering mode, e.g. query mode or render mode*/ 80 void setRenderingMode(int mode); 81 82 /** Renders the scene with view frustum culling only. */ 83 void renderCullFrustum(); 84 /** Renders the scene with the hierarchical stop and wait algorithm. */ 85 void renderStopAndWait(); 86 /** Renders the scene with the coherent hierarchical algorithm and the query queye. */ 87 void renderCoherentWithQueue(); 88 /** Issue a occlusion query for this node. */ 89 HardwareOcclusionQuery *issueOcclusionQuery(SceneNode *node, bool wasVisible); 90 /** Pulls up the visibility from the child nodes. */ 91 void pullUpVisibility(SceneNode *node); 92 /** delete all previously defined occlusion queries */ 93 void deleteQueries(); 94 /** Renders bounding box of specified node. 95 @param the node which bounding box is to be rendered 96 */ 97 void renderBoundingBox(SceneNode *node); 98 /** Returns one half of the bounding box. 99 @param the half of the bouding box 100 */ 101 SolidHalfBoundingBox *getSolidHalfBoundingBox(int half); 102 103 104 // we use a priority queue rather than a renderstack 105 PriorityQueue *mDistanceQueue; 106 107 std::vector<HardwareOcclusionQuery *> mOcclusionQueries; 108 // two halfes of a aabb 109 SolidHalfBoundingBox *mHalfBoundingBox[2]; 110 int mCurrentAlgorithm; 111 112 unsigned int mFrameId; 113 unsigned int mVisibilityThreshold; 114 115 int mCurrentTestIdx; 116 int mQueryMode; 117 118 //--- statistics 119 unsigned int mNumSceneNodes; 120 unsigned int mNumTraversedNodes; 121 unsigned int mNumQueryCulledNodes; 122 unsigned int mNumFrustumCulledNodes; 123 unsigned int mNumRenderedGeometry; 51 OcclusionCullingSceneTraverser mSceneTraverser; 52 124 53 }; 125 54 -
trunk/VUT/OcclusionCullingSceneManager/scripts/OcclusionDemo.overlay
r30 r32 33 33 font_name TrebuchetMSBold 34 34 char_height 16 35 caption [ O] Algorithm35 caption [A] Algorithm 36 36 colour_top 0.5 0.7 0.5 37 37 colour_bottom 0.3 0.5 0.3 … … 60 60 font_name TrebuchetMSBold 61 61 char_height 16 62 caption [-][+] Threshold z62 caption [-][+] Threshold 63 63 colour_top 0.5 0.7 0.5 64 64 colour_bottom 0.3 0.5 0.3 … … 73 73 font_name TrebuchetMSBold 74 74 char_height 16 75 caption : dddd75 caption : 76 76 colour_top 0.5 0.7 0.5 77 77 colour_bottom 0.3 0.5 0.3 … … 84 84 vert_align top 85 85 horz_align right 86 left - 45586 left -355 87 87 top 5 88 88 width 450 89 height 5589 height 70 90 90 material Core/StatsBlockCenter 91 91 border_size 1 1 1 1 … … 116 116 { 117 117 metrics_mode pixels 118 left 1 55119 top 5 120 width 90 121 height 30 122 font_name TrebuchetMSBold 123 char_height 16 124 caption : jjkj118 left 180 119 top 5 120 width 90 121 height 30 122 font_name TrebuchetMSBold 123 char_height 16 124 caption : 125 125 colour_top 0.5 0.7 0.5 126 126 colour_bottom 0.3 0.5 0.3 … … 135 135 font_name TrebuchetMSBold 136 136 char_height 16 137 caption Query QueryCulled Nodes137 caption Query Culled Nodes 138 138 colour_top 0.5 0.7 0.5 139 139 colour_bottom 0.3 0.5 0.3 … … 142 142 { 143 143 metrics_mode pixels 144 left 1 55144 left 180 145 145 top 20 146 146 width 90 … … 168 168 { 169 169 metrics_mode pixels 170 left 1 55170 left 180 171 171 top 35 172 172 width 90 … … 187 187 font_name TrebuchetMSBold 188 188 char_height 16 189 caption TraversedScene Nodes189 caption Scene Nodes 190 190 colour_top 0.5 0.7 0.5 191 191 colour_bottom 0.3 0.5 0.3 … … 194 194 { 195 195 metrics_mode pixels 196 left 1 55196 left 180 197 197 top 50 198 198 width 90 -
trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj
r26 r32 20 20 Name="VCCLCompilerTool" 21 21 Optimization="0" 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"22 AdditionalIncludeDirectories=""$(OGRE_PATH)\PlugIns\OctreeSceneManager\include";"$(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 23 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;PLUGIN_OCCLUSIONCULLINGSCENEMANAGER_EXPORTS;OGRE_COHERENT_OCCLUSION_CULLING" 24 24 MinimalRebuild="TRUE" … … 35 35 Name="VCLinkerTool" 36 36 IgnoreImportLibrary="TRUE" 37 AdditionalDependencies="OgreMain_d.lib CEGUIBase_d.lib OgreGUIRenderer_d.lib "37 AdditionalDependencies="OgreMain_d.lib CEGUIBase_d.lib OgreGUIRenderer_d.lib Plugin_OctreeSceneManager.lib" 38 38 OutputFile="$(OutDir)/Plugin_OcclusionCullingSceneManager.dll" 39 39 Version="0.99" 40 40 LinkIncremental="2" 41 41 SuppressStartupBanner="TRUE" 42 AdditionalLibraryDirectories=""$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)";"$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)";"$(OGRE_PATH)\ Samples\Common\CEGUIRenderer\lib""42 AdditionalLibraryDirectories=""$(OGRE_PATH)\OgreMain\lib\$(ConfigurationName)";"$(OGRE_PATH)\Dependencies\lib\$(ConfigurationName)";"$(OGRE_PATH)\PlugIns\OctreeSceneManager\bin\$(ConfigurationName)";"$(OGRE_PATH)\Samples\Common\CEGUIRenderer\lib"" 43 43 ModuleDefinitionFile="..\misc\OgreOcclusionCullingSceneManager.def" 44 44 GenerateDebugInformation="TRUE" 45 45 ProgramDatabaseFile="$(OutDir)/Plugin_OcclusionCullingSceneManager.pdb" 46 46 SubSystem="2" 47 ImportLibrary=" $(OutDir)/Plugin_OcclusionCullingSceneManager.lib"47 ImportLibrary="" 48 48 TargetMachine="1"/> 49 49 <Tool … … 154 154 </File> 155 155 <File 156 RelativePath="..\src\OgreOcclusionCullingSceneTraverser.cpp"> 157 </File> 158 <File 156 159 RelativePath="..\src\OgreSolidHalfBoundingBox.cpp"> 157 160 </File> … … 170 173 </File> 171 174 <File 175 RelativePath="..\include\OgreOcclusionCullingSceneTraverser.h"> 176 </File> 177 <File 172 178 RelativePath="..\include\OgreSolidHalfBoundingBox.h"> 173 179 </File> -
trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp
r31 r32 13 13 14 14 //----------------------------------------------------------------------- 15 OcclusionCullingSceneManager::OcclusionCullingSceneManager(): 16 mFrameId(1), mDistanceQueue(NULL), mVisibilityThreshold(0), mCurrentTestIdx(0), 17 mQueryMode(MODE_RENDER), mNumSceneNodes(0), mCurrentAlgorithm(RENDER_COHERENT), 18 mNumTraversedNodes(0), mNumQueryCulledNodes(0), mNumFrustumCulledNodes(0), mNumRenderedGeometry(0) 19 { 20 mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0; 15 OcclusionCullingSceneManager::OcclusionCullingSceneManager() 16 { 21 17 } 22 18 //----------------------------------------------------------------------- 23 void OcclusionCullingSceneManager::_findVisibleObjects( Camera* cam, bool onlyShadowCasters)19 void OcclusionCullingSceneManager::_findVisibleObjects( Camera* cam, bool onlyShadowCasters ) 24 20 { 25 // empty because we have to find in _renderVisibleObjects21 // empty because we have to find objects in _renderVisibleObjects 26 22 } 27 23 //----------------------------------------------------------------------- 28 OcclusionCullingSceneManager::~OcclusionCullingSceneManager() 29 { 30 if(mHalfBoundingBox[0]) delete mHalfBoundingBox[0]; 31 if(mHalfBoundingBox[1]) delete mHalfBoundingBox[1]; 32 33 deleteQueries(); 34 //SceneManager::~SceneManager(); 24 void OcclusionCullingSceneManager::_renderVisibleObjects( void ) 25 { 26 mSceneTraverser.renderScene(mCameraInProgress, mSceneRoot); 35 27 } 36 28 //----------------------------------------------------------------------- 37 void OcclusionCullingSceneManager::_renderVisibleObjects(void) 38 { 39 mNumTraversedNodes = 0; 40 mNumQueryCulledNodes = 0; 41 mNumFrustumCulledNodes = 0; 42 mNumRenderedGeometry = 0; 43 44 mDistanceQueue = new PriorityQueue(myless<SceneNode *>(mCameraInProgress)); 45 mDistanceQueue->push(mSceneRoot); 46 mCurrentTestIdx = 0; 47 //renderZPass(); 48 49 switch(mCurrentAlgorithm) 50 { 51 case RENDER_CULL_FRUSTUM: 52 renderCullFrustum(); 53 break; 54 case RENDER_STOP_AND_WAIT: 55 renderStopAndWait(); 56 break; 57 case RENDER_COHERENT: 58 renderCoherentWithQueue(); 59 break; 60 default: 61 renderCullFrustum(); 62 break; 63 } 64 65 delete mDistanceQueue; 66 67 mFrameId ++; 68 } 69 //----------------------------------------------------------------------- 70 void OcclusionCullingSceneManager::renderZPass() 29 /*void OcclusionCullingSceneManager::renderZPass() 71 30 { 72 31 traverseNode(mSceneRoot); 73 } 32 }*/ 74 33 //----------------------------------------------------------------------- 75 void OcclusionCullingSceneManager:: renderCoherentWithQueue()34 void OcclusionCullingSceneManager::_updateSceneGraph( Camera* cam ) 76 35 { 77 QueryQueue queryQueue; 78 79 //-- PART 1: process finished occlusion queries 80 while(!mDistanceQueue->empty() || !queryQueue.empty()) 81 { 82 while(!queryQueue.empty() && 83 ((queryQueue.front().second)->resultAvailable() || mDistanceQueue->empty())) 84 { 85 SceneNode *node = queryQueue.front().first; 86 HardwareOcclusionQuery *query = queryQueue.front().second; 87 88 queryQueue.pop(); 89 90 // wait until result available 91 unsigned int visiblePixels; 92 query->pullOcclusionQuery(&visiblePixels); 93 94 if(visiblePixels > mVisibilityThreshold) 95 { 96 pullUpVisibility(node); 97 traverseNode(node); 98 } 99 else 100 { 101 mNumQueryCulledNodes ++; 102 } 103 } 104 105 //-- PART 2: hierarchical traversal 106 if(!mDistanceQueue->empty()) 107 { 108 SceneNode *node = mDistanceQueue->top(); 109 mDistanceQueue->pop(); 110 111 if(mCameraInProgress->isVisible(node->_getWorldAABB())) 112 { 113 // identify previously visible nodes 114 bool wasVisible = node->isNodeVisible() && (node->lastVisited() == mFrameId - 1); 115 116 // identify nodes that we cannot skip queries for 117 bool leafOrWasInvisible = !wasVisible || isLeaf(node); 118 119 // reset node's visibility classification 120 node->setNodeVisible(false); 121 122 // update node's visited flag 123 node->setLastVisited(mFrameId); 124 125 // skip testing previously visible interior nodes 126 if(leafOrWasInvisible) 127 { 128 HardwareOcclusionQuery *query = issueOcclusionQuery(node, wasVisible); 129 queryQueue.push(query_pair(node, query)); 130 } 131 132 // always traverse a node if it was visible 133 if(wasVisible) 134 { 135 traverseNode(node); 136 } 137 } 138 else 139 { 140 mNumFrustumCulledNodes ++; 141 } 142 } 143 } 144 } 145 //----------------------------------------------------------------------- 146 void OcclusionCullingSceneManager::renderCullFrustum() 147 { 148 while(!mDistanceQueue->empty()) 149 { 150 SceneNode *node = mDistanceQueue->top(); 151 mDistanceQueue->pop(); 152 153 // interesting for visualization purpose 154 node->setNodeVisible(false); 155 156 if(mCameraInProgress->isVisible(node->_getWorldAABB())) 157 { 158 // update node's visited flag 159 node->setLastVisited(mFrameId); 160 node->setNodeVisible(true); 161 traverseNode(node); 162 } 163 else 164 { 165 mNumFrustumCulledNodes ++; 166 } 167 } 168 } 169 //----------------------------------------------------------------------- 170 void OcclusionCullingSceneManager::renderStopAndWait() 171 { 172 while(!mDistanceQueue->empty()) 173 { 174 SceneNode *node = mDistanceQueue->top(); 175 mDistanceQueue->pop(); 36 mSceneTraverser.preprocess(); 176 37 177 // interesting for the visualization178 node->setNodeVisible(false);179 node->setLastVisited(mFrameId);180 181 if(mCameraInProgress->isVisible(node->_getWorldAABB()))182 {183 HardwareOcclusionQuery *query = issueOcclusionQuery(node, false);184 185 unsigned int visiblePixels;186 // wait if result not available187 query->pullOcclusionQuery(&visiblePixels);188 189 // node visible190 if(visiblePixels > mVisibilityThreshold)191 {192 traverseNode(node);193 }194 else195 {196 mNumQueryCulledNodes ++;197 }198 }199 else200 {201 mNumFrustumCulledNodes ++;202 }203 }204 }205 //-----------------------------------------------------------------------206 HardwareOcclusionQuery *OcclusionCullingSceneManager::issueOcclusionQuery(SceneNode *node, bool wasVisible)207 {208 // change state so the bounding box gets not actually rendered on the screen209 setRenderingMode(MODE_QUERY);210 211 // get next available test id212 HardwareOcclusionQuery *query = mOcclusionQueries[mCurrentTestIdx++];213 214 query->beginOcclusionQuery();215 216 /*217 static RenderOperation ro;218 useRenderableViewProjMode(&box);219 box.getRenderOperation(ro);220 ro.srcRenderable = &box;221 mDestRenderSystem->_render(ro);222 */223 224 renderBoundingBox(node);225 226 query->endOcclusionQuery();227 228 return query;229 }230 231 //-----------------------------------------------------------------------232 void OcclusionCullingSceneManager::setRenderingMode(int mode)233 {234 // avoid unnecessary state changes235 if(mode != mQueryMode)236 {237 bool enabled = (mode == MODE_RENDER);238 239 mDestRenderSystem->_setColourBufferWriteEnabled(enabled,240 enabled, enabled, enabled);241 mDestRenderSystem->_setDepthBufferWriteEnabled(enabled);242 mDestRenderSystem->setLightingEnabled(enabled);243 mQueryMode = mode;244 }245 }246 //-----------------------------------------------------------------------247 void OcclusionCullingSceneManager::traverseNode(SceneNode *node)248 {249 mNumTraversedNodes ++;250 251 if(node->numAttachedObjects() > 0)252 {253 render(node);254 }255 256 // internal node: add children to priority queue for further processing257 Node::ChildNodeIterator it = node->getChildIterator();258 259 while (it.hasMoreElements())260 {261 SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());262 mDistanceQueue->push(sceneChild);263 }264 }265 //-----------------------------------------------------------------------266 void OcclusionCullingSceneManager::render(SceneNode *node)267 {268 setRenderingMode(MODE_RENDER);269 270 //HACK (too slow)271 node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false,272 mDisplayNodes, false);273 SceneManager::_renderVisibleObjects();274 getRenderQueue()->clear();275 }276 //-----------------------------------------------------------------------277 void OcclusionCullingSceneManager::_updateSceneGraph(Camera* cam)278 {279 unsigned int numnodes = countSceneNodes(mSceneRoot);280 281 //-- initialise occlusion queries.282 if(numnodes != mNumSceneNodes)283 {284 deleteQueries();285 286 mNumSceneNodes = numnodes;287 288 for(unsigned int i=0; i < mNumSceneNodes; i++)289 {290 mOcclusionQueries.push_back(mDestRenderSystem->createHardwareOcclusionQuery());291 }292 }293 294 38 SceneManager::_updateSceneGraph(cam); 295 }296 //-----------------------------------------------------------------------297 unsigned int OcclusionCullingSceneManager::countSceneNodes(SceneNode *node)298 {299 unsigned int result = 1;300 301 Node::ChildNodeIterator it = node->getChildIterator();302 303 while (it.hasMoreElements())304 {305 SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext());306 result += countSceneNodes(sceneChild);307 }308 309 return result;310 }311 //-----------------------------------------------------------------------312 bool OcclusionCullingSceneManager::isLeaf(SceneNode *node)313 {314 return (node->numChildren() == 0);315 }316 //-----------------------------------------------------------------------317 void OcclusionCullingSceneManager::pullUpVisibility(SceneNode *node)318 {319 while(!node->isNodeVisible())320 {321 node->setNodeVisible(true);322 323 if(node != mSceneRoot)324 node = static_cast<SceneNode *>(node->getParent());325 }326 }327 //-----------------------------------------------------------------------328 void OcclusionCullingSceneManager::deleteQueries()329 {330 for(unsigned int i=0; i < mNumSceneNodes; i++)331 delete mOcclusionQueries[i];332 333 mOcclusionQueries.clear();334 }335 //-----------------------------------------------------------------------336 void OcclusionCullingSceneManager::renderBoundingBox(SceneNode *node)337 {338 // Render two halfes of the bounding box (using triangle fans)339 for(int half=0; half < 2; half ++)340 {341 getSolidHalfBoundingBox(half)->setupBoundingBox(node->_getWorldAABB());342 SceneManager::renderSingleObject(getSolidHalfBoundingBox(half),343 getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), false);344 }345 }346 //-----------------------------------------------------------------------347 SolidHalfBoundingBox *OcclusionCullingSceneManager::getSolidHalfBoundingBox(int half)348 {349 if(!mHalfBoundingBox[half])350 mHalfBoundingBox[half] = new SolidHalfBoundingBox(half == 1);351 352 return mHalfBoundingBox[half];353 39 } 354 40 //----------------------------------------------------------------------- 355 41 bool OcclusionCullingSceneManager::setOption( const String & key, const void * val ) 356 42 { 357 if ( key == "Algorithm" ) 358 { 359 mCurrentAlgorithm = * static_cast < const int * > ( val ); 360 return true; 361 } 362 if ( key == "Threshold" ) 363 { 364 mCurrentAlgorithm = * static_cast < const int * > ( val ); 365 return true; 366 } 367 43 mSceneTraverser.setOption(key, val); 44 368 45 return SceneManager::setOption( key, val ); 369 46 } … … 371 48 bool OcclusionCullingSceneManager::getOption( const String & key, void *val ) 372 49 { 373 if ( key == "Algorithm" ) 374 { 375 * static_cast < int * > ( val ) = mCurrentAlgorithm; 376 return true; 377 } 378 if ( key == "Threshold" ) 379 { 380 * static_cast < unsigned int * > ( val ) = mVisibilityThreshold; 381 return true; 382 } 383 if ( key == "NumSceneNodes" ) 384 { 385 * static_cast < unsigned int * > ( val ) = mNumSceneNodes; 386 return true; 387 } 388 if ( key == "NumTraversedNodes" ) 389 { 390 * static_cast < unsigned int * > ( val ) = mNumTraversedNodes; 391 return true; 392 } 393 if ( key == "NumQueryCulledNodes" ) 394 { 395 * static_cast < unsigned int * > ( val ) = mNumQueryCulledNodes; 396 return true; 397 } 398 if ( key == "NumFrustumCulledNodes" ) 399 { 400 * static_cast < unsigned int * > ( val ) = mNumFrustumCulledNodes; 401 return true; 402 } 403 50 mSceneTraverser.getOption(key, val); 51 404 52 return SceneManager::getOption( key, val ); 405 53 } … … 413 61 { 414 62 SceneManager::getOptionKeys( refKeys ); 63 415 64 refKeys.push_back( "Algorithm" ); 416 65 refKeys.push_back( "Threshold" ); -
trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManagerDll.cpp
r18 r32 24 24 */ 25 25 26 #include "OgreOcclusionCullingSceneManager.h" 27 #include "OgreRoot.h" 26 //#include "OgreOcclusionCullingSceneManager.h" 27 //#include "OgreTerrainOcclusionCullingSceneManager.h" 28 #include <OgreOctreeSceneManager.h> 29 #include <OgreTerrainSceneManager.h> 30 #include <OgreRoot.h> 31 #include "OgreHeightmapTerrainPageSource.h" 28 32 //#include <windows.h> 29 33 30 34 namespace Ogre { 31 35 32 OcclusionCullingSceneManager* occlusionPlugin; 36 //OcclusionCullingSceneManager *occlusionPlugin; 37 //TerrainOcclusionCullingSceneManager *terrainOcclusionPlugin; 38 OctreeSceneManager *ocPlugin; 39 33 40 //----------------------------------------------------------------------- 34 41 extern "C" void dllStartPlugin(void) 35 42 { 36 // Create new scene manager 37 occlusionPlugin = new OcclusionCullingSceneManager(); 38 39 // Register 40 Root::getSingleton().setSceneManager(ST_GENERIC, occlusionPlugin); 41 43 // Create new scene manager 44 // occlusionPlugin = new OcclusionCullingSceneManager(); 45 ocPlugin = new OctreeSceneManager(); 46 47 // Register 48 //Root::getSingleton().setSceneManager( ST_GENERIC, occlusionPlugin ); 49 // Root::getSingleton().setSceneManager( ST_EXTERIOR_CLOSE, terrainOcclusionPlugin ); 50 Root::getSingleton().setSceneManager( ST_EXTERIOR_CLOSE, ocPlugin ); 51 42 52 //MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL); 43 53 } 44 54 extern "C" void dllStopPlugin(void) 45 55 { 46 delete occlusionPlugin; 56 // delete occlusionPlugin; 57 delete ocPlugin; 58 //delete terrainOcclusionPlugin; 47 59 } 48 60 }
Note: See TracChangeset
for help on using the changeset viewer.