#ifndef NO_PRAGMA_ONCE #pragma once #endif #ifndef RENDERTRAVERSER_H #define RENDERTRAVERSER_H #include "glInterface.h" #include "HierarchyNode.h" #include //#include #include using namespace std; typedef stack TraversalStack; typedef queue QueryQueue; typedef priority_queue, myless::value_type> > PriorityQueue; class RenderTraverser { public: enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES}; RenderTraverser(); //! Renders the scene with the specified method /** The mode is one of RENDER_CULL_FRUSTUM: renders the scene with view frustum culling only RENDER_STOP_AND_WAIT: renders the scene with the hierarchical stop and wait algorithm RENDER_COHERENT: renders the scene with the coherent hierarchical algorithm */ void Render(int mode=RENDER_CULL_FRUSTUM); //! sets the scene hierarchy. void SetHierarchy(HierarchyNode *sceneRoot); //! sets viewpoint void SetViewpoint(Vector3 const &viewpoint); //! sets view projection matrix void SetProjViewMatrix(Matrix4x4 const &projViewMatrix); //! returns root of hierarchy HierarchyNode *GetHierarchy(); //! sets visible pixels threshold for visibility classification void SetVisibilityThreshold(int threshold); //! returns visibility threshold int GetVisibilityThreshold(); // several statistics for a rendering pass long GetRenderTime(); int GetNumTraversedNodes(); int GetNumQueryCulledNodes(); int GetNumFrustumCulledNodes(); int GetNumRenderedGeometry(); //! renders a visualization of the hierarchy void RenderVisualization(); //! use optimization to take leaf nodes instead of bounding box for occlusion queries void SetUseOptimization(bool useOptimization); protected: //! renders the scene with view frustum culling only void RenderCullFrustum(); //! renders the scene with the hierarchical stop and wait algorithm void RenderStopAndWait(); //! renders the scene with the coherent hierarchical algorithm and the query queye void RenderCoherentWithQueue(); //! does some importand initialisations void Preprocess(); //! returns occlusion query result for specified node int GetOcclusionQueryResult(HierarchyNode *node); //! the node is traversed as usual void TraverseNode(HierarchyNode *node); //! visibility is pulled up from visibility of children void PullUpVisibility(HierarchyNode *node); //! is result available from query queue? bool ResultAvailable(HierarchyNode *node); //! issues occlusion query for specified node void IssueOcclusionQuery(HierarchyNode *node, bool wasVisible); //! resets occlusion queries after a traversal void ResetQueries(); //! does view frustum culling. returns intersect (if intersects view plane) bool InsideViewFrustum(HierarchyNode *node, bool &intersects); //! switches to normal render mode void Switch2GLRenderState(); //! switches to occlusion query mode (geometry not rendered on the screen) void Switch2GLQueryState(); protected: // the current clip planes of the view frustum VecPlane mClipPlanes; // the indices of the np-vertices of the bounding box for view frustum culling int mNPVertexIndices[12]; Vector3 mViewpoint; Matrix4x4 mProjViewMatrix; HierarchyNode *mHierarchyRoot; //TraversalStack mTraversalStack; PriorityQueue mDistanceQueue; // use a priority queue rather than a renderstack //priority_queue, HierarchyNode *> mPriorityQueue; int mFrameID; int mVisibilityThreshold; unsigned int *mOcclusionQueries; int mCurrentTestIdx; bool mIsQueryMode; bool mIntersects; // statistics int mNumTraversedNodes; int mNumQueryCulledNodes; int mNumFrustumCulledNodes; int mNumRenderedGeometry; long mRenderTime; bool mUseOptimization; }; #endif // RENDERTRAVERSER_H