]> git.localhorst.tv Git - blank.git/blob - src/model/SpriteModel.hpp
allow hsl color shifts for blocks and entities
[blank.git] / src / model / SpriteModel.hpp
1 #ifndef BLANK_MODEL_SPRITEMODEL_HPP_
2 #define BLANK_MODEL_SPRITEMODEL_HPP_
3
4 #include "../graphics/VertexArray.hpp"
5
6 #include <vector>
7 #include <GL/glew.h>
8 #include <glm/glm.hpp>
9
10
11 namespace blank {
12
13 class SpriteModel {
14
15 public:
16         using Position = glm::vec3;
17         using TexCoord = glm::vec2;
18         using Index = unsigned short;
19
20         using Positions = std::vector<Position>;
21         using TexCoords = std::vector<TexCoord>;
22         using Indices = std::vector<Index>;
23
24         enum Attribute {
25                 ATTRIB_VERTEX,
26                 ATTRIB_TEXCOORD,
27                 ATTRIB_INDEX,
28                 ATTRIB_COUNT,
29         };
30
31         struct Buffer {
32
33                 Positions vertices;
34                 TexCoords coords;
35                 Indices indices;
36
37                 void Clear() noexcept {
38                         vertices.clear();
39                         coords.clear();
40                         indices.clear();
41                 }
42
43                 void Reserve(size_t p, size_t i) {
44                         vertices.reserve(p);
45                         coords.reserve(p);
46                         indices.reserve(i);
47                 }
48
49                 void LoadRect(
50                         float w, float h,
51                         const glm::vec2 &pivot = glm::vec2(0.0f),
52                         const glm::vec2 &tex_begin = glm::vec2(0.0f),
53                         const glm::vec2 &tex_end = glm::vec2(1.0f, 1.0f)
54                 );
55
56         };
57
58         using VAO = VertexArray<ATTRIB_COUNT>;
59
60 public:
61         void Update(const Buffer &) noexcept;
62
63         void Draw() noexcept;
64
65 private:
66         VAO vao;
67
68 };
69
70 }
71
72 #endif