#ifndef __RENDERQUEUE_H #define __RENDERQUEUE_H #include "common.h" #include "Timer/PerfTimer.h" namespace CHCDemoEngine { class RenderState; class Camera; /** Defines a bucket for scene entities that have the same properties. */ struct RenderQueueBucket { /** should test for all texture format parameters, but we as use the same format for all textures they differ only in size */ int mTexHeight; int mTexWidth; bool mHasTexture; bool mAlphaTestEnabled; bool mCullFaceEnabled; /// minimal distance to the camera float mMinDistance; ShapeContainer mShapes; }; /** This class implements a render queue that sorts renderable geometry in order to minimize state changes while approximately keeping front-to-back order The implementation roughly follows the suggested implemenation on Tom Forsyth's article on render state changes. It requires sorting only on bucket level and therefore has very low overhead */ class RenderQueue { public: /** Default constructor */ RenderQueue(); /** Constructor taking a render queue */ RenderQueue(RenderState *state, Camera *cam); ~RenderQueue(); /** Enqueues an entity. */ void Enqueue(SceneEntity *entity); /** Sets the current render state */ void SetRenderState(RenderState *state); /** Sets the current render state */ void SetCamera(Camera *cam); /** Returns the number of entries currently in the queue. */ inline int GetSize() const { return (int)mNumEntries; } /** Renders and clears the queue. */ void Apply(); protected: void Sort(); void Enqueue(Shape *shape); inline bool FitsInBucket(Shape *shape, size_t idx) const; /** Clears the render queue */ void Clear(); /** Renders the contents of the render queue. */ void Render(); /** Prints the current state of the render queue. */ void Print(); /////////// RenderState *mState; Camera *mCamera; //SceneEntityContainer mEntities; int mMinSizeForSorting; /// each bucket contains objects with similar materials that don't cause a hard state change std::vector mBuckets; int mNumEntries; }; } #endif