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