aboutsummaryrefslogtreecommitdiffstats
path: root/yage/base/vertex.h
blob: 586e819099d505b61a65e43a71c102901672aaa6 (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
/* ----------------------------------------------------------------------------
 * vertex.h
 *
 * Copyright (c) 2017 Yann Herklotz Grave <ymherklotz@gmail.com> -- MIT License
 * See file LICENSE 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 Color {
    GLubyte r;
    GLubyte g;
    GLubyte b;
    GLubyte a;

    Color() = default;

    Color(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;
    Color color;
    UV uv;

    Vertex() = default;

    Vertex(const Position &position_, const Color &color_, const UV &uv_)
        : position(position_), color(color_), uv(uv_)
    {
    }

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

    void setColor(GLubyte r, GLubyte g, GLubyte b, GLubyte a)
    {
        color.r = r;
        color.g = g;
        color.b = b;
        color.a = a;
    }

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

} // namespace yage

#endif