X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmodel.hpp;h=7b9fc3d1b09cf702109111ae51568e694f45736a;hb=4485397da18a25dfd1a51e864814887b66ba0f2e;hp=ea9bf119e80e6061084117edb0e1c11549a8b1a0;hpb=28fda9f7f55a9e806ade3f49f4e94f0242ec2c3c;p=blank.git diff --git a/src/model.hpp b/src/model.hpp index ea9bf11..7b9fc3d 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -11,13 +11,39 @@ 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; + using Colors = std::vector; + using Normals = std::vector; + using Indices = std::vector; + public: - std::vector vertices; - std::vector colors; - std::vector normals; - std::vector indices; + 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(); @@ -29,29 +55,95 @@ public: Model(Model &&); Model &operator =(Model &&); - void Invalidate() { dirty = true; } - - void Clear(); - void Reserve(int vtx_count, int idx_count); + void Update(const Buffer &); - void CheckUpdate(); - 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; + using Colors = std::vector; + using Normals = std::vector; + using Lights = std::vector; + using Indices = std::vector; + +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; }; @@ -59,12 +151,18 @@ private: class OutlineModel { public: + using Position = glm::vec3; + using Color = glm::vec3; using Index = unsigned short; + using Positions = std::vector; + using Colors = std::vector; + using Indices = std::vector; + public: - std::vector vertices; - std::vector colors; - std::vector indices; + Positions vertices; + Colors colors; + Indices indices; public: OutlineModel();