[2767] | 1 | #ifndef __RENDERQUEUE_H
|
---|
| 2 | #define __RENDERQUEUE_H
|
---|
| 3 |
|
---|
| 4 | #include "common.h"
|
---|
[2795] | 5 | #include "Timer/PerfTimer.h"
|
---|
[2767] | 6 |
|
---|
[2795] | 7 |
|
---|
[2776] | 8 | namespace CHCDemoEngine
|
---|
[2767] | 9 | {
|
---|
| 10 |
|
---|
| 11 | class RenderState;
|
---|
[2802] | 12 | class Camera;
|
---|
[2767] | 13 |
|
---|
| 14 |
|
---|
[2802] | 15 | /** Defines a bucket for scene entities that have the same properties.
|
---|
[2767] | 16 | */
|
---|
[2802] | 17 | struct RenderQueueBucket
|
---|
| 18 | {
|
---|
[2805] | 19 | /** should test for all texture format parameters,
|
---|
| 20 | but we as use the same format for all textures they differ only in size
|
---|
[2802] | 21 | */
|
---|
[2805] | 22 | int mTexHeight;
|
---|
| 23 | int mTexWidth;
|
---|
| 24 |
|
---|
| 25 | bool mHasTexture;
|
---|
[2802] | 26 | bool mAlphaTestEnabled;
|
---|
[2844] | 27 | bool mCullFaceEnabled;
|
---|
[2802] | 28 |
|
---|
| 29 | /// minimal distance to the camera
|
---|
| 30 | float mMinDistance;
|
---|
| 31 |
|
---|
[2839] | 32 | ShapeContainer mShapes;
|
---|
[2802] | 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 | */
|
---|
[2767] | 42 | class RenderQueue
|
---|
| 43 | {
|
---|
| 44 | public:
|
---|
| 45 |
|
---|
| 46 | /** Default constructor
|
---|
| 47 | */
|
---|
| 48 | RenderQueue();
|
---|
| 49 | /** Constructor taking a render queue
|
---|
| 50 | */
|
---|
[2802] | 51 | RenderQueue(RenderState *state, Camera *cam);
|
---|
| 52 |
|
---|
| 53 | ~RenderQueue();
|
---|
| 54 | /** Enqueues an entity.
|
---|
[2767] | 55 | */
|
---|
[2773] | 56 | void Enqueue(SceneEntity *entity);
|
---|
[2767] | 57 | /** Sets the current render state
|
---|
| 58 | */
|
---|
| 59 | void SetRenderState(RenderState *state);
|
---|
[2802] | 60 | /** Sets the current render state
|
---|
[2767] | 61 | */
|
---|
[2802] | 62 | void SetCamera(Camera *cam);
|
---|
[2844] | 63 | /** Returns the number of entries currently in the queue.
|
---|
[2793] | 64 | */
|
---|
[2844] | 65 | inline int GetSize() const { return (int)mNumEntries; }
|
---|
[2795] | 66 | /** Renders and clears the queue.
|
---|
| 67 | */
|
---|
| 68 | void Apply();
|
---|
[2767] | 69 |
|
---|
[2802] | 70 |
|
---|
[2767] | 71 | protected:
|
---|
| 72 |
|
---|
[2842] | 73 | void Sort();
|
---|
| 74 |
|
---|
[2841] | 75 | void Enqueue(Shape *shape);
|
---|
| 76 |
|
---|
[2839] | 77 | inline bool FitsInBucket(Shape *shape, size_t idx) const;
|
---|
[2802] | 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();
|
---|
[2767] | 87 |
|
---|
[2848] | 88 |
|
---|
[2767] | 89 | ///////////
|
---|
| 90 |
|
---|
| 91 | RenderState *mState;
|
---|
[2848] | 92 |
|
---|
[2802] | 93 | Camera *mCamera;
|
---|
| 94 | //SceneEntityContainer mEntities;
|
---|
[2771] | 95 | int mMinSizeForSorting;
|
---|
[2802] | 96 |
|
---|
| 97 | /// each bucket contains objects with similar materials that don't cause a hard state change
|
---|
| 98 | std::vector<RenderQueueBucket *> mBuckets;
|
---|
| 99 |
|
---|
[2844] | 100 | int mNumEntries;
|
---|
[2767] | 101 | };
|
---|
| 102 |
|
---|
[2801] | 103 |
|
---|
[2767] | 104 | }
|
---|
| 105 |
|
---|
| 106 | #endif
|
---|