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

Revision 3051, 2.3 KB checked in by mattausch, 16 years ago (diff)

included new material properties (vp, fp) into render queue

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        ////////
20        //-- the attributes used to sort the materials
21        /// texture parameters
22        int mTexHeight;
23        int mTexWidth;
24        int mTexFormat;
25
26        bool mHasTexture;
27
28        bool mColorWriteEnabled;
29        bool mDepthWriteEnabled;
30        bool mLightingEnabled;
31
32        bool mAlphaTestEnabled;
33        bool mCullFaceEnabled;
34
35        bool mHasVertexProgram;
36        bool mHasFragmentProgram;
37
38        /// minimal distance to the camera
39        float mMinDistance;
40
41        /// the shapes that belong to a bucket
42        ShapeContainer mShapes;
43};
44
45
46/** This class implements a render queue that sorts renderable geometry in order
47        to minimize state changes while approximately keeping front-to-back order
48        The implementation roughly follows the suggested implementation in
49        Tom Forsyth's article on render state changes. It requires sorting only on
50        bucket level and therefore has very     low overhead.
51*/
52class RenderQueue
53{
54public:
55
56        /** Default constructor
57        */
58        RenderQueue();
59        /** Constructor taking a render queue
60        */
61        RenderQueue(RenderState *state, Camera *cam);
62
63        ~RenderQueue();
64        /** Enqueues an entity.
65        */
66        void Enqueue(SceneEntity *entity);
67        /** Sets the current render state
68        */
69        void SetRenderState(RenderState *state);
70        /** Sets the current render state
71        */
72        void SetCamera(Camera *cam);
73        /** Returns the number of entries currently in the queue.
74        */
75        inline int GetSize() const { return (int)mNumEntries; }
76        /** Renders and clears the queue.
77        */
78        void Apply();
79
80
81protected:
82
83        void Sort();
84
85        void Enqueue(Shape *shape);
86
87        inline bool FitsInBucket(Shape *shape, size_t idx) const;
88        /** Clears the render queue
89        */
90        void Clear();
91        /** Renders the contents of the render queue.
92        */
93        void Render();
94        /** Prints the current state of the render queue.
95        */
96        void Print();
97
98
99        ///////////
100
101        RenderState *mState;
102       
103        Camera *mCamera;
104        //SceneEntityContainer mEntities;
105        int mMinSizeForSorting;
106
107        /// each bucket contains objects with similar materials that don't cause a hard state change
108        std::vector<RenderQueueBucket *> mBuckets;
109
110        int mNumEntries;
111};
112
113
114}
115
116#endif
Note: See TracBrowser for help on using the repository browser.