]> git.localhorst.tv Git - blank.git/blobdiff - src/model.hpp
optimize chunk intersection tests a little
[blank.git] / src / model.hpp
index b2a6e21a64a424fbd02639ef78004ddd369b9f3b..d5c77d174929756f2ace1445e887946b017dfe20 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef BLANK_MODEL_HPP_
 #define BLANK_MODEL_HPP_
 
+#include <vector>
+#include <GL/glew.h>
 #include <glm/glm.hpp>
 
 
@@ -8,31 +10,115 @@ namespace blank {
 
 class Model {
 
+public:
+       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();
        ~Model();
 
-       glm::mat4 Transform() const;
+       Model(const Model &) = delete;
+       Model &operator =(const Model &) = delete;
+
+       Model(Model &&);
+       Model &operator =(Model &&);
+
+       void Update(const Buffer &);
+
+       void Draw() const;
+
+private:
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_COLOR,
+               ATTRIB_NORMAL,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
+
+       GLuint va;
+       GLuint handle[ATTRIB_COUNT];
+       size_t count;
 
-       void Velocity(glm::vec3 vel) { velocity = vel; }
-       void Position(glm::vec3 pos) { position = pos; }
-       void Move(glm::vec3 delta) { position += delta; }
+};
+
+
+class OutlineModel {
+
+public:
+       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>;
 
-       // all angles in radians (full circle = 2π)
-       float Pitch() const { return pitch; }
-       void Pitch(float p) { pitch = p; }
-       void RotatePitch(float delta) { pitch += delta; }
-       float Yaw() const { return yaw; }
-       void Yaw(float y) { yaw = y; }
-       void RotateYaw(float delta) { yaw += delta; }
+public:
+       Positions vertices;
+       Colors colors;
+       Indices indices;
 
-       void Update(int dt);
+public:
+       OutlineModel();
+       ~OutlineModel();
+
+       OutlineModel(const OutlineModel &) = delete;
+       OutlineModel &operator =(const OutlineModel &) = delete;
+
+       void Invalidate() { dirty = true; }
+
+       void Clear();
+       void Reserve(int vtx_count, int idx_count);
+
+       void Draw();
 
 private:
-       glm::vec3 velocity;
-       glm::vec3 position;
-       float pitch;
-       float yaw;
+       void Update();
+
+private:
+       enum Attribute {
+               ATTRIB_VERTEX,
+               ATTRIB_COLOR,
+               ATTRIB_INDEX,
+               ATTRIB_COUNT,
+       };
+
+       GLuint va;
+       GLuint handle[ATTRIB_COUNT];
+       bool dirty;
 
 };