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

Revision 2805, 2.2 KB checked in by mattausch, 17 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        SceneEntityContainer mEntities;
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        inline bool FitsInBucket(SceneEntity *ent, size_t idx) const;
73
74        /** Sorts the render queue by materials / textures.
75        */
76        void Sort();
77        /** Clears the render queue
78        */
79        void Clear();
80        /** Renders the contents of the render queue.
81        */
82        void Render();
83        /** Prints the current state of the render queue.
84        */
85        void Print();
86
87        ///////////
88
89        RenderState *mState;
90        Camera *mCamera;
91        //SceneEntityContainer mEntities;
92        int mMinSizeForSorting;
93
94        /// each bucket contains objects with similar materials that don't cause a hard state change
95        std::vector<RenderQueueBucket *> mBuckets;
96
97        int mSize;
98};
99
100
101}
102
103#endif
Note: See TracBrowser for help on using the repository browser.