[10] | 1 | #ifndef NO_PRAGMA_ONCE |
---|
| 2 | #pragma once |
---|
| 3 | #endif |
---|
| 4 | |
---|
| 5 | #ifndef RENDERTRAVERSER_H |
---|
| 6 | #define RENDERTRAVERSER_H |
---|
| 7 | |
---|
| 8 | #include "glInterface.h" |
---|
| 9 | #include "HierarchyNode.h" |
---|
| 10 | #include <queue> |
---|
| 11 | //#include <priority_queue> |
---|
| 12 | #include <stack> |
---|
| 13 | |
---|
| 14 | using namespace std; |
---|
| 15 | |
---|
| 16 | typedef stack<HierarchyNode *> TraversalStack; |
---|
| 17 | typedef queue<HierarchyNode *> QueryQueue; |
---|
| 18 | typedef priority_queue<HierarchyNode *, vector<HierarchyNode *>, myless<vector<HierarchyNode *>::value_type> > PriorityQueue; |
---|
| 19 | |
---|
| 20 | class RenderTraverser |
---|
| 21 | { |
---|
| 22 | public: |
---|
| 23 | enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES}; |
---|
| 24 | |
---|
| 25 | RenderTraverser(); |
---|
| 26 | //! Renders the scene with the specified method |
---|
| 27 | /** |
---|
| 28 | The mode is one of |
---|
| 29 | RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only |
---|
| 30 | RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm |
---|
| 31 | RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm |
---|
| 32 | */ |
---|
| 33 | void Render(int mode=RENDER_CULL_FRUSTUM); |
---|
| 34 | //! sets the scene hierarchy. |
---|
| 35 | void SetHierarchy(HierarchyNode *sceneRoot); |
---|
| 36 | //! sets viewpoint |
---|
| 37 | void SetViewpoint(Vector3 const &viewpoint); |
---|
| 38 | //! sets view projection matrix |
---|
| 39 | void SetProjViewMatrix(Matrix4x4 const &projViewMatrix); |
---|
| 40 | //! returns root of hierarchy |
---|
| 41 | HierarchyNode *GetHierarchy(); |
---|
| 42 | //! sets visible pixels threshold for visibility classification |
---|
| 43 | void SetVisibilityThreshold(int threshold); |
---|
| 44 | //! returns visibility threshold |
---|
| 45 | int GetVisibilityThreshold(); |
---|
| 46 | |
---|
| 47 | // several statistics for a rendering pass |
---|
| 48 | long GetRenderTime(); |
---|
[22] | 49 | int GetNumTraversedNodes(); |
---|
[10] | 50 | int GetNumQueryCulledNodes(); |
---|
| 51 | int GetNumFrustumCulledNodes(); |
---|
| 52 | int GetNumRenderedGeometry(); |
---|
| 53 | |
---|
| 54 | //! renders a visualization of the hierarchy |
---|
| 55 | void RenderVisualization(); |
---|
| 56 | |
---|
| 57 | //! use optimization to take leaf nodes instead of bounding box for occlusion queries |
---|
| 58 | void SetUseOptimization(bool useOptimization); |
---|
| 59 | |
---|
[724] | 60 | //! if arb queries should be used instead of nv |
---|
| 61 | void SetUseArbQueries(const bool useArbQueries); |
---|
| 62 | //! see set |
---|
| 63 | bool GetUseArbQueries() const; |
---|
| 64 | |
---|
[10] | 65 | protected: |
---|
| 66 | |
---|
| 67 | //! renders the scene with view frustum culling only |
---|
| 68 | void RenderCullFrustum(); |
---|
| 69 | //! renders the scene with the hierarchical stop and wait algorithm |
---|
| 70 | void RenderStopAndWait(); |
---|
| 71 | //! renders the scene with the coherent hierarchical algorithm and the query queye |
---|
| 72 | void RenderCoherentWithQueue(); |
---|
| 73 | //! does some importand initialisations |
---|
| 74 | void Preprocess(); |
---|
| 75 | |
---|
| 76 | //! returns occlusion query result for specified node |
---|
[724] | 77 | unsigned int GetOcclusionQueryResult(HierarchyNode *node) const; |
---|
[10] | 78 | //! the node is traversed as usual |
---|
| 79 | void TraverseNode(HierarchyNode *node); |
---|
| 80 | //! visibility is pulled up from visibility of children |
---|
| 81 | void PullUpVisibility(HierarchyNode *node); |
---|
| 82 | //! is result available from query queue? |
---|
[724] | 83 | bool ResultAvailable(HierarchyNode *node) const; |
---|
[10] | 84 | //! issues occlusion query for specified node |
---|
| 85 | void IssueOcclusionQuery(HierarchyNode *node, bool wasVisible); |
---|
| 86 | //! resets occlusion queries after a traversal |
---|
[724] | 87 | void DelQueries(); |
---|
[10] | 88 | //! does view frustum culling. returns intersect (if intersects view plane) |
---|
| 89 | bool InsideViewFrustum(HierarchyNode *node, bool &intersects); |
---|
| 90 | //! switches to normal render mode |
---|
| 91 | void Switch2GLRenderState(); |
---|
| 92 | //! switches to occlusion query mode (geometry not rendered on the screen) |
---|
| 93 | void Switch2GLQueryState(); |
---|
| 94 | |
---|
[724] | 95 | |
---|
[10] | 96 | protected: |
---|
| 97 | |
---|
[724] | 98 | /// if arb queries should be instead of nv |
---|
| 99 | bool mUseArbQueries; |
---|
| 100 | |
---|
[10] | 101 | // the current clip planes of the view frustum |
---|
| 102 | VecPlane mClipPlanes; |
---|
| 103 | // the indices of the np-vertices of the bounding box for view frustum culling |
---|
| 104 | int mNPVertexIndices[12]; |
---|
| 105 | |
---|
[724] | 106 | // the current view point |
---|
[10] | 107 | Vector3 mViewpoint; |
---|
| 108 | Matrix4x4 mProjViewMatrix; |
---|
[724] | 109 | // the root of the scene hierarchy |
---|
[10] | 110 | HierarchyNode *mHierarchyRoot; |
---|
| 111 | //TraversalStack mTraversalStack; |
---|
| 112 | PriorityQueue mDistanceQueue; // use a priority queue rather than a renderstack |
---|
| 113 | |
---|
| 114 | //priority_queue<vector<HierarchyNode *>, HierarchyNode *> mPriorityQueue; |
---|
| 115 | int mFrameID; |
---|
| 116 | int mVisibilityThreshold; |
---|
| 117 | unsigned int *mOcclusionQueries; |
---|
[724] | 118 | int mCurrentQueryIdx; |
---|
[10] | 119 | bool mIsQueryMode; |
---|
| 120 | |
---|
| 121 | bool mIntersects; |
---|
| 122 | |
---|
| 123 | // statistics |
---|
| 124 | int mNumTraversedNodes; |
---|
| 125 | int mNumQueryCulledNodes; |
---|
| 126 | int mNumFrustumCulledNodes; |
---|
| 127 | int mNumRenderedGeometry; |
---|
| 128 | |
---|
| 129 | long mRenderTime; |
---|
| 130 | |
---|
| 131 | bool mUseOptimization; |
---|
| 132 | }; |
---|
| 133 | |
---|
| 134 | #endif // RENDERTRAVERSER_H |
---|