diff --git a/vis/include/cgl/buffer.hpp b/vis/include/cgl/buffer.hpp index 57b0977..0cc9369 100644 --- a/vis/include/cgl/buffer.hpp +++ b/vis/include/cgl/buffer.hpp @@ -53,8 +53,12 @@ namespace cgl { glNamedBufferData(id, sizeof(T), &data, usage); } - void put(const std::vector &data, GLenum usage = GL_STATIC_DRAW) { - glNamedBufferData(id, sizeof(T) * data.size(), &data[0], usage); + template + void put(It begin, It end, GLenum usage = GL_STATIC_DRAW) { + glNamedBufferData(id, sizeof(T) * (end - begin), nullptr, usage); + void* ptr = glMapNamedBuffer(id, GL_WRITE_ONLY); + std::copy(begin, end, (T*) ptr); + glUnmapNamedBuffer(id); } void bound(GLenum target, const std::function &action) const { diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 04c3c54..589934f 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -153,8 +153,10 @@ struct SliceProp : public Prop { ) { SliceProp res(color); - res.vbo.put(points(g, coords)); - res.ibo.put(merge(hull(g, all_sg_gens, exclude))); + auto pts = points(g, coords); + res.vbo.put(pts.begin(), pts.end()); + auto inds = merge(hull(g, all_sg_gens, exclude)); + res.ibo.put(inds.begin(), inds.end()); res.vao.ipointer(0, res.ibo, 4, GL_UNSIGNED_INT); return res; @@ -244,8 +246,10 @@ struct WireframeProp : public Prop<2> { ) { WireframeProp res(color); - res.vbo.put(points(g, coords)); - res.ibo.put(merge<2>(hull<2>(g, all_sg_gens, exclude))); + auto pts = points(g, coords); + res.vbo.put(pts.begin(), pts.end()); + auto inds = merge<2>(hull<2>(g, all_sg_gens, exclude)); + res.ibo.put(inds.begin(), inds.end()); return res; }