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