summaryrefslogtreecommitdiff
path: root/Client/Source/GUI/UISquare.cpp
blob: f5c370220a8e20acb0c2000131aadd9d9e2945ed (plain)
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
#include "../Math/Math.h"
#include "../Graphics/GfxDevice.h"

#include "UISquare.h"

struct UISquareLayout
{
    Vector2f position;
};

static CustomVertexLayout layout;

InitializeStaticVariables([]() {
    VertexAttributeDescriptor POSITION = VertexAttributeDescriptor(0, 2, VertexAttrFormat_Float, sizeof(UISquareLayout));

    layout.attributes.push_back(POSITION);
});

void UISquare::Draw()
{
    const int nVerts = 4;
    const int nIndices = 6;

    float pos[] = {
        m_Left,  m_Bottom, // left-bottom
        m_Right, m_Bottom, // right-bottom
        m_Right, m_Top,    // right-top
        m_Left,  m_Top,    // top-left
    };

    int indices[] = {
        0, 1, 3, // right-top  
        1, 2, 3, // left-bottom
    };

    uint8* vb;
    uint16* ib;

    g_SharedVBO.GetChunk(sizeof(UISquareLayout), sizeof(uint16), 4, 6, Primitive_Triangle, (void**)&vb, (void**)&ib);

    UISquareLayout* dst = (UISquareLayout*)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(4, 6);
    g_SharedVBO.DrawChunk(layout);
}