1 | #include "CHCTraverser.h"
|
---|
2 |
|
---|
3 | namespace CHCDemo
|
---|
4 | {
|
---|
5 |
|
---|
6 | CHCTraverser::CHCTraverser(): RenderTraverser()
|
---|
7 | {
|
---|
8 | }
|
---|
9 |
|
---|
10 |
|
---|
11 | CHCTraverser::~CHCTraverser()
|
---|
12 | {
|
---|
13 | //DelQueries();
|
---|
14 | }
|
---|
15 |
|
---|
16 |
|
---|
17 | void CHCTraverser::Render()
|
---|
18 | {
|
---|
19 | #if 0
|
---|
20 | QueryQueue queryQueue;
|
---|
21 |
|
---|
22 | //-- PART 1: process finished occlusion queries
|
---|
23 | while (!mDistanceQueue.empty() || !queryQueue.empty())
|
---|
24 | {
|
---|
25 | while (!queryQueue.empty() &&
|
---|
26 | (ResultAvailable(queryQueue.front()) || mDistanceQueue.empty()))
|
---|
27 | {
|
---|
28 | HierarchyNode *node = queryQueue.front();
|
---|
29 | queryQueue.pop();
|
---|
30 |
|
---|
31 | // wait until result available
|
---|
32 | int visiblePixels = GetOcclusionQueryResult(node);
|
---|
33 |
|
---|
34 | if(visiblePixels > mVisibilityThreshold)
|
---|
35 | {
|
---|
36 | PullUpVisibility(node);
|
---|
37 | TraverseNode(node);
|
---|
38 | }
|
---|
39 | else
|
---|
40 | {
|
---|
41 | mNumQueryCulledNodes ++;
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | //-- PART 2: hierarchical traversal
|
---|
46 | if (!mDistanceQueue.empty())
|
---|
47 | {
|
---|
48 | HierarchyNode *node = mDistanceQueue.top();
|
---|
49 |
|
---|
50 | mDistanceQueue.pop();
|
---|
51 |
|
---|
52 | mNumTraversedNodes ++;
|
---|
53 |
|
---|
54 | bool intersects;
|
---|
55 |
|
---|
56 | if (InsideViewFrustum(node, intersects))
|
---|
57 | {
|
---|
58 | // for near plane intersecting bounding box possible
|
---|
59 | // wrong results => skip occlusion query
|
---|
60 | if(intersects)
|
---|
61 | {
|
---|
62 | // update node's visited flag
|
---|
63 | node->SetLastVisited(mFrameID);
|
---|
64 | node->SetVisible(true);
|
---|
65 | PullUpVisibility(node);
|
---|
66 | TraverseNode(node);
|
---|
67 | }
|
---|
68 | else
|
---|
69 | {
|
---|
70 | // identify previously visible nodes
|
---|
71 | bool wasVisible = node->Visible() && (node->LastVisited() == mFrameID - 1);
|
---|
72 |
|
---|
73 | // identify nodes that we cannot skip queries for
|
---|
74 | bool leafOrWasInvisible = (node->LastVisited() != mFrameID) && (!wasVisible || node->IsLeaf());
|
---|
75 |
|
---|
76 | // reset node's visibility classification
|
---|
77 | node->SetVisible(false);
|
---|
78 |
|
---|
79 | // update node's visited flag
|
---|
80 | node->SetLastVisited(mFrameID);
|
---|
81 |
|
---|
82 | // skip testing previously visible interior nodes
|
---|
83 | if(leafOrWasInvisible)
|
---|
84 | {
|
---|
85 | IssueOcclusionQuery(node, wasVisible);
|
---|
86 | queryQueue.push(node);
|
---|
87 | }
|
---|
88 |
|
---|
89 | // always traverse a node if it was visible
|
---|
90 | if(wasVisible)
|
---|
91 | TraverseNode(node);
|
---|
92 | }
|
---|
93 | }
|
---|
94 | else
|
---|
95 | {
|
---|
96 | // for stats
|
---|
97 | mNumFrustumCulledNodes ++;
|
---|
98 | }
|
---|
99 | }
|
---|
100 | }
|
---|
101 | #endif
|
---|
102 | }
|
---|
103 |
|
---|
104 | } |
---|