source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/RenderQueue.cpp @ 2782

Revision 2782, 1.4 KB checked in by mattausch, 17 years ago (diff)
Line 
1#include "RenderQueue.h"
2#include "SceneEntity.h"
3#include "Geometry.h"
4#include "Texture.h"
5#include "Material.h"
6
7
8using namespace std;
9
10
11namespace CHCDemoEngine
12{
13
14
15inline static bool IsLower(SceneEntity *ent1, SceneEntity *ent2)
16{
17        // group by texture size
18        Texture *t1 = ent1->GetMaterial()->GetTexture();
19        Texture *t2 = ent2->GetMaterial()->GetTexture();
20
21        int tsize1 = t1 ? t1->GetByteSize() : 0;
22        int tsize2 = t2 ? t2->GetByteSize() : 0;
23
24        // if texture size equal, group by material
25        if (tsize1 == tsize2)
26                return ent1->GetMaterial() < ent2->GetMaterial();
27
28        return tsize1 < tsize2;
29}
30
31
32RenderQueue::RenderQueue(): mState(NULL), mMinSizeForSorting(3)
33{
34}
35
36
37RenderQueue::RenderQueue(RenderState *state):
38mState(state)
39{
40}
41
42
43void RenderQueue::Enqueue(SceneEntity *entity)
44{
45        mEntities.push_back(entity);
46}
47       
48
49void RenderQueue::Clear()
50{
51        mEntities.clear();
52
53}
54
55
56void RenderQueue::SetRenderState(RenderState *state)
57{
58        mState = state;
59}
60
61
62void RenderQueue::Render()
63{
64        if (mEntities.size() >= mMinSizeForSorting)
65                Sort();
66       
67        SceneEntityContainer::const_iterator sit, sit_end = mEntities.end();
68
69        for (sit = mEntities.begin(); sit != sit_end; ++ sit)
70        {
71                SceneEntity *ent = *sit;
72                ent->Render(mState);
73        }
74}
75       
76
77void RenderQueue::Sort()
78{
79        sort(mEntities.begin(), mEntities.end(), IsLower);
80}
81
82
83}
Note: See TracBrowser for help on using the repository browser.