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

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