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