@@ -12,45 +12,55 @@ DebugScene::DebugScene(entt::registry ®, const RenderContext &renderer)
1212 : m_registry(reg)
1313 , m_renderer(renderer)
1414 , m_trianglePipeline(nullptr )
15- , m_linePipeline(nullptr ) {}
15+ , m_linePipeline(nullptr )
16+ , m_sharedMeshes() {
17+ this ->initializeSharedMeshes ();
18+ }
1619
1720DebugScene::DebugScene (DebugScene &&other)
1821 : m_registry(other.m_registry)
1922 , m_renderer(other.m_renderer)
2023 , m_trianglePipeline(other.m_trianglePipeline)
2124 , m_linePipeline(other.m_linePipeline)
22- , m_subsystems(std::move(other.m_subsystems)) {
25+ , m_subsystems(std::move(other.m_subsystems))
26+ , m_sharedMeshes(std::move(other.m_sharedMeshes)) {
2327 other.m_trianglePipeline = nullptr ;
2428 other.m_linePipeline = nullptr ;
2529}
2630
31+ void DebugScene::initializeSharedMeshes () {
32+ {
33+ std::array triad_datas = loadTriadSolid ();
34+ Mesh mesh = createMeshFromBatch (device (), triad_datas, true );
35+ setupPipelines (mesh.layout ());
36+ m_sharedMeshes.emplace (TRIAD, std::move (mesh));
37+ }
38+ {
39+ MeshData grid_data = loadGrid (20 );
40+ m_sharedMeshes.emplace (GRID, createMesh (device (), grid_data, true ));
41+ }
42+ {
43+ MeshData arrow_data = loadArrowSolid (false );
44+ m_sharedMeshes.emplace (ARROW, createMesh (device (), arrow_data, true ));
45+ }
46+ }
47+
2748std::tuple<entt::entity, DebugMeshComponent &>
2849DebugScene::addTriad (const Float3 &scale) {
29- auto triad_datas = loadTriadSolid ();
30- std::vector<Float4> triad_colors (3 );
31- Mesh triad = createMeshFromBatch (device (), triad_datas, true );
32- for (size_t i = 0 ; i < 3 ; i++) {
33- triad_colors[i] = triad_datas[i].material .baseColor ;
34- }
35- setupPipelines (triad.layout ());
3650 entt::entity entity = m_registry.create ();
3751 auto &item = m_registry.emplace <DebugMeshComponent>(
38- entity, DebugPipelines::TRIANGLE_FILL, std::move (triad), triad_colors,
39- true , scale);
52+ entity, DebugPipelines::TRIANGLE_FILL, TRIAD,
53+ std::vector<Float4>{m_triadColors.begin (), m_triadColors.end ()}, true ,
54+ scale);
4055 m_registry.emplace <TransformComponent>(entity, Mat4f::Identity ());
4156 return {entity, item};
4257}
4358
4459std::tuple<entt::entity, DebugMeshComponent &>
4560DebugScene::addLineGrid (const Float4 &color) {
46- auto grid_data = loadGrid (20 );
47- Mesh grid = createMesh (device (), grid_data, true );
48-
49- setupPipelines (grid.layout ());
5061 auto entity = m_registry.create ();
5162 auto &item = m_registry.emplace <DebugMeshComponent>(
52- entity, DebugPipelines::TRIANGLE_LINE, std::move (grid),
53- std::vector{color});
63+ entity, DebugPipelines::TRIANGLE_LINE, GRID, std::vector{color});
5464 m_registry.emplace <TransformComponent>(entity, Mat4f::Identity ());
5565 return {entity, item};
5666}
@@ -116,7 +126,7 @@ void DebugScene::render(CommandBuffer &cmdBuf, const Camera &camera) const {
116126 auto group =
117127 m_registry.view <const DebugMeshComponent, const TransformComponent>(
118128 entt::exclude<Disable>);
119- group.each ([&](auto &cmd, auto &tr) {
129+ group.each ([&](const DebugMeshComponent &cmd, auto &tr) {
120130 if (!cmd.enable )
121131 return ;
122132
@@ -131,11 +141,12 @@ void DebugScene::render(CommandBuffer &cmdBuf, const Camera &camera) const {
131141
132142 const GpuMat4 mvp = viewProj * tr;
133143 cmdBuf.pushVertexUniform (TRANSFORM_SLOT, mvp);
134- rend::bindMesh (render_pass, cmd.mesh );
135- for (size_t i = 0 ; i < cmd.mesh .numViews (); i++) {
144+ auto &mesh = this ->getMesh (cmd.meshType );
145+ rend::bindMesh (render_pass, mesh);
146+ for (size_t i = 0 ; i < mesh.numViews (); i++) {
136147 const auto &color = cmd.colors [i];
137148 cmdBuf.pushFragmentUniform (COLOR_SLOT, color);
138- rend::drawView (render_pass, cmd. mesh .view (i));
149+ rend::drawView (render_pass, mesh.view (i));
139150 }
140151 });
141152
0 commit comments