#ifndef __RENDERQUEUE_H #define __RENDERQUEUE_H #include "common.h" namespace CHCDemoEngine { class RenderState; class Camera; typedef std::pair ShapePair; typedef std::vector ShapePairArray; /** Defines a bucket for scene entities that have the same properties. */ struct RenderQueueBucket { inline bool IsEmpty() const { return mShapes.empty();} //////// //-- the attributes used to sort the materials // texture related parameters int mTexHeight; int mTexWidth; int mTexFormat; bool mHasTexture; bool mColorWriteEnabled; bool mDepthWriteEnabled; bool mLightingEnabled; bool mAlphaTestEnabled; bool mCullFaceEnabled; //bool mHasVertexProgram; //bool mHasFragmentProgram; ShaderProgram *mVertexProgram; ShaderProgram *mFragmentProgram; /// the shapes that belong to a bucket ShapePairArray mShapes; /// minimal distance to the camera //float mMinDistance; }; /** 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 implementation in Tom Forsyth's article on render state changes. It assumes that the incoming objecs are roughly front to back level and therefore does not require any sorting and therefore has very low overhead. */ class RenderQueue { public: /** Default constructor */ RenderQueue(); /** Constructor passing the current render state */ RenderQueue(RenderState *state); ~RenderQueue(); /** Enqueues all the shapes of an entity. */ void Enqueue(SceneEntity *entity); /** Enqueues a single shape. We also have to pass the entity which contains the shape. */ void Enqueue(Shape *shape, SceneEntity *containingEnt); /** Sets the current render state */ void SetRenderState(RenderState *state); /** Returns the number of entries currently in the queue. */ inline int GetSize() const { return (int)mNumEntries; } /** Renders and clears the queue. */ void Apply(); /** Clears the render queue */ void Clear(); protected: //void Sort(); inline bool FitsInBucket(Shape *shape, size_t idx) const; /** Renders the contents of the render queue. */ void Render(); /////////// //-- members // the current render state RenderState *mState; /// each bucket contains objects with similar materials that don't cause a hard state change std::vector mBuckets; /// this are the buckets that where touched until the last clear. They are sorted by distance std::vector mActiveBuckets; int mNumEntries; }; } #endif