source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h @ 3061

Revision 3061, 2.5 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef __RENDERQUEUE_H
2#define __RENDERQUEUE_H
3
4#include "common.h"
5#include "Timer/PerfTimer.h"
6
7
8namespace CHCDemoEngine
9{
10
11class RenderState;
12class Camera;
13
14
15/** Defines a bucket for scene entities that have the same properties.
16*/
17struct RenderQueueBucket
18{
19        inline bool IsEmpty() const { return mShapes.empty();}
20
21        ////////
22        //-- the attributes used to sort the materials
23       
24        // texture related parameters
25        int mTexHeight;
26        int mTexWidth;
27        int mTexFormat;
28
29        bool mHasTexture;
30
31        bool mColorWriteEnabled;
32        bool mDepthWriteEnabled;
33        bool mLightingEnabled;
34
35        bool mAlphaTestEnabled;
36        bool mCullFaceEnabled;
37
38        //bool mHasVertexProgram;
39        //bool mHasFragmentProgram;
40        ShaderProgram *mVertexProgram;
41        ShaderProgram *mFragmentProgram;
42
43        /// minimal distance to the camera
44        //float mMinDistance;
45
46        /// the shapes that belong to a bucket
47        ShapeContainer mShapes;
48};
49
50
51/** This class implements a render queue that sorts renderable geometry in order
52        to minimize state changes while approximately keeping front-to-back order
53        The implementation roughly follows the suggested implementation in
54        Tom Forsyth's article on render state changes. It assumes that the incoming
55        objecs are roughly front to back level and therefore does not require any sorting
56        and therefore has very  low overhead.
57*/
58class RenderQueue
59{
60public:
61
62        /** Default constructor
63        */
64        RenderQueue();
65        /** Constructor passing the current render state
66        */
67        RenderQueue(RenderState *state);
68
69        ~RenderQueue();
70        /** Enqueues an entity.
71        */
72        void Enqueue(SceneEntity *entity);
73        /** Enqueues a single shape.
74        */
75        void Enqueue(Shape *shape);
76        /** Sets the current render state
77        */
78        void SetRenderState(RenderState *state);
79        /** Returns the number of entries currently in the queue.
80        */
81        inline int GetSize() const { return (int)mNumEntries; }
82        /** Renders and clears the queue.
83        */
84        void Apply();
85        /** Clears the render queue
86        */
87        void Clear();
88
89protected:
90
91        //void Sort();
92
93        inline bool FitsInBucket(Shape *shape, size_t idx) const;
94        /** Renders the contents of the render queue.
95        */
96        void Render();
97
98
99        ///////////
100        //-- members
101
102        // the current render state
103        RenderState *mState;
104        /// each bucket contains objects with similar materials that don't cause a hard state change
105        std::vector<RenderQueueBucket *> mBuckets;
106        /// this are the buckets that where touched until the last clear. They are sorted by distance
107        std::vector<RenderQueueBucket *> mActiveBuckets;
108
109        int mNumEntries;
110};
111
112
113}
114
115#endif
Note: See TracBrowser for help on using the repository browser.