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

Revision 2802, 2.2 KB checked in by mattausch, 16 years ago (diff)

worked on renderqueue

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        /** should be full texture format, but we as use the same format for all textures
20            they differ only in size, and we implicitly assume that textures with the same
21            size have exactly the same format
22        */
23        int mTextureSize;
24        bool mAlphaTestEnabled;
25
26        /// minimal distance to the camera
27        float mMinDistance;
28
29        SceneEntityContainer mEntities;
30};
31
32
33/** This class implements a render queue that sorts renderable geometry in order
34        to minimize state changes while approximately keeping front-to-back order
35        The implementation roughly follows the suggested implemenation on Tom Forsyth's article
36        on render state changes. It requires sorting only on bucket level and therefore has very
37        low overhead
38*/
39class RenderQueue
40{
41public:
42
43        /** Default constructor
44        */
45        RenderQueue();
46        /** Constructor taking a render queue
47        */
48        RenderQueue(RenderState *state, Camera *cam);
49
50        ~RenderQueue();
51        /** Enqueues an entity.
52        */
53        void Enqueue(SceneEntity *entity);
54        /** Sets the current render state
55        */
56        void SetRenderState(RenderState *state);
57        /** Sets the current render state
58        */
59        void SetCamera(Camera *cam);
60        /** Returns the number entities currently in the queue.
61        */
62        inline int GetSize() const { return (int)mSize; }
63        /** Renders and clears the queue.
64        */
65        void Apply();
66
67
68protected:
69
70        inline bool FitsInBucket(SceneEntity *ent, size_t idx) const;
71
72        /** Sorts the render queue by materials / textures.
73        */
74        void Sort();
75        /** Clears the render queue
76        */
77        void Clear();
78        /** Renders the contents of the render queue.
79        */
80        void Render();
81        /** Prints the current state of the render queue.
82        */
83        void Print();
84
85        ///////////
86
87        RenderState *mState;
88        Camera *mCamera;
89        //SceneEntityContainer mEntities;
90        int mMinSizeForSorting;
91
92        /// each bucket contains objects with similar materials that don't cause a hard state change
93        std::vector<RenderQueueBucket *> mBuckets;
94
95        int mSize;
96};
97
98
99}
100
101#endif
Note: See TracBrowser for help on using the repository browser.