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