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