]> git.localhorst.tv Git - blank.git/blob - src/model.hpp
62f467c4f787a6de9547f450af12197dd3e955f6
[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         Positions vertices;
26         Colors colors;
27         Normals normals;
28         Indices indices;
29
30 public:
31         Model();
32         ~Model();
33
34         Model(const Model &) = delete;
35         Model &operator =(const Model &) = delete;
36
37         Model(Model &&);
38         Model &operator =(Model &&);
39
40         void Invalidate() { dirty = true; }
41
42         void Clear();
43         void Reserve(int vtx_count, int idx_count);
44
45         void CheckUpdate();
46         void Draw();
47
48 private:
49         void Update();
50
51 private:
52         enum Attribute {
53                 ATTRIB_VERTEX,
54                 ATTRIB_COLOR,
55                 ATTRIB_NORMAL,
56                 ATTRIB_INDEX,
57                 ATTRIB_COUNT,
58         };
59
60         GLuint va;
61         GLuint handle[ATTRIB_COUNT];
62         bool dirty;
63
64 };
65
66
67 class OutlineModel {
68
69 public:
70         using Position = glm::vec3;
71         using Color = glm::vec3;
72         using Index = unsigned short;
73
74         using Positions = std::vector<Position>;
75         using Colors = std::vector<Color>;
76         using Indices = std::vector<Index>;
77
78 public:
79         Positions vertices;
80         Colors colors;
81         Indices indices;
82
83 public:
84         OutlineModel();
85         ~OutlineModel();
86
87         OutlineModel(const OutlineModel &) = delete;
88         OutlineModel &operator =(const OutlineModel &) = delete;
89
90         void Invalidate() { dirty = true; }
91
92         void Clear();
93         void Reserve(int vtx_count, int idx_count);
94
95         void Draw();
96
97 private:
98         void Update();
99
100 private:
101         enum Attribute {
102                 ATTRIB_VERTEX,
103                 ATTRIB_COLOR,
104                 ATTRIB_INDEX,
105                 ATTRIB_COUNT,
106         };
107
108         GLuint va;
109         GLuint handle[ATTRIB_COUNT];
110         bool dirty;
111
112 };
113
114 }
115
116 #endif