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