1 | #ifndef __RENDERTRAVERSER_H
|
---|
2 | #define __RENDERTRAVERSER_H
|
---|
3 |
|
---|
4 | #include <queue>
|
---|
5 | #include "Bvh.h"
|
---|
6 | #include "OcclusionQuery.h"
|
---|
7 | #include "Camera.h"
|
---|
8 | #include "RenderQueue.h"
|
---|
9 |
|
---|
10 |
|
---|
11 |
|
---|
12 | namespace CHCDemo
|
---|
13 | {
|
---|
14 |
|
---|
15 | class Camera;
|
---|
16 | class Matrix4x4;
|
---|
17 |
|
---|
18 |
|
---|
19 |
|
---|
20 | struct TraversalStatistics
|
---|
21 | {
|
---|
22 | public:
|
---|
23 |
|
---|
24 | void Reset();
|
---|
25 |
|
---|
26 | //////////
|
---|
27 | //-- several statistics for a rendering pass
|
---|
28 |
|
---|
29 | int mNumTraversedNodes;
|
---|
30 | int mNumQueryCulledNodes;
|
---|
31 | int mNumFrustumCulledNodes;
|
---|
32 | int mNumRenderedGeometry;
|
---|
33 | int mNumRenderedTriangles;
|
---|
34 | int mNumIssuedQueries;
|
---|
35 |
|
---|
36 | long mRenderTime;
|
---|
37 | };
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | /** Abstract class implementing a scene traversal for rendering.
|
---|
42 | */
|
---|
43 | class RenderTraverser
|
---|
44 | {
|
---|
45 | public:
|
---|
46 |
|
---|
47 | enum {CULL_FRUSTUM, STOP_AND_WAIT, CHC, CHCPLUSPLUS, NUM_RENDERMODES};
|
---|
48 |
|
---|
49 | RenderTraverser();
|
---|
50 | ~RenderTraverser();
|
---|
51 |
|
---|
52 | //! Renders the scene with the specified method
|
---|
53 | /**
|
---|
54 | The method is one of
|
---|
55 | CULL_FRUSTUM: view frustum culling only
|
---|
56 | STOP_AND_WAIT: hierarchical stop and wait algorithm
|
---|
57 | CHC: coherent hierarchical algorithm
|
---|
58 | CHCPLUSPLUS: coherent hierarchical algorithm revisited
|
---|
59 | */
|
---|
60 | void RenderScene();
|
---|
61 | /** Sets the scene hierarchy.
|
---|
62 | */
|
---|
63 | void SetHierarchy(Bvh *bvh);
|
---|
64 | /** Sets the camera.
|
---|
65 | */
|
---|
66 | void SetCamera(Camera *cam) {mCamera = cam;}
|
---|
67 | /** Sets visible pixels threshold for visibility classification
|
---|
68 | */
|
---|
69 | void SetVisibilityThreshold(int threshold);
|
---|
70 | /** Returns visibility threshold
|
---|
71 | */
|
---|
72 | int GetVisibilityThreshold() const;
|
---|
73 | /** renders a visualization of the hierarchy
|
---|
74 | */
|
---|
75 | void RenderVisualization();
|
---|
76 | /** use optimization to take leaf nodes instead of bounding box for occlusion queries
|
---|
77 | */
|
---|
78 | void SetUseOptimization(bool useOptimization);
|
---|
79 | /** Sets the current render state
|
---|
80 | */
|
---|
81 | void SetRenderState(RenderState *state);
|
---|
82 |
|
---|
83 | void SetUseRenderQueue(bool useRenderQueue);
|
---|
84 | const TraversalStatistics &GetStats() const { return mStats; }
|
---|
85 |
|
---|
86 | protected:
|
---|
87 |
|
---|
88 | /** This is the actual rendering algorithm. It must be implemented by all
|
---|
89 | the subclasses.
|
---|
90 | */
|
---|
91 | virtual void Traverse() = 0;
|
---|
92 | /** Hierarchy traversal
|
---|
93 | */
|
---|
94 | void TraverseNode(BvhNode *node);
|
---|
95 | /** Issues occlusion query for specified node
|
---|
96 | */
|
---|
97 | OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible);
|
---|
98 | /** switches to normal render mode
|
---|
99 | */
|
---|
100 | void Switch2GLRenderState();
|
---|
101 | /** switches to occlusion query mode (geometry not rendered on the screen)
|
---|
102 | */
|
---|
103 | void Switch2GLQueryState();
|
---|
104 | /** Retunrs true if the current bvh node intersects the near plane.
|
---|
105 | */
|
---|
106 | inline bool IntersectsNearPlane(BvhNode *node) const;
|
---|
107 | /** Enqueues a bvh node.
|
---|
108 | */
|
---|
109 | void EnqueueNode(BvhNode *node);
|
---|
110 |
|
---|
111 |
|
---|
112 |
|
---|
113 | ////////////
|
---|
114 | //-- members
|
---|
115 |
|
---|
116 | /// the current camera
|
---|
117 | Camera *mCamera;
|
---|
118 | /// the root of the scene hierarchy
|
---|
119 | Bvh *mBvh;
|
---|
120 | /// the priority queue used for front to back traversal
|
---|
121 | TraversalQueue mDistanceQueue;
|
---|
122 | /// the current frame id
|
---|
123 | int mFrameId;
|
---|
124 |
|
---|
125 | bool mIsQueryMode;
|
---|
126 |
|
---|
127 | RenderState *mRenderState;
|
---|
128 |
|
---|
129 | QueryHandler mQueryHandler;
|
---|
130 |
|
---|
131 | TraversalStatistics mStats;
|
---|
132 |
|
---|
133 | QueryQueue mQueryQueue;
|
---|
134 |
|
---|
135 | int mVisibilityThreshold;
|
---|
136 |
|
---|
137 | bool mUseOptimization;
|
---|
138 |
|
---|
139 | RenderQueue mRenderQueue;
|
---|
140 |
|
---|
141 | bool mUseRenderQueue;
|
---|
142 | };
|
---|
143 |
|
---|
144 |
|
---|
145 | inline bool RenderTraverser::IntersectsNearPlane(BvhNode *node) const
|
---|
146 | {
|
---|
147 | return mBvh->GetDistance(node) < mCamera->GetNear();
|
---|
148 | }
|
---|
149 |
|
---|
150 |
|
---|
151 | }
|
---|
152 |
|
---|
153 |
|
---|
154 |
|
---|
155 | #endif // RENDERTRAVERSER_H |
---|