]> git.localhorst.tv Git - blank.git/blob - src/model.hpp
modify stair model so cut is along x axis
[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 OutlineModel {
79
80 public:
81         using Position = glm::vec3;
82         using Color = glm::vec3;
83         using Index = unsigned short;
84
85         using Positions = std::vector<Position>;
86         using Colors = std::vector<Color>;
87         using Indices = std::vector<Index>;
88
89 public:
90         Positions vertices;
91         Colors colors;
92         Indices indices;
93
94 public:
95         OutlineModel();
96         ~OutlineModel();
97
98         OutlineModel(const OutlineModel &) = delete;
99         OutlineModel &operator =(const OutlineModel &) = delete;
100
101         void Invalidate() { dirty = true; }
102
103         void Clear();
104         void Reserve(int vtx_count, int idx_count);
105
106         void Draw();
107
108 private:
109         void Update();
110
111 private:
112         enum Attribute {
113                 ATTRIB_VERTEX,
114                 ATTRIB_COLOR,
115                 ATTRIB_INDEX,
116                 ATTRIB_COUNT,
117         };
118
119         GLuint va;
120         GLuint handle[ATTRIB_COUNT];
121         bool dirty;
122
123 };
124
125 }
126
127 #endif