]> git.localhorst.tv Git - blank.git/blob - src/model/SpriteModel.hpp
implemented font redering
[blank.git] / src / model / SpriteModel.hpp
1 #ifndef BLANK_MODEL_SPRITEMODEL_HPP_
2 #define BLANK_MODEL_SPRITEMODEL_HPP_
3
4 #include <vector>
5 #include <GL/glew.h>
6 #include <glm/glm.hpp>
7
8
9 namespace blank {
10
11 class SpriteModel {
12
13 public:
14         using Position = glm::vec3;
15         using TexCoord = glm::vec2;
16         using Index = unsigned short;
17
18         using Positions = std::vector<Position>;
19         using TexCoords = std::vector<TexCoord>;
20         using Indices = std::vector<Index>;
21
22 public:
23         Positions vertices;
24         TexCoords coords;
25         Indices indices;
26
27 public:
28         SpriteModel() noexcept;
29         ~SpriteModel() noexcept;
30
31         SpriteModel(const SpriteModel &) = delete;
32         SpriteModel &operator =(const SpriteModel &) = delete;
33
34         void Invalidate() noexcept { dirty = true; }
35
36         void Clear() noexcept;
37         void Reserve(int vtx_count, int idx_count);
38
39         void LoadRect(
40                 float w, float h,
41                 const glm::vec2 &pivot = glm::vec2(0.0f),
42                 const glm::vec2 &tex_begin = glm::vec2(0.0f),
43                 const glm::vec2 &tex_end = glm::vec2(1.0f, 1.0f)
44         );
45
46         void Draw() noexcept;
47
48 private:
49         void Update() noexcept;
50
51 private:
52         enum Attribute {
53                 ATTRIB_VERTEX,
54                 ATTRIB_TEXCOORD,
55                 ATTRIB_INDEX,
56                 ATTRIB_COUNT,
57         };
58
59         GLuint va;
60         GLuint handle[ATTRIB_COUNT];
61         bool dirty;
62
63 };
64
65 }
66
67 #endif