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

Revision 3054, 2.4 KB checked in by mattausch, 16 years ago (diff)

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