]> git.localhorst.tv Git - blank.git/blob - src/graphics/PrimitiveMesh.hpp
1aa3cce58acf417e6605fe82f99c2d473845ed1c
[blank.git] / src / graphics / PrimitiveMesh.hpp
1 #ifndef BLANK_GRAPHICS_PRIMITIVEMESH_HPP_
2 #define BLANK_GRAPHICS_PRIMITIVEMESH_HPP_
3
4 #include "VertexArray.hpp"
5
6 #include <vector>
7 #include <GL/glew.h>
8 #include <glm/glm.hpp>
9
10
11 namespace blank {
12
13 class PrimitiveMesh {
14
15 public:
16         using Position = glm::vec3;
17         using Color = glm::vec4;
18         using Index = unsigned short;
19
20         using Positions = std::vector<Position>;
21         using Colors = std::vector<Color>;
22         using Indices = std::vector<Index>;
23
24         enum Attribute {
25                 ATTRIB_VERTEX,
26                 ATTRIB_COLOR,
27                 ATTRIB_INDEX,
28                 ATTRIB_COUNT,
29         };
30
31         struct Buffer {
32
33                 Positions vertices;
34                 Colors colors;
35                 Indices indices;
36
37                 void Clear() noexcept {
38                         vertices.clear();
39                         colors.clear();
40                         indices.clear();
41                 }
42
43                 void Reserve(size_t p, size_t i) {
44                         vertices.reserve(p);
45                         colors.reserve(p);
46                         indices.reserve(i);
47                 }
48
49                 void FillRect(
50                         float w, float h,
51                         const glm::vec4 &color = glm::vec4(0.0f),
52                         const glm::vec2 &pivot = glm::vec2(0.0f)
53                 );
54
55         };
56
57         using VAO = VertexArray<ATTRIB_COUNT>;
58
59 public:
60         void Update(const Buffer &) noexcept;
61
62         void DrawLines() noexcept;
63         void DrawTriangles() noexcept;
64
65 private:
66         VAO vao;
67
68 };
69
70 }
71
72 #endif