aboutsummaryrefslogtreecommitdiffstats
path: root/yage/data/vertex.h
blob: 4cd095a924ca041d9acee613bcc46706c0eb002e (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
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
80
81
82
83
84
/** ---------------------------------------------------------------------------
 * @file: vertex.h
 *
 * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com>
 * MIT License, see LICENSE file for more details.
 * ----------------------------------------------------------------------------
 */

#ifndef VERTEX_H
#define VERTEX_H

#include <glad/glad.h>

namespace yage
{

struct Position {
    float x;
    float y;

    Position() = default;

    Position(float x_, float y_) : x(x_), y(y_) {}
};

struct Colour {
    GLubyte r;
    GLubyte g;
    GLubyte b;
    GLubyte a;

    Colour() : r(0), g(0), b(0), a(0) {}

    Colour(GLubyte r_, GLubyte g_, GLubyte b_, GLubyte a_)
        : r(r_), g(g_), b(b_), a(a_)
    {
    }
};

struct UV {
    float u;
    float v;

    UV() = default;

    UV(float u_, float v_) : u(u_), v(v_) {}
};

struct Vertex {
    Position position;
    Colour colour;
    UV uv;

    Vertex() = default;

    Vertex(const Position &position_, const Colour &colour_, const UV &uv_)
        : position(position_), colour(colour_), uv(uv_)
    {
    }

    void setPosition(float x, float y)
    {
        position.x = x;
        position.y = y;
    }

    void setColour(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
    {
        colour.r = r;
        colour.g = g;
        colour.b = b;
        colour.a = a;
    }

    void setUv(float u, float v)
    {
        uv.u = u;
        uv.v = v;
    }
};

} // namespace yage

#endif