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

Revision 3110, 2.7 KB checked in by mattausch, 16 years ago (diff)

worked on id for 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 *, SceneEntity *> 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        ////////
24        //-- the attributes used to sort the materials
25       
26        // texture related parameters
27        int mTexHeight;
28        int mTexWidth;
29        int mTexFormat;
30
31        bool mHasTexture;
32
33        bool mColorWriteEnabled;
34        bool mDepthWriteEnabled;
35        bool mLightingEnabled;
36
37        bool mAlphaTestEnabled;
38        bool mCullFaceEnabled;
39
40        //bool mHasVertexProgram;
41        //bool mHasFragmentProgram;
42        ShaderProgram *mVertexProgram;
43        ShaderProgram *mFragmentProgram;
44        /// the shapes that belong to a bucket
45        ShapePairArray mShapes;
46        /// minimal distance to the camera
47        //float mMinDistance;
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
53        The implementation roughly follows the suggested implementation in
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.
57*/
58class RenderQueue
59{
60public:
61
62        /** Default constructor
63        */
64        RenderQueue();
65        /** Constructor passing the current render state
66        */
67        RenderQueue(RenderState *state);
68
69        ~RenderQueue();
70        /** Enqueues all the shapes of an entity.
71        */
72        void Enqueue(SceneEntity *entity);
73        /** Enqueues a single shape. We also have to pass the entity which contains the shape.
74        */
75        void Enqueue(Shape *shape, SceneEntity *containingEnt);
76        /** Sets the current render state
77        */
78        void SetRenderState(RenderState *state);
79        /** Returns the number of entries currently in the queue.
80        */
81        inline int GetSize() const { return (int)mNumEntries; }
82        /** Renders and clears the queue.
83        */
84        void Apply();
85        /** Clears the render queue
86        */
87        void Clear();
88
89
90protected:
91
92        //void Sort();
93
94        inline bool FitsInBucket(Shape *shape, size_t idx) const;
95        /** Renders the contents of the render queue.
96        */
97        void Render();
98
99
100        ///////////
101        //-- members
102
103        // the current render state
104        RenderState *mState;
105        /// each bucket contains objects with similar materials that don't cause a hard state change
106        std::vector<RenderQueueBucket *> mBuckets;
107        /// this are the buckets that where touched until the last clear. They are sorted by distance
108        std::vector<RenderQueueBucket *> mActiveBuckets;
109
110        int mNumEntries;
111};
112
113
114}
115
116#endif
Note: See TracBrowser for help on using the repository browser.