#include "OgreOcclusionCullingSceneManager.h" #include "OgreMath.h" #include "OgreIteratorWrappers.h" #include "OgreRenderSystem.h" #include "OgreCamera.h" #include namespace Ogre { //----------------------------------------------------------------------- OcclusionCullingSceneManager::OcclusionCullingSceneManager(): mFrameID(1), mDistanceQueue(NULL) { } void OcclusionCullingSceneManager::_findVisibleObjects(Camera* cam, bool onlyShadowCasters) { // empty because we have to find in _renderVisibleObjects } //----------------------------------------------------------------------- void OcclusionCullingSceneManager::_renderVisibleObjects(void) { mDistanceQueue = new PriorityQueue(myless(mCameraInProgress)); mDistanceQueue->push(mSceneRoot); //renderZPass(); renderCullFrustum(); delete mDistanceQueue; //mDestRenderSystem->_setDepthBufferParams(true, false, CMPF_LESS); //SceneManager::_renderVisibleObjects(); //mDestRenderSystem->_setDepthBufferParams(); //mDistanceQueue.push(mSceneRoot); //Preprocess(); //renderCullFrustum(); //mFrameID ++; //ResetQueries(); } //----------------------------------------------------------------------- void OcclusionCullingSceneManager::renderZPass() { traverseNode(mSceneRoot); } //----------------------------------------------------------------------- void OcclusionCullingSceneManager::renderCullFrustum() { while(!mDistanceQueue->empty()) { SceneNode *node = mDistanceQueue->top(); mDistanceQueue->pop(); // interesting for the visualization, so rest and set //node->SetVisible(false); if(mCameraInProgress->isVisible(node->_getWorldAABB())) { // update node's visited flag => needed for rendering // so set it also here //node->SetLastVisited(mFrameID); //node->SetVisible(true); traverseNode(node); } //else //MessageBox( NULL, "myplugin registered", "this is my plugin", MB_OK | MB_ICONERROR | MB_TASKMODAL); } } //----------------------------------------------------------------------- void OcclusionCullingSceneManager::traverseNode(SceneNode *node) { if(node->numChildren() == 0) // reached leaf { renderSceneNode(node); } else // internal node: add children to priority queue for further processing { Node::ChildNodeIterator it = node->getChildIterator(); char str[100]; sprintf(str, "number of children: %d", node->numChildren()); while (it.hasMoreElements()) { SceneNode* sceneChild = static_cast(it.getNext()); //mDistanceQueue->addRenderable(sceneChild); mDistanceQueue->push(sceneChild); } } /* static RenderOperation ro; node->getRenderOperation(ro); ro.srcRenderable = node; mDestRenderSystem->_render(ro); Pass pass(); renderSingleObject(node, &pass, true); */ } void OcclusionCullingSceneManager::renderSceneNode(SceneNode *node) { node->_findVisibleObjects(mCameraInProgress, getRenderQueue(), false, mDisplayNodes, false); SceneManager::_renderVisibleObjects(); getRenderQueue()->clear(); } }