-
Notifications
You must be signed in to change notification settings - Fork 0
/
renderer.cpp
79 lines (64 loc) · 2.07 KB
/
renderer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "renderer.h"
#include <cassert>
TSQueue<RenderList*> gFreeRenderLists;
RenderList* AcquireRenderList()
{
RenderList* rl = gFreeRenderLists.pop();
if(!rl)
{
// all render lists are taken get new one
rl = new RenderList();
}
rl->Acquire();
return rl;
}
void ReleaseRenderList(RenderList* rl) {
assert(rl && rl->IsAcquired());
rl->Release();
rl->GetRenderPackets().resize(0);
rl->GetDebugPrimitives().resize(0);
gFreeRenderLists.push(rl);
}
void DeleteRenderLists() {
while(gFreeRenderLists.size()) {
RenderList* rl = gFreeRenderLists.pop();
delete rl;
}
}
void ScheduleRenderCommand(RenderFrameContext *rfc, std::function<void(void)>&& cmd)
{
assert(rfc);
rfc->commands_.push_back(cmd);
}
HGOSVERTEXDECLARATION get_svd_vdecl() {
static const gosVERTEX_FORMAT_RECORD simple_vdecl[] = {
{0, 3, false, sizeof(SVD), 0, gosVERTEX_ATTRIB_TYPE::kFLOAT, 0},
{1, 2, false, sizeof(SVD), offsetof(SVD, uv),
gosVERTEX_ATTRIB_TYPE::kFLOAT, 0},
{2, 3, false, sizeof(SVD), offsetof(SVD, normal),
gosVERTEX_ATTRIB_TYPE::kFLOAT, 0},
};
static auto vdecl = gos_CreateVertexDeclaration(
simple_vdecl, sizeof(simple_vdecl) / sizeof(gosVERTEX_FORMAT_RECORD));
return vdecl;
}
HGOSVERTEXDECLARATION get_pos_only_vdecl() {
static const gosVERTEX_FORMAT_RECORD pos_only_vdecl[] = {
{0, 3, false, sizeof(vec3), 0, gosVERTEX_ATTRIB_TYPE::kFLOAT, 0},
};
static auto vdecl = gos_CreateVertexDeclaration(
pos_only_vdecl,
sizeof(pos_only_vdecl) / sizeof(gosVERTEX_FORMAT_RECORD));
return vdecl;
};
HGOSVERTEXDECLARATION get_quad_vdecl() {
static const gosVERTEX_FORMAT_RECORD quad_vdecl[] = {
{0, 2, false, sizeof(QVD), 0, gosVERTEX_ATTRIB_TYPE::kFLOAT, 0},
//{1, 2, false, sizeof(QVD), offsetof(QVD, uv),
//gosVERTEX_ATTRIB_TYPE::FLOAT
//}
};
static auto vdecl = gos_CreateVertexDeclaration(
quad_vdecl, sizeof(quad_vdecl) / sizeof(gosVERTEX_FORMAT_RECORD));
return vdecl;
}