diff --git a/vis/src/comps.hpp b/vis/src/comps.hpp index 12c19bf..0f3cb29 100644 --- a/vis/src/comps.hpp +++ b/vis/src/comps.hpp @@ -31,7 +31,7 @@ namespace vis { using Cell = Eigen::Array; Points points; - Hull hull; + Hull hull; std::vector enabled; std::vector colors; @@ -48,7 +48,10 @@ namespace vis { } }; + template struct VBOs { + using Str = Str_; + struct Uniform { Eigen::Matrix4f linear; Eigen::Vector4f translation; @@ -58,15 +61,16 @@ namespace vis { unsigned int count, instanceCount, first, baseInstance; }; - cgl::Buffer::Vertex> vertices; - cgl::Buffer::Color> colors; - cgl::Buffer::Cell> indices; + 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, VBOs>(); + auto view = registry.view>(); for (auto [entity, structure, vbos]: view.each()) { auto vertices = structure.points.verts.colwise(); @@ -77,12 +81,13 @@ namespace vis { } } + template void upload_uniforms(entt::registry ®istry) { - auto view = registry.view, VBOs>(); + auto view = registry.view>(); for (auto [entity, structure, vbos]: view.each()) { auto colors = structure.colors; - VBOs::Uniform uniform{ + typename VBOs::Uniform uniform{ structure.transform.linear(), structure.transform.translation(), }; @@ -92,13 +97,14 @@ namespace vis { } } + template void upload_commands(entt::registry ®istry) { - auto view = registry.view, VBOs>(); + auto view = registry.view>(); for (auto [entity, structure, vbos]: view.each()) { const auto &tilings = structure.hull.tilings; - std::vector commands; + std::vector::Command> commands; for (unsigned int i = 0; i < tilings.size(); ++i) { if (structure.enabled[i]) { @@ -111,7 +117,10 @@ namespace vis { } } + template struct SliceRenderer { + using Str = Str_; + cgl::pgm::vert defer = cgl::pgm::vert(shaders::deferred_vs_glsl); cgl::pgm::geom slice = cgl::pgm::geom(shaders::slice_gm_glsl); cgl::pgm::frag solid = cgl::pgm::frag(shaders::solid_fs_glsl); @@ -132,11 +141,9 @@ namespace vis { } void operator()(entt::registry ®) { - auto view = reg.view(); + auto view = reg.view>(); for (auto [entity, vbos]: view.each()) { - const size_t N = 4; - glBindProgramPipeline(pipe); glBindBufferBase(GL_UNIFORM_BUFFER, 2, vbos.uniform); diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 32b8b48..80bb3bf 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -145,7 +145,8 @@ int run(GLFWwindow* window, ImGuiContext* ctx) { glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - vis::SliceRenderer renderer; + using Slice = vis::Structure<5, 4, 4>; + vis::SliceRenderer renderer; State state{}; glfwSetWindowUserPointer(window, &state); @@ -153,8 +154,6 @@ int run(GLFWwindow* window, ImGuiContext* ctx) { auto ®istry = state.registry; state.dimension = 4; - using Slice = vis::Structure<5, 4, 4>; - auto entity = registry.create(); { // todo move symbol and root to structure @@ -165,12 +164,12 @@ int run(GLFWwindow* window, ImGuiContext* ctx) { Hull<4> hull(group); auto &structure = registry.emplace(entity, std::move(points), std::move(hull)); - registry.emplace(entity); + registry.emplace>(entity); structure.enabled[0] = false; // disable {0,1,2} cells } - vis::upload_structure(registry); + vis::upload_structure(registry); auto ubo = cgl::Buffer(); glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo); @@ -229,8 +228,8 @@ int run(GLFWwindow* window, ImGuiContext* ctx) { tform.translation().w() = std::sin(state.time * 1.4) * 1.0; } - vis::upload_commands(registry); - vis::upload_uniforms(registry); + vis::upload_commands(registry); + vis::upload_uniforms(registry); renderer(registry);