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