#include "CoherentHierarchicalCullingManager.h" #include namespace GtpVisibility { //----------------------------------------------------------------------- void CoherentHierarchicalCullingManager::RenderScene() { //InitFrame(); QueryQueue queryQueue; unsigned int visiblePixels = 0; bool isAvailable = false; //-- PART 1: process finished occlusion queries while (!mHierarchyInterface->GetQueue()->empty() || !queryQueue.empty()) { while (!queryQueue.empty() && queryQueue.front().second->GetQueryResult(visiblePixels, mHierarchyInterface->GetQueue()->empty())) { HierarchyNode *node = queryQueue.front().first; queryQueue.pop(); if (visiblePixels > mVisibilityThreshold) { mHierarchyInterface->PullUpVisibility(node); mHierarchyInterface->TraverseNode(node); } else { if (mHierarchyInterface->mDummy) mNumQueryCulledNodes ++; } } //-- PART 2: hierarchical traversal if (!mHierarchyInterface->GetQueue()->empty()) { HierarchyNode *node = mHierarchyInterface->GetQueue()->top(); mHierarchyInterface->GetQueue()->pop(); bool intersects = false; if (!mHierarchyInterface->CheckFrustumVisible(node, intersects)) { if (mHierarchyInterface->mDummy) mNumFrustumCulledNodes ++; } else { // if intersects near plane => skip occlusion query because wrong results possible if (intersects) { // update octant's visited flag mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); mHierarchyInterface->PullUpVisibility(node); mHierarchyInterface->TraverseNode(node); continue; } // identify previously visible nodes bool wasVisible = mHierarchyInterface->IsNodeVisible(node) && (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId() - 1); // identify nodes that we cannot skip queries for // geometry not only in leaves => test for renderable geometry bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node); // reset node's visibility classification mHierarchyInterface->SetNodeVisible(node, false); // update node's visited flag mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); // skip testing previously visible nodes without geometry if (issueQuery) { mNumQueriesIssued ++; queryQueue.push(QueryPair(node, mHierarchyInterface-> IssueOcclusionQuery(node, wasVisible))); } // always traverse a node if it was visible if (wasVisible) { mHierarchyInterface->TraverseNode(node); } } } } } } // namespace GtpVisibility