From 293eeb375928412c76004ec2a6234bd41b4d2faf Mon Sep 17 00:00:00 2001 From: David Allemang Date: Thu, 21 May 2020 20:28:19 -0400 Subject: [PATCH] introduce Bundle --- vis/src/main.cpp | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 5691118..8848be3 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -146,9 +146,29 @@ struct Prop { Prop() : vao(), vbo(), ibo() {} }; +template +struct Bundle : public std::vector> { +}; + template struct Renderer { - virtual void draw(const Prop &) const = 0; + virtual void bound(const std::function &action) const = 0; + + virtual void _draw(const Prop &) const = 0; + + void draw(const Prop &prop) const { + bound([&]() { + _draw(prop); + }); + } + + void draw(const Bundle &bundle) const { + bound([&]() { + for (const Prop &prop : bundle) { + _draw(prop); + } + }); + } }; template @@ -196,14 +216,16 @@ struct SliceRenderer : public Renderer { SliceRenderer(SliceRenderer &&) noexcept = default; - void draw(const Prop &prop) const override { - pipe.bound([&]() { - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, prop.vbo); -// glProgramUniform3fv(solid, 2, 1, &prop.color.front()); - glProgramUniform3f(solid, 2, 1.f, 1.f, 1.f); - prop.vao.bound([&]() { - glDrawArrays(GL_POINTS, 0, prop.ibo.count() * N); - }); + void bound(const std::function &action) const override { + pipe.bound(action); + } + + void _draw(const Prop &prop) const override { + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, prop.vbo); +// glProgramUniform3fv(solid, 2, 1, &prop.color.front()); + glProgramUniform3f(solid, 2, 1.f, 1.f, 1.f); + prop.vao.bound([&]() { + glDrawArrays(GL_POINTS, 0, prop.ibo.count() * N); }); } }; @@ -268,7 +290,8 @@ void run(const std::string &config_file, GLFWwindow *window) { state.dimension = scene["dimension"].as(); - auto slices = std::vector>(); + auto slices = Bundle<4>(); +// auto slices = std::vector>(); // auto wires = std::vector(); for (const auto &group_info : scene["groups"]) { @@ -370,9 +393,7 @@ void run(const std::string &config_file, GLFWwindow *window) { // } // }); - for (const auto &slice : slices) { - sRen.draw(slice); - } + sRen.draw(slices); glfwSwapInterval(2); glfwSwapBuffers(window);