[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 | {
|
---|
[3051] | 19 | ////////
|
---|
| 20 | //-- the attributes used to sort the materials
|
---|
| 21 | /// texture parameters
|
---|
[2805] | 22 | int mTexHeight;
|
---|
| 23 | int mTexWidth;
|
---|
[3051] | 24 | int mTexFormat;
|
---|
[2805] | 25 |
|
---|
| 26 | bool mHasTexture;
|
---|
[3051] | 27 |
|
---|
| 28 | bool mColorWriteEnabled;
|
---|
| 29 | bool mDepthWriteEnabled;
|
---|
| 30 | bool mLightingEnabled;
|
---|
| 31 |
|
---|
[2802] | 32 | bool mAlphaTestEnabled;
|
---|
[2844] | 33 | bool mCullFaceEnabled;
|
---|
[2802] | 34 |
|
---|
[3054] | 35 | //bool mHasVertexProgram;
|
---|
| 36 | //bool mHasFragmentProgram;
|
---|
| 37 | ShaderProgram *mVertexProgram;
|
---|
| 38 | ShaderProgram *mFragmentProgram;
|
---|
[3051] | 39 |
|
---|
[2802] | 40 | /// minimal distance to the camera
|
---|
| 41 | float mMinDistance;
|
---|
| 42 |
|
---|
[3051] | 43 | /// the shapes that belong to a bucket
|
---|
[2839] | 44 | ShapeContainer mShapes;
|
---|
[2802] | 45 | };
|
---|
| 46 |
|
---|
| 47 |
|
---|
| 48 | /** This class implements a render queue that sorts renderable geometry in order
|
---|
| 49 | to minimize state changes while approximately keeping front-to-back order
|
---|
[3051] | 50 | The implementation roughly follows the suggested implementation in
|
---|
| 51 | Tom Forsyth's article on render state changes. It requires sorting only on
|
---|
| 52 | bucket level and therefore has very low overhead.
|
---|
[2802] | 53 | */
|
---|
[2767] | 54 | class RenderQueue
|
---|
| 55 | {
|
---|
| 56 | public:
|
---|
| 57 |
|
---|
| 58 | /** Default constructor
|
---|
| 59 | */
|
---|
| 60 | RenderQueue();
|
---|
| 61 | /** Constructor taking a render queue
|
---|
| 62 | */
|
---|
[2802] | 63 | RenderQueue(RenderState *state, Camera *cam);
|
---|
| 64 |
|
---|
| 65 | ~RenderQueue();
|
---|
| 66 | /** Enqueues an entity.
|
---|
[2767] | 67 | */
|
---|
[2773] | 68 | void Enqueue(SceneEntity *entity);
|
---|
[3054] | 69 | /** Enqueues a single shape.
|
---|
| 70 | */
|
---|
| 71 | void Enqueue(Shape *shape);
|
---|
[2767] | 72 | /** Sets the current render state
|
---|
| 73 | */
|
---|
| 74 | void SetRenderState(RenderState *state);
|
---|
[2802] | 75 | /** Sets the current render state
|
---|
[2767] | 76 | */
|
---|
[2802] | 77 | void SetCamera(Camera *cam);
|
---|
[2844] | 78 | /** Returns the number of entries currently in the queue.
|
---|
[2793] | 79 | */
|
---|
[2844] | 80 | inline int GetSize() const { return (int)mNumEntries; }
|
---|
[2795] | 81 | /** Renders and clears the queue.
|
---|
| 82 | */
|
---|
| 83 | void Apply();
|
---|
[3054] | 84 | /** Clears the render queue
|
---|
| 85 | */
|
---|
| 86 | void Clear();
|
---|
[2767] | 87 |
|
---|
| 88 | protected:
|
---|
| 89 |
|
---|
[2842] | 90 | void Sort();
|
---|
| 91 |
|
---|
[2839] | 92 | inline bool FitsInBucket(Shape *shape, size_t idx) const;
|
---|
[2802] | 93 | /** Renders the contents of the render queue.
|
---|
| 94 | */
|
---|
| 95 | void Render();
|
---|
| 96 | /** Prints the current state of the render queue.
|
---|
| 97 | */
|
---|
| 98 | void Print();
|
---|
[2767] | 99 |
|
---|
[2848] | 100 |
|
---|
[2767] | 101 | ///////////
|
---|
| 102 |
|
---|
| 103 | RenderState *mState;
|
---|
[2848] | 104 |
|
---|
[2802] | 105 | Camera *mCamera;
|
---|
| 106 | //SceneEntityContainer mEntities;
|
---|
[2771] | 107 | int mMinSizeForSorting;
|
---|
[2802] | 108 | /// each bucket contains objects with similar materials that don't cause a hard state change
|
---|
| 109 | std::vector<RenderQueueBucket *> mBuckets;
|
---|
| 110 |
|
---|
[2844] | 111 | int mNumEntries;
|
---|
[2767] | 112 | };
|
---|
| 113 |
|
---|
[2801] | 114 |
|
---|
[2767] | 115 | }
|
---|
| 116 |
|
---|
| 117 | #endif
|
---|