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

Revision 2848, 2.2 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef __RENDERQUEUE_H
2#define __RENDERQUEUE_H
3
4#include "common.h"
5#include "Timer/PerfTimer.h"
6
7
8namespace CHCDemoEngine
9{
10
11class RenderState;
12class Camera;
13
14
15/** Defines a bucket for scene entities that have the same properties.
16*/
17struct RenderQueueBucket
18{
19        /** should test for all texture format parameters,
20            but we as use the same format for all textures they differ only in size
21        */
22        int mTexHeight;
23        int mTexWidth;
24
25        bool mHasTexture;
26        bool mAlphaTestEnabled;
27        bool mCullFaceEnabled;
28
29        /// minimal distance to the camera
30        float mMinDistance;
31
32        ShapeContainer mShapes;
33};
34
35
36/** This class implements a render queue that sorts renderable geometry in order
37        to minimize state changes while approximately keeping front-to-back order
38        The implementation roughly follows the suggested implemenation on Tom Forsyth's article
39        on render state changes. It requires sorting only on bucket level and therefore has very
40        low overhead
41*/
42class RenderQueue
43{
44public:
45
46        /** Default constructor
47        */
48        RenderQueue();
49        /** Constructor taking a render queue
50        */
51        RenderQueue(RenderState *state, Camera *cam);
52
53        ~RenderQueue();
54        /** Enqueues an entity.
55        */
56        void Enqueue(SceneEntity *entity);
57        /** Sets the current render state
58        */
59        void SetRenderState(RenderState *state);
60        /** Sets the current render state
61        */
62        void SetCamera(Camera *cam);
63        /** Returns the number of entries currently in the queue.
64        */
65        inline int GetSize() const { return (int)mNumEntries; }
66        /** Renders and clears the queue.
67        */
68        void Apply();
69
70
71protected:
72
73        void Sort();
74
75        void Enqueue(Shape *shape);
76
77        inline bool FitsInBucket(Shape *shape, size_t idx) const;
78        /** Clears the render queue
79        */
80        void Clear();
81        /** Renders the contents of the render queue.
82        */
83        void Render();
84        /** Prints the current state of the render queue.
85        */
86        void Print();
87
88
89        ///////////
90
91        RenderState *mState;
92       
93        Camera *mCamera;
94        //SceneEntityContainer mEntities;
95        int mMinSizeForSorting;
96
97        /// each bucket contains objects with similar materials that don't cause a hard state change
98        std::vector<RenderQueueBucket *> mBuckets;
99
100        int mNumEntries;
101};
102
103
104}
105
106#endif
Note: See TracBrowser for help on using the repository browser.