source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.h @ 3071

Revision 3071, 2.6 KB checked in by mattausch, 16 years ago (diff)

worked on dynamic objects

Line 
1#ifndef __RENDERQUEUE_H
2#define __RENDERQUEUE_H
3
4#include "common.h"
5
6
7namespace CHCDemoEngine
8{
9
10class RenderState;
11class Camera;
12
13typedef std::pair<Shape *, Transform3 *> ShapePair;
14typedef std::vector<ShapePair> ShapePairArray;
15
16/** Defines a bucket for scene entities that have the same properties.
17*/
18struct RenderQueueBucket
19{
20        inline bool IsEmpty() const { return mShapes.empty();}
21
22        ////////
23        //-- the attributes used to sort the materials
24       
25        // texture related parameters
26        int mTexHeight;
27        int mTexWidth;
28        int mTexFormat;
29
30        bool mHasTexture;
31
32        bool mColorWriteEnabled;
33        bool mDepthWriteEnabled;
34        bool mLightingEnabled;
35
36        bool mAlphaTestEnabled;
37        bool mCullFaceEnabled;
38
39        //bool mHasVertexProgram;
40        //bool mHasFragmentProgram;
41        ShaderProgram *mVertexProgram;
42        ShaderProgram *mFragmentProgram;
43
44        /// minimal distance to the camera
45        //float mMinDistance;
46
47        /// the shapes that belong to a bucket
48        ShapePairArray mShapes;
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
54        The implementation roughly follows the suggested implementation in
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.
58*/
59class RenderQueue
60{
61public:
62
63        /** Default constructor
64        */
65        RenderQueue();
66        /** Constructor passing the current render state
67        */
68        RenderQueue(RenderState *state);
69
70        ~RenderQueue();
71        /** Enqueues an entity.
72        */
73        void Enqueue(SceneEntity *entity);
74        /** Enqueues a single shape.
75        */
76        void Enqueue(Shape *shape, Transform3 *trafo);
77        /** Sets the current render state
78        */
79        void SetRenderState(RenderState *state);
80        /** Returns the number of entries currently in the queue.
81        */
82        inline int GetSize() const { return (int)mNumEntries; }
83        /** Renders and clears the queue.
84        */
85        void Apply();
86        /** Clears the render queue
87        */
88        void Clear();
89
90
91protected:
92
93        //void Sort();
94
95        inline bool FitsInBucket(Shape *shape, size_t idx) const;
96        /** Renders the contents of the render queue.
97        */
98        void Render();
99
100
101        ///////////
102        //-- members
103
104        // the current render state
105        RenderState *mState;
106        /// each bucket contains objects with similar materials that don't cause a hard state change
107        std::vector<RenderQueueBucket *> mBuckets;
108        /// this are the buckets that where touched until the last clear. They are sorted by distance
109        std::vector<RenderQueueBucket *> mActiveBuckets;
110
111        int mNumEntries;
112};
113
114
115}
116
117#endif
Note: See TracBrowser for help on using the repository browser.