]> git.localhorst.tv Git - blank.git/blobdiff - src/model.hpp
use light levels for shading of blocks
[blank.git] / src / model.hpp
index 4423cd7115338f671847d2461def60ffd11454cd..7b9fc3d1b09cf702109111ae51568e694f45736a 100644 (file)
@@ -11,9 +11,39 @@ namespace blank {
 class Model {
 
 public:
-       std::vector<glm::vec3> vertices;
-       std::vector<glm::vec3> colors;
-       std::vector<glm::vec3> normals;
+       using Position = glm::vec3;
+       using Color = glm::vec3;
+       using Normal = glm::vec3;
+       using Index = unsigned int;
+
+       using Positions = std::vector<Position>;
+       using Colors = std::vector<Color>;
+       using Normals = std::vector<Normal>;
+       using Indices = std::vector<Index>;
+
+public:
+       struct Buffer {
+
+               Positions vertices;
+               Colors colors;
+               Normals normals;
+               Indices indices;
+
+               void Clear() {
+                       vertices.clear();
+                       colors.clear();
+                       normals.clear();
+                       indices.clear();
+               }
+
+               void Reserve(size_t p, size_t i) {
+                       vertices.reserve(p);
+                       colors.reserve(p);
+                       normals.reserve(p);
+                       indices.reserve(i);
+               }
+
+       };
 
 public:
        Model();
@@ -25,26 +55,95 @@ public:
        Model(Model &&);
        Model &operator =(Model &&);
 
-       void Invalidate() { dirty = true; }
+       void Update(const Buffer &);
 
-       void Clear();
-       void Reserve(int);
-
-       void Draw();
+       void Draw() const;
 
 private:
-       void Update();
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_COLOR,
+               ATTRIB_NORMAL,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
+
+       GLuint va;
+       GLuint handle[ATTRIB_COUNT];
+       size_t count;
+
+};
+
+
+class BlockModel {
+
+public:
+       using Position = glm::vec3;
+       using Color = glm::vec3;
+       using Normal = glm::vec3;
+       using Light = float;
+       using Index = unsigned int;
+
+       using Positions = std::vector<Position>;
+       using Colors = std::vector<Color>;
+       using Normals = std::vector<Normal>;
+       using Lights = std::vector<Light>;
+       using Indices = std::vector<Index>;
+
+public:
+       struct Buffer {
+
+               Positions vertices;
+               Colors colors;
+               Normals normals;
+               Lights lights;
+               Indices indices;
+
+               void Clear() {
+                       vertices.clear();
+                       colors.clear();
+                       normals.clear();
+                       lights.clear();
+                       indices.clear();
+               }
+
+               void Reserve(size_t p, size_t i) {
+                       vertices.reserve(p);
+                       colors.reserve(p);
+                       normals.reserve(p);
+                       lights.reserve(p);
+                       indices.reserve(i);
+               }
+
+       };
+
+public:
+       BlockModel();
+       ~BlockModel();
+
+       BlockModel(const BlockModel &) = delete;
+       BlockModel &operator =(const Model &) = delete;
+
+       BlockModel(BlockModel &&);
+       BlockModel &operator =(BlockModel &&);
+
+       void Update(const Buffer &);
+
+       void Draw() const;
 
 private:
        enum Attribute {
                ATTRIB_VERTEX,
                ATTRIB_COLOR,
                ATTRIB_NORMAL,
+               ATTRIB_LIGHT,
+               ATTRIB_INDEX,
                ATTRIB_COUNT,
        };
 
+       GLuint va;
        GLuint handle[ATTRIB_COUNT];
-       bool dirty;
+       size_t count;
 
 };
 
@@ -52,8 +151,18 @@ private:
 class OutlineModel {
 
 public:
-       std::vector<glm::vec3> vertices;
-       std::vector<glm::vec3> colors;
+       using Position = glm::vec3;
+       using Color = glm::vec3;
+       using Index = unsigned short;
+
+       using Positions = std::vector<Position>;
+       using Colors = std::vector<Color>;
+       using Indices = std::vector<Index>;
+
+public:
+       Positions vertices;
+       Colors colors;
+       Indices indices;
 
 public:
        OutlineModel();
@@ -65,7 +174,7 @@ public:
        void Invalidate() { dirty = true; }
 
        void Clear();
-       void Reserve(int);
+       void Reserve(int vtx_count, int idx_count);
 
        void Draw();
 
@@ -76,9 +185,11 @@ private:
        enum Attribute {
                ATTRIB_VERTEX,
                ATTRIB_COLOR,
+               ATTRIB_INDEX,
                ATTRIB_COUNT,
        };
 
+       GLuint va;
        GLuint handle[ATTRIB_COUNT];
        bool dirty;