1 | #ifndef __RENDERQUEUE_H
|
---|
2 | #define __RENDERQUEUE_H
|
---|
3 |
|
---|
4 | #include "common.h"
|
---|
5 | #include "Timer/PerfTimer.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | namespace CHCDemoEngine
|
---|
9 | {
|
---|
10 |
|
---|
11 | class RenderState;
|
---|
12 | class Camera;
|
---|
13 |
|
---|
14 |
|
---|
15 | /** Defines a bucket for scene entities that have the same properties.
|
---|
16 | */
|
---|
17 | struct 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 | bool mCullFaceEnabled;
|
---|
28 |
|
---|
29 | /// minimal distance to the camera
|
---|
30 | float mMinDistance;
|
---|
31 |
|
---|
32 | ShapeContainer mShapes;
|
---|
33 | };
|
---|
34 |
|
---|
35 |
|
---|
36 | /** This class implements a render queue that sorts renderable geometry in order
|
---|
37 | to minimize state changes while approximately keeping front-to-back order
|
---|
38 | The implementation roughly follows the suggested implemenation on Tom Forsyth's article
|
---|
39 | on render state changes. It requires sorting only on bucket level and therefore has very
|
---|
40 | low overhead
|
---|
41 | */
|
---|
42 | class RenderQueue
|
---|
43 | {
|
---|
44 | public:
|
---|
45 |
|
---|
46 | /** Default constructor
|
---|
47 | */
|
---|
48 | RenderQueue();
|
---|
49 | /** Constructor taking a render queue
|
---|
50 | */
|
---|
51 | RenderQueue(RenderState *state, Camera *cam);
|
---|
52 |
|
---|
53 | ~RenderQueue();
|
---|
54 | /** Enqueues an entity.
|
---|
55 | */
|
---|
56 | void Enqueue(SceneEntity *entity);
|
---|
57 | /** Sets the current render state
|
---|
58 | */
|
---|
59 | void SetRenderState(RenderState *state);
|
---|
60 | /** Sets the current render state
|
---|
61 | */
|
---|
62 | void SetCamera(Camera *cam);
|
---|
63 | /** Returns the number of entries currently in the queue.
|
---|
64 | */
|
---|
65 | inline int GetSize() const { return (int)mNumEntries; }
|
---|
66 | /** Renders and clears the queue.
|
---|
67 | */
|
---|
68 | void Apply();
|
---|
69 |
|
---|
70 |
|
---|
71 | protected:
|
---|
72 |
|
---|
73 | void Sort();
|
---|
74 |
|
---|
75 | void Enqueue(Shape *shape);
|
---|
76 |
|
---|
77 | inline bool FitsInBucket(Shape *shape, size_t idx) const;
|
---|
78 | /** Clears the render queue
|
---|
79 | */
|
---|
80 | void Clear();
|
---|
81 | /** Renders the contents of the render queue.
|
---|
82 | */
|
---|
83 | void Render();
|
---|
84 | /** Prints the current state of the render queue.
|
---|
85 | */
|
---|
86 | void Print();
|
---|
87 |
|
---|
88 |
|
---|
89 | ///////////
|
---|
90 |
|
---|
91 | RenderState *mState;
|
---|
92 |
|
---|
93 | Camera *mCamera;
|
---|
94 | //SceneEntityContainer mEntities;
|
---|
95 | int mMinSizeForSorting;
|
---|
96 |
|
---|
97 | /// each bucket contains objects with similar materials that don't cause a hard state change
|
---|
98 | std::vector<RenderQueueBucket *> mBuckets;
|
---|
99 |
|
---|
100 | int mNumEntries;
|
---|
101 | };
|
---|
102 |
|
---|
103 |
|
---|
104 | }
|
---|
105 |
|
---|
106 | #endif
|
---|