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

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

implemented multiqueries, but still buggy 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), mMinSizeForSorting(5)
31{
32}
33
34
35RenderQueue::RenderQueue(RenderState *state):
36mState(state)
37{
38}
39
40
41void RenderQueue::Enqueue(SceneEntity *entity)
42{
43        mEntities.push_back(entity);
44}
45       
46
47void RenderQueue::Clear()
48{
49        mEntities.clear();
50
51}
52
53
54void RenderQueue::SetRenderState(RenderState *state)
55{
56        mState = state;
57}
58
59
60void RenderQueue::Render()
61{
62        if (mEntities.size() >= mMinSizeForSorting)
63                Sort();
64       
65        //if (!mEntities.empty()) Debug << "rendering render queue" << endl;
66        SceneEntityContainer::const_iterator sit, sit_end = mEntities.end();
67
68        for (sit = mEntities.begin(); sit != sit_end; ++ sit)
69        {
70                SceneEntity *ent = *sit;
71                ent->Render(mState);
72
73                /*if (ent->GetMaterial()->GetTexture())
74                        Debug << " " << ent->GetMaterial()->GetTexture()->GetWidth();
75                else
76                        Debug << " 0";*/
77        }
78}
79       
80
81void RenderQueue::Sort()
82{
83        //InitTiming();
84        //long t1, t2;
85        //t1 = GetTime();
86
87        sort(mEntities.begin(), mEntities.end(), IsLower);
88
89        //t2 = GetTime();
90        //cout << "sort: " << TimeDiff(t1, t2) << endl;
91}
92
93
94}
Note: See TracBrowser for help on using the repository browser.