]> git.localhorst.tv Git - blank.git/blobdiff - src/model/SpriteModel.hpp
"streamlined" model/VAO handling
[blank.git] / src / model / SpriteModel.hpp
index d661501fb51e7e954570514f978b69783e4baa1a..c5670fcb3bf5161f15d9dfaab13e8c0a68d70808 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef BLANK_MODEL_SPRITEMODEL_HPP_
 #define BLANK_MODEL_SPRITEMODEL_HPP_
 
+#include "../graphics/VertexArray.hpp"
+
 #include <vector>
 #include <GL/glew.h>
 #include <glm/glm.hpp>
@@ -19,46 +21,49 @@ public:
        using TexCoords = std::vector<TexCoord>;
        using Indices = std::vector<Index>;
 
-public:
-       Positions vertices;
-       TexCoords coords;
-       Indices indices;
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_TEXCOORD,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
 
-public:
-       SpriteModel() noexcept;
-       ~SpriteModel() noexcept;
+       struct Buffer {
 
-       SpriteModel(const SpriteModel &) = delete;
-       SpriteModel &operator =(const SpriteModel &) = delete;
+               Positions vertices;
+               TexCoords coords;
+               Indices indices;
 
-       void Invalidate() noexcept { dirty = true; }
+               void Clear() noexcept {
+                       vertices.clear();
+                       coords.clear();
+                       indices.clear();
+               }
 
-       void Clear() noexcept;
-       void Reserve(int vtx_count, int idx_count);
+               void Reserve(size_t p, size_t i) {
+                       vertices.reserve(p);
+                       coords.reserve(p);
+                       indices.reserve(i);
+               }
 
-       void LoadRect(
-               float w, float h,
-               const glm::vec2 &pivot = glm::vec2(0.0f),
-               const glm::vec2 &tex_begin = glm::vec2(0.0f),
-               const glm::vec2 &tex_end = glm::vec2(1.0f, 1.0f)
-       );
+               void LoadRect(
+                       float w, float h,
+                       const glm::vec2 &pivot = glm::vec2(0.0f),
+                       const glm::vec2 &tex_begin = glm::vec2(0.0f),
+                       const glm::vec2 &tex_end = glm::vec2(1.0f, 1.0f)
+               );
 
-       void Draw() noexcept;
+       };
 
-private:
-       void Update() noexcept;
+       using VAO = VertexArray<ATTRIB_COUNT>;
 
-private:
-       enum Attribute {
-               ATTRIB_VERTEX,
-               ATTRIB_TEXCOORD,
-               ATTRIB_INDEX,
-               ATTRIB_COUNT,
-       };
+public:
+       void Update(const Buffer &) noexcept;
 
-       GLuint va;
-       GLuint handle[ATTRIB_COUNT];
-       bool dirty;
+       void Draw() noexcept;
+
+private:
+       VAO vao;
 
 };