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