#ifndef __RENDERTRAVERSER_H #define __RENDERTRAVERSER_H #include #include #include "glInterface.h" #include "Bvh.h" #include "OcclusionQuery.h" namespace CHCDemo { class Camera; class Matrix4x4; struct TraversalStatistics { friend class RenderTraverser; public: ////////// //-- several statistics for a rendering pass long GetRenderTime(); int GetNumTraversedNodes(); int GetNumQueryCulledNodes(); int GetNumFrustumCulledNodes(); int GetNumRenderedGeometry(); protected: // statistics int mNumTraversedNodes; int mNumQueryCulledNodes; int mNumFrustumCulledNodes; int mNumRenderedGeometry; long mRenderTime; }; //typedef std::priority_queue, myless::value_type> > TraversalQueue; typedef std::priority_queue, myless> TraversalQueue; /** Abstract class implementing a scene traversal for rendering. */ class RenderTraverser { public: //enum {RENDER_CULL_FRUSTUM, RENDER_STOP_AND_WAIT, RENDER_COHERENT, NUM_RENDERMODES}; RenderTraverser(); ~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 */ virtual void Render() = 0; /** Sets the scene hierarchy. */ void SetHierarchy(Bvh *bvh); /** Sets the camera. */ void SetCamera(Camera *cam) {mCamera = cam;} /** sets view projection matrix */ //void SetProjViewMatrix(Matrix4x4 const &projViewMatrix); /** Sets visible pixels threshold for visibility classification */ void SetVisibilityThreshold(int threshold); /** Returns visibility threshold */ int GetVisibilityThreshold() const; /** 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); /** Sets the current render state */ void SetRenderState(RenderState *state); void RenderFrustum(); protected: /** does some important initializations */ void Preprocess(); /** Hierarchy traversal */ void TraverseNode(BvhNode *node); /** Visibility is pulled up from visibility of children */ void PullUpVisibility(BvhNode *node); /** Issues occlusion query for specified node */ OcclusionQuery *IssueOcclusionQuery(BvhNode *node, bool wasVisible); /** Resets occlusion queries after a traversal */ void DelQueries(); /** Does view frustum culling. returns intersect (if intersects view plane) */ bool InsideViewFrustum(BvhNode *node, bool &intersects); /** switches to normal render mode */ void Switch2GLRenderState(); /** switches to occlusion query mode (geometry not rendered on the screen) */ void Switch2GLQueryState(); void EnqueueNode(BvhNode *node); void RenderBox(const AxisAlignedBox3 &box); //////////// //-- members // /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]; /// the current camera Camera *mCamera; //Matrix4x4 mProjViewMatrix; /// the root of the scene hierarchy Bvh *mBvh; /// use a priority queue rather than a renderstack TraversalQueue mDistanceQueue; int mFrameID; int mVisibilityThreshold; //unsigned int *mOcclusionQueries; int mCurrentQueryIdx; bool mIsQueryMode; //bool mIntersects; bool mUseOptimization; RenderState *mRenderState; QueryHandler mQueryHandler; }; } #endif // RENDERTRAVERSER_H