From 844bf23b3b2fe0a18822f17af032fa1eb2dc8ab6 Mon Sep 17 00:00:00 2001 From: David Allemang Date: Sun, 12 Feb 2023 09:59:27 -0500 Subject: [PATCH] WIP: organization - move group, root into Structure<> - semantic type aliases like VectorDf, MatrixGXui, etc. - separate components and systems files --- vis/CMakeLists.txt | 2 +- vis/src/components.hpp | 97 ++++++++++++++++++++++++++++++ vis/src/main.cpp | 14 ++--- vis/src/{comps.hpp => systems.hpp} | 83 ++++++++----------------- 4 files changed, 130 insertions(+), 66 deletions(-) create mode 100644 vis/src/components.hpp rename vis/src/{comps.hpp => systems.hpp} (61%) diff --git a/vis/CMakeLists.txt b/vis/CMakeLists.txt index 2d18e08..4a753a1 100644 --- a/vis/CMakeLists.txt +++ b/vis/CMakeLists.txt @@ -9,7 +9,7 @@ add_custom_command( add_executable(vis src/main.cpp - src/comps.hpp + src/components.hpp ) target_include_directories(vis PRIVATE include) target_link_libraries(vis PRIVATE diff --git a/vis/src/components.hpp b/vis/src/components.hpp new file mode 100644 index 0000000..d9fa7b0 --- /dev/null +++ b/vis/src/components.hpp @@ -0,0 +1,97 @@ +#pragma once + +#include +#include +#include +#include + +#include + +#include + +#include + +#include "mirror.hpp" +#include "geometry.hpp" +#include "solver.hpp" + +#include + +namespace vis { + template + struct Structure { + static constexpr auto Rank = R_; + static constexpr auto Dim = D_; + static constexpr auto Grade = G_; + + using Affine = Eigen::Transform; + + using VectorRf = Eigen::Vector; + using MatrixRXf = Eigen::Matrix; + using VectorDf = Eigen::Vector; + using MatrixDXf = Eigen::Matrix; + using VectorGf = Eigen::Vector; + using MatrixGXf = Eigen::Matrix; + + using ArrayRui = Eigen::Array; + using ArrayRXui = Eigen::Array; + using ArrayDui = Eigen::Array; + using ArrayDXui = Eigen::Array; + using ArrayGui = Eigen::Array; + using ArrayGXui = Eigen::Array; + + using Color = Eigen::Vector; // todo global typedef + + // todo cache and recompute cells/points on frame (only if changed) in a system. + + tc::Group group; + VectorRf root; + + Points points; + Hull hull; + + std::vector enabled; + std::vector colors; + + Affine transform = Affine::Identity(); + + explicit Structure( + tc::Group group, + VectorRf root, + Color color_ = Color::Ones() + ) : + group(group), + root(root), + points(group, root), // todo separate system + hull(group), // todo separate system + enabled(hull.tilings.size(), true), + colors(hull.tilings.size(), color_), + transform(Affine::Identity()) { + } + }; + + template + struct VBOs { + using Str = Str_; + + using VectorDf = Str::VectorDf; + using Color = Str::Color; + using ArrayGui = Str::ArrayGui; + + struct Uniform { + Eigen::Matrix4f linear; + Eigen::Vector4f translation; + }; + + struct Command { + unsigned int count, instanceCount, first, baseInstance; + }; + + cgl::Buffer vertices; + cgl::Buffer colors; + cgl::Buffer indices; + cgl::Buffer uniform; + cgl::Buffer commands; + }; + +} diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 80bb3bf..f78546b 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -13,9 +13,10 @@ #include "util.hpp" #include "mirror.hpp" -#include "comps.hpp" +#include "components.hpp" #include "fmt/core.h" #include "fmt/ranges.h" +#include "systems.hpp" #include @@ -156,14 +157,13 @@ int run(GLFWwindow* window, ImGuiContext* ctx) { auto entity = registry.create(); { - // todo move symbol and root to structure - // cache and recompute cells/points on frame (only if changed) in a system. - tc::Group group = tc::schlafli({5, 3, 3, 2}); - Points points(group, vec5{0.80, 0.09, 0.09, 0.09, 0.09}); - Hull<4> hull(group); - auto &structure = registry.emplace(entity, std::move(points), std::move(hull)); + auto &structure = registry.emplace( + entity, + group, + vec5{0.80, 0.09, 0.09, 0.09, 0.09} + ); registry.emplace>(entity); structure.enabled[0] = false; // disable {0,1,2} cells diff --git a/vis/src/comps.hpp b/vis/src/systems.hpp similarity index 61% rename from vis/src/comps.hpp rename to vis/src/systems.hpp index 0f3cb29..b7616c1 100644 --- a/vis/src/comps.hpp +++ b/vis/src/systems.hpp @@ -14,60 +14,11 @@ #include "mirror.hpp" #include "geometry.hpp" #include "solver.hpp" +#include "components.hpp" #include namespace vis { - template - struct Structure { - static constexpr auto Rank = R_; - static constexpr auto Dim = D_; - static constexpr auto Grade = G_; - - using Affine = Eigen::Transform; - - using Vertex = Eigen::Vector; - using Color = Eigen::Vector; - using Cell = Eigen::Array; - - Points points; - Hull hull; - - std::vector enabled; - std::vector colors; - - Affine transform = Affine::Identity(); - - template - explicit Structure(P &&points_, H &&hull_, Color color_ = Color::Ones()): - points(std::forward

(points_)), - hull(std::forward(hull_)), - enabled(hull.tilings.size(), true), - colors(hull.tilings.size(), color_), - transform(Affine::Identity()) { - } - }; - - template - struct VBOs { - using Str = Str_; - - struct Uniform { - Eigen::Matrix4f linear; - Eigen::Vector4f translation; - }; - - struct Command { - unsigned int count, instanceCount, first, baseInstance; - }; - - cgl::Buffer vertices; - cgl::Buffer colors; - cgl::Buffer indices; - cgl::Buffer uniform; - cgl::Buffer commands; - }; - template void upload_structure(entt::registry ®istry) { auto view = registry.view>(); @@ -134,9 +85,9 @@ namespace vis { pipe.stage(slice); pipe.stage(solid); - vao.iformat(0, 4, GL_UNSIGNED_INT); - vao.format(1, 3, GL_FLOAT); + vao.iformat(0, Str::Grade, GL_UNSIGNED_INT); // inds + vao.format(1, 3, GL_FLOAT); // color glVertexArrayBindingDivisor(vao, 1, 1); } @@ -146,20 +97,36 @@ namespace vis { for (auto [entity, vbos]: view.each()) { glBindProgramPipeline(pipe); - glBindBufferBase(GL_UNIFORM_BUFFER, 2, vbos.uniform); - glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbos.vertices); + glBindBufferBase( + GL_SHADER_STORAGE_BUFFER, + 1, + vbos.vertices + ); + glBindBufferBase( + GL_UNIFORM_BUFFER, + 2, + vbos.uniform + ); + + glBindBuffer( + GL_DRAW_INDIRECT_BUFFER, + vbos.commands + ); vao.vertexBuffer(0, vbos.indices); vao.vertexBuffer(1, vbos.colors); - glBindBuffer(GL_DRAW_INDIRECT_BUFFER, vbos.commands); - glBindVertexArray(vao); - glMultiDrawArraysIndirect(GL_POINTS, nullptr, vbos.commands.count(), 0); + glMultiDrawArraysIndirect( + GL_POINTS, + nullptr, + vbos.commands.count(), + 0 + ); glBindVertexArray(0); glBindProgramPipeline(0); } } }; -} +} \ No newline at end of file