X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fmodel.hpp;h=d5c77d174929756f2ace1445e887946b017dfe20;hb=b368ecb2c0f34e27b1d3b97cceb218b554dee324;hp=4423cd7115338f671847d2461def60ffd11454cd;hpb=5700ea3c08ea5e4a5c743f0413b65dc8eebfd220;p=blank.git diff --git a/src/model.hpp b/src/model.hpp index 4423cd7..d5c77d1 100644 --- a/src/model.hpp +++ b/src/model.hpp @@ -11,9 +11,39 @@ 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() { + 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,22 @@ public: Model(Model &&); Model &operator =(Model &&); - void Invalidate() { dirty = true; } - - void Clear(); - void Reserve(int); - - void Draw(); + void Update(const Buffer &); -private: - void Update(); + void Draw() const; private: enum Attribute { ATTRIB_VERTEX, ATTRIB_COLOR, ATTRIB_NORMAL, + ATTRIB_INDEX, ATTRIB_COUNT, }; + GLuint va; GLuint handle[ATTRIB_COUNT]; - bool dirty; + size_t count; }; @@ -52,8 +78,18 @@ 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(); @@ -65,7 +101,7 @@ public: void Invalidate() { dirty = true; } void Clear(); - void Reserve(int); + void Reserve(int vtx_count, int idx_count); void Draw(); @@ -76,9 +112,11 @@ private: enum Attribute { ATTRIB_VERTEX, ATTRIB_COLOR, + ATTRIB_INDEX, ATTRIB_COUNT, }; + GLuint va; GLuint handle[ATTRIB_COUNT]; bool dirty;