From 49927568e4aae9577b7ced2213c5af0b3fb93ced Mon Sep 17 00:00:00 2001 From: David Allemang Date: Tue, 13 Oct 2020 10:56:55 -0400 Subject: [PATCH] Introduce cgl::Buffer::put for Eigen matrices and other containers. Make put(std::vector) more generic by specializing the new put method. --- vis/include/cgl/buffer.hpp | 14 ++++++++++---- vis/include/rendering.hpp | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/vis/include/cgl/buffer.hpp b/vis/include/cgl/buffer.hpp index de18bc1..ad3226e 100644 --- a/vis/include/cgl/buffer.hpp +++ b/vis/include/cgl/buffer.hpp @@ -53,14 +53,20 @@ namespace cgl { glNamedBufferData(id, sizeof(T), &data, usage); } - void put(const std::vector &data, GLenum usage = GL_STATIC_DRAW) { - put(&data[0], data.size(), usage); - } - void put(const T *data, const size_t &size, GLenum usage = GL_STATIC_DRAW) { glNamedBufferData(id, sizeof(T) * size, data, usage); } + template + void put(const E &data, GLenum usage = GL_STATIC_DRAW) { + put(data.data(), data.size(), usage); + } + + template<> + void put>(const std::vector &data, GLenum usage = GL_STATIC_DRAW) { + put(data.data, data.size(), usage); + } + void bound(GLenum target, const std::function &action) const { glBindBuffer(target, id); action(); diff --git a/vis/include/rendering.hpp b/vis/include/rendering.hpp index 090238d..9fe87d4 100644 --- a/vis/include/rendering.hpp +++ b/vis/include/rendering.hpp @@ -44,8 +44,8 @@ public: template Slice(const tc::Group &g, T all_sg_gens, const std::vector> &exclude) : group(g) { - const Prims &data = merge(hull(g, all_sg_gens, exclude)); - ibo.put(data.data(), data.size()); + const auto &data = merge(hull(g, all_sg_gens, exclude)); + ibo.put(data); vao.ipointer(0, ibo, 4, GL_UNSIGNED_INT); }