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

Revision 3060, 2.7 KB checked in by mattausch, 16 years ago (diff)

updated render queue: as we assume incoming nodes to be sorted front to back,
no sorting is required anymore

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 taking a render queue
66        */
67        RenderQueue(RenderState *state, Camera *cam);
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        /** Sets the current render state
80        */
81        void SetCamera(Camera *cam);
82        /** Returns the number of entries currently in the queue.
83        */
84        inline int GetSize() const { return (int)mNumEntries; }
85        /** Renders and clears the queue.
86        */
87        void Apply();
88        /** Clears the render queue
89        */
90        void Clear();
91
92protected:
93
94        //void Sort();
95
96        inline bool FitsInBucket(Shape *shape, size_t idx) const;
97        /** Renders the contents of the render queue.
98        */
99        void Render();
100        /** Prints the current state of the render queue.
101        */
102        void Print();
103
104
105        ///////////
106        //-- members
107
108        // the current render state
109        RenderState *mState;
110       
111        Camera *mCamera;
112        /// each bucket contains objects with similar materials that don't cause a hard state change
113        std::vector<RenderQueueBucket *> mBuckets;
114        /// this are the buckets that where touched until the last clear. They are sorted by distance
115        std::vector<RenderQueueBucket *> mActiveBuckets;
116
117        int mNumEntries;
118};
119
120
121}
122
123#endif
Note: See TracBrowser for help on using the repository browser.