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