Changeset 26
- Timestamp:
- 03/22/05 14:51:26 (20 years ago)
- Location:
- trunk/VUT/OcclusionCullingSceneManager
- Files:
-
- 2 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/VUT/OcclusionCullingSceneManager/TestCulling/TestCullingApplication.h
r18 r26 5 5 #include "CEGUIForwardRefs.h" 6 6 #include "ExampleApplication.h" 7 7 #include "OgreOcclusionCullingSceneManager.h" 8 8 9 9 class MouseQueryListener : public ExampleFrameListener, public MouseListener, public MouseMotionListener … … 13 13 MouseQueryListener(RenderWindow* win, Camera* cam, SceneManager *sceneManager, CEGUI::Renderer *renderer, 14 14 SceneNode* shipNode) 15 : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), mShipNode(shipNode) 15 : ExampleFrameListener(win, cam, false, true), mGUIRenderer(renderer), mShipNode(shipNode), mShutdownRequested(false) 16 16 { 17 17 // Setup default variables … … 24 24 mMoveSpeed = 50; 25 25 mRotateSpeed *= 2; 26 27 mAlgorithmType = OcclusionCullingSceneManager::RENDER_COHERENT; 28 29 showDebugOverlay(false); 26 30 27 31 // Register this so that we get mouse events. 28 mEventProcessor->addMouseListener( this ); 29 mEventProcessor->addMouseMotionListener( this ); 32 mEventProcessor->addMouseListener(this); 33 mEventProcessor->addMouseMotionListener(this); 34 mEventProcessor->addKeyListener(this); 30 35 } // MouseQueryListener 31 36 … … 36 41 bool frameStarted(const FrameEvent &evt) 37 42 { 38 return ExampleFrameListener::frameStarted( evt ); 43 Real MoveFactor = 80.0 * evt.timeSinceLastFrame; 44 45 mInputDevice->capture(); 46 47 if(mInputDevice->isKeyDown(Ogre::KC_UP)) 48 { 49 50 mAlgorithmType = (mAlgorithmType + 1) % OcclusionCullingSceneManager::NUM_RENDERMODES; 51 //mShipNode->translate(0.0, MoveFactor, 0.0); 52 } 53 54 if(mInputDevice->isKeyDown(Ogre::KC_DOWN)) 55 mShipNode->translate(0.0, -MoveFactor, 0.0); 56 57 if(mInputDevice->isKeyDown(Ogre::KC_LEFT)) 58 mShipNode->translate(-MoveFactor, 0.0, 0.0); 59 60 if(mInputDevice->isKeyDown(Ogre::KC_RIGHT)) 61 mShipNode->translate(MoveFactor, 0.0, 0.0); 62 63 if(mInputDevice->isKeyDown(Ogre::KC_ESCAPE)) 64 return false; 65 66 return true; 39 67 } 40 68 … … 56 84 virtual void mouseDragged (MouseEvent *e); 57 85 86 void keyPressed(KeyEvent* e) 87 { 88 if(e->getKey() == KC_ESCAPE) 89 { 90 mShutdownRequested = true; 91 e->consume(); 92 return; 93 } 94 95 CEGUI::System::getSingleton().injectKeyDown(e->getKey()); 96 CEGUI::System::getSingleton().injectChar(e->getKeyChar()); 97 e->consume(); 98 } 99 100 void keyReleased(KeyEvent* e) 101 { 102 CEGUI::System::getSingleton().injectKeyUp(e->getKey()); 103 e->consume(); 104 } 105 void keyClicked(KeyEvent* e) 106 { 107 // Do nothing 108 e->consume(); 109 } 110 111 bool frameEnded(const FrameEvent& evt) 112 { 113 if (mShutdownRequested) 114 return false; 115 else 116 return ExampleFrameListener::frameEnded(evt); 117 } 118 119 void setAlgorithmType(int type) { mAlgorithmType = type; } 120 int getAlgorithmType() { return mAlgorithmType; } 121 58 122 protected: 59 123 bool mLMouseDown, mRMouseDown; // True if the mouse buttons are down … … 62 126 CEGUI::Renderer *mGUIRenderer; // cegui renderer 63 127 SceneNode* mShipNode; 128 bool mShutdownRequested; 129 int mAlgorithmType; 64 130 }; 65 131 66 67 class TestCullingFrameListener : public ExampleFrameListener68 {69 protected:70 SceneNode* mShipNode;71 72 public:73 TestCullingFrameListener(RenderWindow* win, Camera* cam, SceneNode* shipNode) : ExampleFrameListener(win, cam)74 {75 mShipNode = shipNode;76 };77 78 bool frameStarted(const FrameEvent& evt)79 {80 Real MoveFactor = 80.0 * evt.timeSinceLastFrame;81 82 mInputDevice->capture();83 84 if(mInputDevice->isKeyDown(Ogre::KC_UP))85 mShipNode->translate(0.0, MoveFactor, 0.0);86 87 if(mInputDevice->isKeyDown(Ogre::KC_DOWN))88 mShipNode->translate(0.0, -MoveFactor, 0.0);89 90 if(mInputDevice->isKeyDown(Ogre::KC_LEFT))91 mShipNode->translate(-MoveFactor, 0.0, 0.0);92 93 if(mInputDevice->isKeyDown(Ogre::KC_RIGHT))94 mShipNode->translate(MoveFactor, 0.0, 0.0);95 96 if(mInputDevice->isKeyDown(Ogre::KC_ESCAPE))97 return false;98 99 return true;100 }101 };102 132 103 133 class TestCullingApplication : public ExampleApplication … … 106 136 /*TestCullingApplication() 107 137 { 108 109 138 110 139 }*/ … … 150 179 { 151 180 mSceneMgr = mRoot->getSceneManager(ST_GENERIC); 152 //mSceneMgr = mRoot->getSceneManager(ST_INTERIOR);153 181 } 154 /* 155 // Scene creation 156 void createScene(void) 157 { 158 159 // Load world geometry 160 mSceneMgr->setWorldGeometry(mQuakeLevel); 161 162 // modify camera for close work 163 mCamera->setNearClipDistance(4); 164 mCamera->setFarClipDistance(4000); 165 166 // Also change position, and set Quake-type orientation 167 // Get random player start point 168 ViewPoint vp = mSceneMgr->getSuggestedViewpoint(true); 169 mCamera->setPosition(vp.position); 170 mCamera->pitch(Degree(90)); // Quake uses X/Y horizon, Z up 171 mCamera->rotate(vp.orientation); 172 // Don't yaw along variable axis, causes leaning 173 mCamera->setFixedYawAxis(true, Vector3::UNIT_Z); 174 }*/ 175 182 176 183 }; 177 184 -
trunk/VUT/OcclusionCullingSceneManager/include/OgreOcclusionCullingSceneManager.h
r23 r26 5 5 #include "OgreSceneManager.h" 6 6 #include "OgrePrerequisites.h" 7 #include "OgreSolidHalfBoundingBox.h" 7 8 #include <queue> 8 9 … … 27 28 }; 28 29 30 typedef pair<SceneNode *, HardwareOcclusionQuery *> query_pair; 29 31 typedef priority_queue<SceneNode *, vector<SceneNode *>, myless<vector<SceneNode *>::value_type> > PriorityQueue; 30 typedef queue< SceneNode *> QueryQueue;32 typedef queue<query_pair> QueryQueue; 31 33 /** 32 34 Class which implements a scene mangager which uses occlusion queries for culling occluded objects … … 35 37 { 36 38 public: 37 enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES};38 39 39 OcclusionCullingSceneManager(); 40 40 ~OcclusionCullingSceneManager(); 41 41 42 /** Overriden from SceneManager. */ 42 43 enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES}; 44 45 /** Overriden from SceneManager. Renders the scene with the specified algorithm 46 /** 47 The algorithm is one of 48 RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only 49 RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm 50 RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm 51 */ 43 52 void _renderVisibleObjects(void); 44 53 void _findVisibleObjects(Camera* cam, bool onlyShadowCasters); … … 64 73 void renderCoherentWithQueue(); 65 74 /** Issue a occlusion query for this node. */ 66 voidissueOcclusionQuery(SceneNode *node, bool wasVisible);75 HardwareOcclusionQuery *issueOcclusionQuery(SceneNode *node, bool wasVisible); 67 76 /** Pulls up the visibility from the child nodes. */ 68 77 void pullUpVisibility(SceneNode *node); 78 /** delete all previously defined occlusion queries */ 79 void deleteQueries(); 80 /** Renders bounding box of specified node. 81 @param the node which bounding box is to be rendered 82 */ 83 void renderBoundingBox(SceneNode *node); 84 /** Returns one half of the bounding box. 85 @param the half of the bouding box 86 */ 87 SolidHalfBoundingBox *getSolidHalfBoundingBox(int half); 88 /** sets the type of the algorithm 89 @param algorithm type 90 */ 91 void setAlgorithmType(int type); 92 93 int getAlgorithmType(); 69 94 70 void deleteQueries(); 71 72 /** we use a priority queue rather than a renderstack */ 95 // we use a priority queue rather than a renderstack 73 96 PriorityQueue *mDistanceQueue; 74 97 75 98 unsigned int mFrameId; 76 99 unsigned int mVisibilityThreshold; … … 80 103 81 104 std::vector<HardwareOcclusionQuery *> mOcclusionQueries; 105 // two halfes of a aabb 106 SolidHalfBoundingBox *mHalfBoundingBox[2]; 107 int mAlgorithmType; 82 108 }; 83 109 -
trunk/VUT/OcclusionCullingSceneManager/scripts/Plugin_OcclusionCullingSceneManager.vcproj
r24 r26 154 154 </File> 155 155 <File 156 RelativePath="..\src\OgreSolid BoundingBox.cpp">156 RelativePath="..\src\OgreSolidHalfBoundingBox.cpp"> 157 157 </File> 158 158 <File … … 170 170 </File> 171 171 <File 172 RelativePath="..\include\OgreSolid BoundingBox.h">172 RelativePath="..\include\OgreSolidHalfBoundingBox.h"> 173 173 </File> 174 174 </Filter> -
trunk/VUT/OcclusionCullingSceneManager/src/OgreOcclusionCullingSceneManager.cpp
r24 r26 6 6 #include "OgreHardwareOcclusionQuery.h" 7 7 //#include "OgreWireBoundingBox.h" 8 #include "OgreSolid BoundingBox.h"8 #include "OgreSolidHalfBoundingBox.h" 9 9 10 10 #include <windows.h> … … 15 15 OcclusionCullingSceneManager::OcclusionCullingSceneManager(): 16 16 mFrameId(1), mDistanceQueue(NULL), mVisibilityThreshold(0), mCurrentTestIdx(0), 17 mQueryMode(MODE_RENDER), mNumSceneNodes(0) 17 mQueryMode(MODE_RENDER), mNumSceneNodes(0), mAlgorithmType(RENDER_COHERENT) 18 18 { 19 mHalfBoundingBox[0] = mHalfBoundingBox[1] = 0; 19 20 } 20 21 //----------------------------------------------------------------------- … … 26 27 OcclusionCullingSceneManager::~OcclusionCullingSceneManager() 27 28 { 29 delete mHalfBoundingBox[0]; 30 delete mHalfBoundingBox[1]; 31 28 32 deleteQueries(); 29 33 //SceneManager::~SceneManager(); … … 37 41 38 42 mCurrentTestIdx = 0; 43 39 44 //renderZPass(); 40 //renderCullFrustum(); 41 //renderCoherentWithQueue(); 42 renderStopAndWait(); 45 46 switch(mAlgorithmType) 47 { 48 case RENDER_CULL_FRUSTUM: 49 renderCullFrustum(); 50 break; 51 case RENDER_STOP_AND_WAIT: 52 renderStopAndWait(); 53 break; 54 case RENDER_COHERENT: 55 renderCoherentWithQueue(); 56 break; 57 default: 58 renderCullFrustum(); 59 break; 60 } 61 43 62 delete mDistanceQueue; 44 63 … … 67 86 { 68 87 while(!queryQueue.empty() && 69 (queryQueue.front()->getOcclusionQuery()->resultAvailable() || mDistanceQueue->empty())) 70 { 71 SceneNode *node = queryQueue.front(); 88 ((queryQueue.front().second)->resultAvailable() || mDistanceQueue->empty())) 89 { 90 SceneNode *node = queryQueue.front().first; 91 HardwareOcclusionQuery *query = queryQueue.front().second; 92 72 93 queryQueue.pop(); 73 94 74 95 // wait until result available 75 96 unsigned int visiblePixels; 76 node->getOcclusionQuery()->pullOcclusionQuery(&visiblePixels);97 query->pullOcclusionQuery(&visiblePixels); 77 98 78 99 if(visiblePixels > mVisibilityThreshold) … … 99 120 100 121 // reset node's visibility classification 101 node->set Visible(false);122 node->setNodeVisible(false); 102 123 103 124 // update node's visited flag … … 107 128 if(leafOrWasInvisible) 108 129 { 109 issueOcclusionQuery(node, wasVisible);110 queryQueue.push( node);130 HardwareOcclusionQuery *query = issueOcclusionQuery(node, wasVisible); 131 queryQueue.push(query_pair(node, query)); 111 132 } 112 133 … … 126 147 mDistanceQueue->pop(); 127 148 128 // interesting for the visualization, so rest and set129 //node->SetVisible(false);149 // interesting for visualization purpose 150 node->setNodeVisible(false); 130 151 131 152 if(mCameraInProgress->isVisible(node->_getWorldAABB())) 132 153 { 133 // update node's visited flag => needed for rendering 134 // so set it also here 135 //node->SetLastVisited(mFrameID); 136 //node->SetVisible(true); 154 // update node's visited flag 155 node->setLastVisited(mFrameId); 156 node->setNodeVisible(true); 137 157 traverseNode(node); 138 158 } … … 148 168 149 169 // interesting for the visualization 150 //node->SetVisible(false);170 node->setNodeVisible(false); 151 171 node->setLastVisited(mFrameId); 152 172 153 173 if(mCameraInProgress->isVisible(node->_getWorldAABB())) 154 174 { 155 issueOcclusionQuery(node, false);175 HardwareOcclusionQuery *query = issueOcclusionQuery(node, false); 156 176 157 177 unsigned int visiblePixels; 158 178 // wait if result not available 159 node->getOcclusionQuery()->pullOcclusionQuery(&visiblePixels);179 query->pullOcclusionQuery(&visiblePixels); 160 180 161 181 //char str[100]; sprintf(str, "number: %d, id: %d", (int)visiblePixels, mCurrentTestIdx); … … 171 191 } 172 192 //----------------------------------------------------------------------- 173 voidOcclusionCullingSceneManager::issueOcclusionQuery(SceneNode *node, bool wasVisible)193 HardwareOcclusionQuery *OcclusionCullingSceneManager::issueOcclusionQuery(SceneNode *node, bool wasVisible) 174 194 { 175 195 // change state so the bounding box gets not actually rendered on the screen … … 178 198 // get next available test id 179 199 HardwareOcclusionQuery *query = mOcclusionQueries[mCurrentTestIdx++]; 180 node->setOcclusionQuery(query); 181 200 182 201 query->beginOcclusionQuery(); 183 202 184 SolidBoundingBox boxHalf[2];185 boxHalf[1].mIsFirstHalf = false;186 187 203 /* 188 204 static RenderOperation ro; … … 193 209 box.getRenderOperation(ro); 194 210 ro.srcRenderable = &box; 195 mDestRenderSystem->_render(ro);*/ 196 for(int i = 0; i < 2; i++) 197 { 198 boxHalf[i].setupBoundingBox(node->_getWorldAABB()); 199 //setPass(boxHalf[i].getTechnique()->getPass(0)); //setRenderingMode(MODE_QUERY); 200 SceneManager::renderSingleObject(&boxHalf[i], boxHalf[i].getTechnique()->getPass(0), false); 201 } 211 mDestRenderSystem->_render(ro); 212 */ 213 214 renderBoundingBox(node); 202 215 203 216 query->endOcclusionQuery(); 217 218 return query; 204 219 } 205 220 … … 212 227 bool enabled = (mode == MODE_RENDER); 213 228 214 // char str[100]; sprintf(str, "number: %d", mode);215 // MessageBox( NULL, str, "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);216 229 mDestRenderSystem->_setColourBufferWriteEnabled(enabled, 217 230 enabled, enabled, enabled); … … 224 237 void OcclusionCullingSceneManager::traverseNode(SceneNode *node) 225 238 { 226 if(isLeaf(node)) // reached leaf239 if(isLeaf(node)) 227 240 { 228 241 render(node); … … 235 248 { 236 249 SceneNode* sceneChild = static_cast<SceneNode*>(it.getNext()); 237 //mDistanceQueue->addRenderable(sceneChild); 238 mDistanceQueue->push(sceneChild); 250 mDistanceQueue->push(sceneChild); 239 251 } 240 252 } … … 243 255 void OcclusionCullingSceneManager::render(SceneNode *node) 244 256 { 245 setRenderingMode(MODE_RENDER);246 257 //setRenderingMode(MODE_RENDER); 258 //MessageBox( NULL, "harhar", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL); 247 259 //HACK (too slow) 248 260 node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false, … … 267 279 mOcclusionQueries.push_back(hw); 268 280 } 269 //char str[100]; sprintf(str, "number: %d", mNumSceneNodes);270 //MessageBox( NULL, str, "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL);271 281 } 272 282 … … 300 310 void OcclusionCullingSceneManager::pullUpVisibility(SceneNode *node) 301 311 { 302 while( node &&!node->isNodeVisible())312 while(!node->isNodeVisible()) 303 313 { 304 314 node->setNodeVisible(true); 305 node = static_cast<SceneNode *>(node->getParent()); 315 316 if(node != mSceneRoot) 317 node = static_cast<SceneNode *>(node->getParent()); 306 318 } 307 319 } … … 314 326 mOcclusionQueries.clear(); 315 327 } 328 //----------------------------------------------------------------------- 329 void OcclusionCullingSceneManager::renderBoundingBox(SceneNode *node) 330 { 331 // Render two halfes of the bounding box (using triangle fans) 332 for(int half=0; half < 2; half ++) 333 { 334 getSolidHalfBoundingBox(half)->setupBoundingBox(node->_getWorldAABB()); 335 SceneManager::renderSingleObject(getSolidHalfBoundingBox(half), 336 getSolidHalfBoundingBox(half)->getTechnique()->getPass(0), false); 337 } 338 } 339 //----------------------------------------------------------------------- 340 SolidHalfBoundingBox *OcclusionCullingSceneManager::getSolidHalfBoundingBox(int half) 341 { 342 if(!mHalfBoundingBox[half]) 343 mHalfBoundingBox[half] = new SolidHalfBoundingBox(half == 1); 344 345 return mHalfBoundingBox[half]; 346 } 347 //----------------------------------------------------------------------- 348 void OcclusionCullingSceneManager::setAlgorithmType(int type) 349 { 350 mAlgorithmType = type; 351 } 352 //----------------------------------------------------------------------- 353 int OcclusionCullingSceneManager::getAlgorithmType() 354 { 355 return mAlgorithmType; 356 } 316 357 }
Note: See TracChangeset
for help on using the changeset viewer.