X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmodel.hpp;h=d5c77d174929756f2ace1445e887946b017dfe20;hb=d2d3cb877984b97fafb97254f5005cbf4bcf47a6;hp=02ab3f274bd5b096205f9c1d4a153bff004e7c4a;hpb=3baab6cca7423d55ea08288d96570b02380b1fe9;p=blank.git diff --git a/src/model.hpp b/src/model.hpp index 02ab3f2..d5c77d1 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -11,27 +11,114 @@ 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: + 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(); + + 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; + +}; + + +class OutlineModel { + public: - explicit Model( - std::vector &&vertices, - std::vector &&colors, - std::vector &&normals); - ~Model(); + 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(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: - std::vector vertices; - std::vector colors; - std::vector normals; + void Update(); + +private: + enum Attribute { + ATTRIB_VERTEX, + ATTRIB_COLOR, + ATTRIB_INDEX, + ATTRIB_COUNT, + }; + + GLuint va; GLuint handle[ATTRIB_COUNT]; + bool dirty; };