Line | |
---|
1 | #include "RenderQueue.h"
|
---|
2 | #include "SceneEntity.h"
|
---|
3 | #include "Geometry.h"
|
---|
4 | #include "Texture.h"
|
---|
5 | #include "Material.h"
|
---|
6 |
|
---|
7 |
|
---|
8 | using namespace std;
|
---|
9 |
|
---|
10 |
|
---|
11 | namespace CHCDemoEngine
|
---|
12 | {
|
---|
13 |
|
---|
14 |
|
---|
15 | inline 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 |
|
---|
32 | RenderQueue::RenderQueue(): mState(NULL), mMinSizeForSorting(3)
|
---|
33 | {
|
---|
34 | }
|
---|
35 |
|
---|
36 |
|
---|
37 | RenderQueue::RenderQueue(RenderState *state):
|
---|
38 | mState(state)
|
---|
39 | {
|
---|
40 | }
|
---|
41 |
|
---|
42 |
|
---|
43 | void RenderQueue::Enqueue(SceneEntity *entity)
|
---|
44 | {
|
---|
45 | mEntities.push_back(entity);
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | void RenderQueue::Clear()
|
---|
50 | {
|
---|
51 | mEntities.clear();
|
---|
52 |
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | void RenderQueue::SetRenderState(RenderState *state)
|
---|
57 | {
|
---|
58 | mState = state;
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | void 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 |
|
---|
77 | void RenderQueue::Sort()
|
---|
78 | {
|
---|
79 | sort(mEntities.begin(), mEntities.end(), IsLower);
|
---|
80 | }
|
---|
81 |
|
---|
82 |
|
---|
83 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.