ENH: Upload to buffer from iterator

This commit is contained in:
David Allemang
2023-02-04 21:09:22 -05:00
parent 11a5e29518
commit c8025b29db
2 changed files with 14 additions and 6 deletions

View File

@@ -53,8 +53,12 @@ namespace cgl {
glNamedBufferData(id, sizeof(T), &data, usage);
}
void put(const std::vector<T> &data, GLenum usage = GL_STATIC_DRAW) {
glNamedBufferData(id, sizeof(T) * data.size(), &data[0], usage);
template<typename It>
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<void()> &action) const {

View File

@@ -153,8 +153,10 @@ struct SliceProp : public Prop<N> {
) {
SliceProp<N> res(color);
res.vbo.put(points(g, coords));
res.ibo.put(merge<N>(hull<N>(g, all_sg_gens, exclude)));
auto pts = points(g, coords);
res.vbo.put(pts.begin(), pts.end());
auto inds = merge<N>(hull<N>(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;
}