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
|
#include "UILine.h"
struct UILineLayout
{
Vector2f position;
};
static CustomVertexLayout layout;
InitializeStaticVariables([]() {
VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UILineLayout));
layout.attributes.push_back(POSITION);
});
void UILine::Draw()
{
const int nVerts = 2;
const int nIndices = 2;
float pos[] = {
m_From.x, m_From.y,
m_To.x, m_To.y,
};
uint16 indices[] = {
0, 1
};
uint8* vb;
uint16* ib;
g_SharedVBO.GetChunk(sizeof(UILineLayout), sizeof(uint16), nVerts, nIndices, Primitive_Line, (void**)&vb, (void**)&ib);
UILineLayout* dst = (UILineLayout*)vb;
for (int i = 0; i < nVerts; ++i)
{
dst[i].position.Set(pos[2 * i], pos[2 * i + 1]);
}
for (int i = 0; i < nIndices; ++i)
ib[i] = indices[i];
g_SharedVBO.ReleaseChunk(nVerts, nIndices);
g_SharedVBO.DrawChunk(layout);
}
|