[59] | 1 | #include "CoherentHierarchicalCullingManager.h" |
---|
[115] | 2 | //#include <OgreLogManager.h> |
---|
[59] | 3 | |
---|
| 4 | namespace GtpVisibility { |
---|
| 5 | |
---|
| 6 | //----------------------------------------------------------------------- |
---|
| 7 | void CoherentHierarchicalCullingManager::RenderScene() |
---|
| 8 | { |
---|
[85] | 9 | QueryQueue queryQueue; |
---|
[86] | 10 | unsigned int visiblePixels = 0; |
---|
| 11 | bool isAvailable = false; |
---|
[87] | 12 | |
---|
[59] | 13 | //-- PART 1: process finished occlusion queries |
---|
| 14 | while (!mHierarchyInterface->GetQueue()->empty() || !queryQueue.empty()) |
---|
| 15 | { |
---|
| 16 | while (!queryQueue.empty() && |
---|
[86] | 17 | queryQueue.front().second->GetQueryResult(visiblePixels, |
---|
| 18 | mHierarchyInterface->GetQueue()->empty())) |
---|
[59] | 19 | { |
---|
[94] | 20 | HierarchyNode *node = queryQueue.front().first; |
---|
[115] | 21 | |
---|
[59] | 22 | queryQueue.pop(); |
---|
| 23 | |
---|
[96] | 24 | if (visiblePixels > mVisibilityThreshold) |
---|
[59] | 25 | { |
---|
| 26 | mHierarchyInterface->PullUpVisibility(node); |
---|
| 27 | mHierarchyInterface->TraverseNode(node); |
---|
| 28 | } |
---|
| 29 | else |
---|
[112] | 30 | { //if (mHierarchyInterface->mIsShadowPass) |
---|
[59] | 31 | mNumQueryCulledNodes ++; |
---|
[112] | 32 | |
---|
| 33 | if(mVisualizeCulledNodes) |
---|
| 34 | { |
---|
| 35 | mHierarchyInterface->VisualizeCulledNode(node, QUERY_CULLED); |
---|
| 36 | } |
---|
[59] | 37 | } |
---|
[85] | 38 | } |
---|
[87] | 39 | |
---|
[59] | 40 | //-- PART 2: hierarchical traversal |
---|
| 41 | if (!mHierarchyInterface->GetQueue()->empty()) |
---|
| 42 | { |
---|
| 43 | HierarchyNode *node = mHierarchyInterface->GetQueue()->top(); |
---|
| 44 | mHierarchyInterface->GetQueue()->pop(); |
---|
| 45 | |
---|
| 46 | bool intersects = false; |
---|
| 47 | |
---|
[74] | 48 | if (!mHierarchyInterface->CheckFrustumVisible(node, intersects)) |
---|
[130] | 49 | { |
---|
[59] | 50 | mNumFrustumCulledNodes ++; |
---|
[112] | 51 | |
---|
| 52 | if(mVisualizeCulledNodes) |
---|
| 53 | { |
---|
[113] | 54 | mHierarchyInterface->VisualizeCulledNode(node, FRUSTUM_CULLED); |
---|
[112] | 55 | } |
---|
[59] | 56 | } |
---|
[74] | 57 | else |
---|
[59] | 58 | { |
---|
[74] | 59 | // if intersects near plane => skip occlusion query because wrong results possible |
---|
| 60 | if (intersects) |
---|
| 61 | { |
---|
| 62 | // update octant's visited flag |
---|
| 63 | mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); |
---|
[59] | 64 | |
---|
[74] | 65 | mHierarchyInterface->PullUpVisibility(node); |
---|
| 66 | mHierarchyInterface->TraverseNode(node); |
---|
[59] | 67 | |
---|
[74] | 68 | continue; |
---|
| 69 | } |
---|
[59] | 70 | |
---|
[74] | 71 | // identify previously visible nodes |
---|
| 72 | bool wasVisible = mHierarchyInterface->IsNodeVisible(node) && |
---|
| 73 | (mHierarchyInterface->LastVisited(node) == mHierarchyInterface->GetFrameId() - 1); |
---|
[59] | 74 | |
---|
[74] | 75 | // identify nodes that we cannot skip queries for |
---|
[87] | 76 | // geometry not only in leaves => test for renderable geometry |
---|
| 77 | bool issueQuery = !wasVisible || mHierarchyInterface->HasGeometry(node); |
---|
[95] | 78 | |
---|
[74] | 79 | // reset node's visibility classification |
---|
| 80 | mHierarchyInterface->SetNodeVisible(node, false); |
---|
[59] | 81 | |
---|
[74] | 82 | // update node's visited flag |
---|
| 83 | mHierarchyInterface->SetLastVisited(node, mHierarchyInterface->GetFrameId()); |
---|
[59] | 84 | |
---|
[87] | 85 | // skip testing previously visible nodes without geometry |
---|
| 86 | if (issueQuery) |
---|
[74] | 87 | { |
---|
[87] | 88 | mNumQueriesIssued ++; |
---|
| 89 | |
---|
| 90 | queryQueue.push(QueryPair(node, mHierarchyInterface-> |
---|
| 91 | IssueOcclusionQuery(node, wasVisible))); |
---|
[74] | 92 | } |
---|
[59] | 93 | |
---|
[74] | 94 | // always traverse a node if it was visible |
---|
| 95 | if (wasVisible) |
---|
| 96 | { |
---|
| 97 | mHierarchyInterface->TraverseNode(node); |
---|
| 98 | } |
---|
[59] | 99 | } |
---|
| 100 | } |
---|
| 101 | } |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | } // namespace GtpVisibility |
---|