[2767] | 1 | #ifndef __RENDERQUEUE_H
|
---|
| 2 | #define __RENDERQUEUE_H
|
---|
| 3 |
|
---|
| 4 | #include "common.h"
|
---|
| 5 |
|
---|
[2795] | 6 |
|
---|
[2776] | 7 | namespace CHCDemoEngine
|
---|
[2767] | 8 | {
|
---|
| 9 |
|
---|
| 10 | class RenderState;
|
---|
[2802] | 11 | class Camera;
|
---|
[2767] | 12 |
|
---|
[3071] | 13 | typedef std::pair<Shape *, Transform3 *> ShapePair;
|
---|
| 14 | typedef std::vector<ShapePair> ShapePairArray;
|
---|
[2767] | 15 |
|
---|
[2802] | 16 | /** Defines a bucket for scene entities that have the same properties.
|
---|
[2767] | 17 | */
|
---|
[2802] | 18 | struct RenderQueueBucket
|
---|
| 19 | {
|
---|
[3060] | 20 | inline bool IsEmpty() const { return mShapes.empty();}
|
---|
| 21 |
|
---|
[3051] | 22 | ////////
|
---|
| 23 | //-- the attributes used to sort the materials
|
---|
[3060] | 24 |
|
---|
| 25 | // texture related parameters
|
---|
[2805] | 26 | int mTexHeight;
|
---|
| 27 | int mTexWidth;
|
---|
[3051] | 28 | int mTexFormat;
|
---|
[2805] | 29 |
|
---|
| 30 | bool mHasTexture;
|
---|
[3051] | 31 |
|
---|
| 32 | bool mColorWriteEnabled;
|
---|
| 33 | bool mDepthWriteEnabled;
|
---|
| 34 | bool mLightingEnabled;
|
---|
| 35 |
|
---|
[2802] | 36 | bool mAlphaTestEnabled;
|
---|
[2844] | 37 | bool mCullFaceEnabled;
|
---|
[2802] | 38 |
|
---|
[3054] | 39 | //bool mHasVertexProgram;
|
---|
| 40 | //bool mHasFragmentProgram;
|
---|
| 41 | ShaderProgram *mVertexProgram;
|
---|
| 42 | ShaderProgram *mFragmentProgram;
|
---|
[3051] | 43 |
|
---|
[2802] | 44 | /// minimal distance to the camera
|
---|
[3060] | 45 | //float mMinDistance;
|
---|
[2802] | 46 |
|
---|
[3051] | 47 | /// the shapes that belong to a bucket
|
---|
[3071] | 48 | ShapePairArray mShapes;
|
---|
[2802] | 49 | };
|
---|
| 50 |
|
---|
| 51 |
|
---|
| 52 | /** This class implements a render queue that sorts renderable geometry in order
|
---|
| 53 | to minimize state changes while approximately keeping front-to-back order
|
---|
[3051] | 54 | The implementation roughly follows the suggested implementation in
|
---|
[3060] | 55 | Tom Forsyth's article on render state changes. It assumes that the incoming
|
---|
| 56 | objecs are roughly front to back level and therefore does not require any sorting
|
---|
| 57 | and therefore has very low overhead.
|
---|
[2802] | 58 | */
|
---|
[2767] | 59 | class RenderQueue
|
---|
| 60 | {
|
---|
| 61 | public:
|
---|
| 62 |
|
---|
| 63 | /** Default constructor
|
---|
| 64 | */
|
---|
| 65 | RenderQueue();
|
---|
[3061] | 66 | /** Constructor passing the current render state
|
---|
[2767] | 67 | */
|
---|
[3061] | 68 | RenderQueue(RenderState *state);
|
---|
[2802] | 69 |
|
---|
| 70 | ~RenderQueue();
|
---|
| 71 | /** Enqueues an entity.
|
---|
[2767] | 72 | */
|
---|
[2773] | 73 | void Enqueue(SceneEntity *entity);
|
---|
[3054] | 74 | /** Enqueues a single shape.
|
---|
| 75 | */
|
---|
[3071] | 76 | void Enqueue(Shape *shape, Transform3 *trafo);
|
---|
[2767] | 77 | /** Sets the current render state
|
---|
| 78 | */
|
---|
| 79 | void SetRenderState(RenderState *state);
|
---|
[2844] | 80 | /** Returns the number of entries currently in the queue.
|
---|
[2793] | 81 | */
|
---|
[2844] | 82 | inline int GetSize() const { return (int)mNumEntries; }
|
---|
[2795] | 83 | /** Renders and clears the queue.
|
---|
| 84 | */
|
---|
| 85 | void Apply();
|
---|
[3054] | 86 | /** Clears the render queue
|
---|
| 87 | */
|
---|
| 88 | void Clear();
|
---|
[2767] | 89 |
|
---|
[3071] | 90 |
|
---|
[2767] | 91 | protected:
|
---|
| 92 |
|
---|
[3060] | 93 | //void Sort();
|
---|
[2842] | 94 |
|
---|
[2839] | 95 | inline bool FitsInBucket(Shape *shape, size_t idx) const;
|
---|
[2802] | 96 | /** Renders the contents of the render queue.
|
---|
| 97 | */
|
---|
| 98 | void Render();
|
---|
[2767] | 99 |
|
---|
[2848] | 100 |
|
---|
[2767] | 101 | ///////////
|
---|
[3060] | 102 | //-- members
|
---|
[2767] | 103 |
|
---|
[3060] | 104 | // the current render state
|
---|
[2767] | 105 | RenderState *mState;
|
---|
[2802] | 106 | /// each bucket contains objects with similar materials that don't cause a hard state change
|
---|
| 107 | std::vector<RenderQueueBucket *> mBuckets;
|
---|
[3060] | 108 | /// this are the buckets that where touched until the last clear. They are sorted by distance
|
---|
| 109 | std::vector<RenderQueueBucket *> mActiveBuckets;
|
---|
[2802] | 110 |
|
---|
[2844] | 111 | int mNumEntries;
|
---|
[2767] | 112 | };
|
---|
| 113 |
|
---|
[2801] | 114 |
|
---|
[2767] | 115 | }
|
---|
| 116 |
|
---|
| 117 | #endif
|
---|