source: GTP/trunk/App/Demos/Vis/CHC_revisited/RenderQueue.cpp @ 2768

Revision 2768, 1.6 KB checked in by mattausch, 17 years ago (diff)

debug version

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 CHCDemo
12{
13
14
15inline static bool IsLower(SceneEntity *ent1, SceneEntity *ent2)
16{
17        Texture *t1 = ent1->GetMaterial()->GetTexture();
18        Texture *t2 = ent2->GetMaterial()->GetTexture();
19
20        int tsize1 = t1 ? t1->GetByteSize() : 0;
21        int tsize2 = t2 ? t2->GetByteSize() : 0;
22
23        if (tsize1 == tsize2)
24                return ent1->GetMaterial() < ent2->GetMaterial();
25
26        return tsize1 < tsize2;
27}
28
29
30RenderQueue::RenderQueue(): mState(NULL)
31{
32}
33
34
35RenderQueue::RenderQueue(RenderState *state):
36mState(state)
37{
38}
39
40
41void RenderQueue::Enqueue(SceneEntity **entities, int size)
42{
43        for (int i = 0; i < size; ++ i)
44                mEntities.push_back(entities[i]);
45
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        Sort();
65       
66        //if (!mEntities.empty()) Debug << "rendering render queue" << endl;
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                /*if (ent->GetMaterial()->GetTexture())
75                        Debug << " " << ent->GetMaterial()->GetTexture()->GetWidth();
76                else
77                        Debug << " 0";*/
78        }
79}
80       
81
82void RenderQueue::Sort()
83{
84        //InitTiming();
85        //long t1, t2;
86        //t1 = GetTime();
87
88        sort(mEntities.begin(), mEntities.end(), IsLower);
89
90        //t2 = GetTime();
91        //cout << "sort: " << TimeDiff(t1, t2) << endl;
92}
93
94
95}
Note: See TracBrowser for help on using the repository browser.