]> git.localhorst.tv Git - blank.git/blob - src/model.hpp
remove move branching from interface
[blank.git] / src / model.hpp
1 #ifndef BLANK_MODEL_HPP_
2 #define BLANK_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() {
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();
50         ~Model();
51
52         Model(const Model &) = delete;
53         Model &operator =(const Model &) = delete;
54
55         Model(Model &&);
56         Model &operator =(Model &&);
57
58         void Update(const Buffer &);
59
60         void Draw() const;
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 class BlockModel {
79
80 public:
81         using Position = glm::vec3;
82         using Color = glm::vec3;
83         using Normal = glm::vec3;
84         using Light = float;
85         using Index = unsigned int;
86
87         using Positions = std::vector<Position>;
88         using Colors = std::vector<Color>;
89         using Normals = std::vector<Normal>;
90         using Lights = std::vector<Light>;
91         using Indices = std::vector<Index>;
92
93 public:
94         struct Buffer {
95
96                 Positions vertices;
97                 Colors colors;
98                 Normals normals;
99                 Lights lights;
100                 Indices indices;
101
102                 void Clear() {
103                         vertices.clear();
104                         colors.clear();
105                         normals.clear();
106                         lights.clear();
107                         indices.clear();
108                 }
109
110                 void Reserve(size_t p, size_t i) {
111                         vertices.reserve(p);
112                         colors.reserve(p);
113                         normals.reserve(p);
114                         lights.reserve(p);
115                         indices.reserve(i);
116                 }
117
118         };
119
120 public:
121         BlockModel();
122         ~BlockModel();
123
124         BlockModel(const BlockModel &) = delete;
125         BlockModel &operator =(const Model &) = delete;
126
127         BlockModel(BlockModel &&);
128         BlockModel &operator =(BlockModel &&);
129
130         void Update(const Buffer &);
131
132         void Draw() const;
133
134 private:
135         enum Attribute {
136                 ATTRIB_VERTEX,
137                 ATTRIB_COLOR,
138                 ATTRIB_NORMAL,
139                 ATTRIB_LIGHT,
140                 ATTRIB_INDEX,
141                 ATTRIB_COUNT,
142         };
143
144         GLuint va;
145         GLuint handle[ATTRIB_COUNT];
146         size_t count;
147
148 };
149
150
151 class OutlineModel {
152
153 public:
154         using Position = glm::vec3;
155         using Color = glm::vec3;
156         using Index = unsigned short;
157
158         using Positions = std::vector<Position>;
159         using Colors = std::vector<Color>;
160         using Indices = std::vector<Index>;
161
162 public:
163         Positions vertices;
164         Colors colors;
165         Indices indices;
166
167 public:
168         OutlineModel();
169         ~OutlineModel();
170
171         OutlineModel(const OutlineModel &) = delete;
172         OutlineModel &operator =(const OutlineModel &) = delete;
173
174         void Invalidate() { dirty = true; }
175
176         void Clear();
177         void Reserve(int vtx_count, int idx_count);
178
179         void Draw();
180
181 private:
182         void Update();
183
184 private:
185         enum Attribute {
186                 ATTRIB_VERTEX,
187                 ATTRIB_COLOR,
188                 ATTRIB_INDEX,
189                 ATTRIB_COUNT,
190         };
191
192         GLuint va;
193         GLuint handle[ATTRIB_COUNT];
194         bool dirty;
195
196 };
197
198 }
199
200 #endif