X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmodel.hpp;h=096e1cfd3aff2738f6288a6909c557d227ed3909;hb=83ed3de28841d1eecfca39ff540e804cf6809b32;hp=4fd4515563022215e0ca8e2f847813b4610b501f;hpb=2d8c7c015478a4528c0909f11d43998b1393948d;p=blank.git diff --git a/src/model.hpp b/src/model.hpp index 4fd4515..096e1cf 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -11,37 +11,133 @@ namespace blank { class Model { public: - std::vector vertices; - std::vector colors; - std::vector normals; + 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: + struct Buffer { + + Positions vertices; + Colors colors; + Normals normals; + Indices indices; + + void Clear() noexcept { + 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(); + Model() noexcept; + ~Model() noexcept; Model(const Model &) = delete; Model &operator =(const Model &) = delete; - void Invalidate() { dirty = true; } + Model(Model &&) noexcept; + Model &operator =(Model &&) noexcept; - void Clear(); - void Reserve(int); + void Update(const Buffer &) noexcept; - void Draw(); + void Draw() const noexcept; 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 Light = float; + using Index = unsigned int; + + using Positions = std::vector; + using Colors = std::vector; + using Lights = std::vector; + using Indices = std::vector; + +public: + struct Buffer { + + Positions vertices; + Colors colors; + Lights lights; + Indices indices; + + void Clear() noexcept { + vertices.clear(); + colors.clear(); + lights.clear(); + indices.clear(); + } + + void Reserve(size_t p, size_t i) { + vertices.reserve(p); + colors.reserve(p); + lights.reserve(p); + indices.reserve(i); + } + + }; + +public: + BlockModel() noexcept; + ~BlockModel() noexcept; + + BlockModel(const BlockModel &) = delete; + BlockModel &operator =(const Model &) = delete; + + BlockModel(BlockModel &&) noexcept; + BlockModel &operator =(BlockModel &&) noexcept; + + void Update(const Buffer &) noexcept; + + void Draw() const noexcept; 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; }; @@ -49,33 +145,45 @@ private: class OutlineModel { public: - std::vector vertices; - std::vector colors; + 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: + Positions vertices; + Colors colors; + Indices indices; public: - OutlineModel(); - ~OutlineModel(); + OutlineModel() noexcept; + ~OutlineModel() noexcept; OutlineModel(const OutlineModel &) = delete; OutlineModel &operator =(const OutlineModel &) = delete; - void Invalidate() { dirty = true; } + void Invalidate() noexcept { dirty = true; } - void Clear(); - void Reserve(int); + void Clear() noexcept; + void Reserve(int vtx_count, int idx_count); - void Draw(); + void Draw() noexcept; private: - void Update(); + void Update() noexcept; private: enum Attribute { ATTRIB_VERTEX, ATTRIB_COLOR, + ATTRIB_INDEX, ATTRIB_COUNT, }; + GLuint va; GLuint handle[ATTRIB_COUNT]; bool dirty;