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