From bb6ec1d018ea49ab5813a1ade86707096a69ad7e Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 15 Nov 2025 10:51:19 +0800 Subject: [PATCH 1/5] feat: Merge Editor into one --- main.cpp | 62 +++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/main.cpp b/main.cpp index 3e70027..0c61d90 100644 --- a/main.cpp +++ b/main.cpp @@ -133,29 +133,53 @@ void main() ImGui::ShowDemoWindow(); { - ImGui::Begin("NodeEditor"); - auto change = ImGui::DragFloat3("node1", vertices[0].position(), 0.01f, -1.f, 1.f); - change = ImGui::DragFloat3("node2", vertices[1].position(), 0.01f, -1.f, 1.f) || change; - change = ImGui::DragFloat3("node3", vertices[2].position(), 0.01f, -1.f, 1.f) || change; - if (change) + ImGui::Begin("Editor"); + static int current = 0; + const char* items[] = {"Node", "Vertex", "Fragment"}; + ImGui::Combo("##Object", ¤t, items, IM_ARRAYSIZE(items)); + switch (current) { - vertex_buffer.upload(&vertices, sizeof(vertices), 0); + case 0: + { + + auto change = ImGui::DragFloat3("##node1", vertices[0].position(), 0.01f, -1.f, 1.f); + change = ImGui::DragFloat3("##node2", vertices[1].position(), 0.01f, -1.f, 1.f) || change; + change = ImGui::DragFloat3("##node3", vertices[2].position(), 0.01f, -1.f, 1.f) || change; + if (change) + { + vertex_buffer.upload(&vertices, sizeof(vertices), 0); + } + } + break; + case 1: + { + auto line_count = std::count(vertex_source.begin(), vertex_source.end(), '\n'); + ImVec2 size = ImVec2( + ImGui::GetContentRegionAvail().x, + std::min(ImGui::GetTextLineHeight() * (line_count + 3), ImGui::GetContentRegionAvail().y)); + if (ImGui::InputTextMultiline("##vertex editor", &vertex_source, size, + ImGuiInputTextFlags_AllowTabInput)) + { + pipeline_wrapper.set_vertex_shader(vertex_source); + } + } + break; + case 2: + { + auto line_count = std::count(fragment_source.begin(), fragment_source.end(), '\n'); + ImVec2 size = ImVec2( + ImGui::GetContentRegionAvail().x, + std::min(ImGui::GetTextLineHeight() * (line_count + 3), ImGui::GetContentRegionAvail().y)); + if (ImGui::InputTextMultiline("##fragment editor", &fragment_source, size, + ImGuiInputTextFlags_AllowTabInput)) + { + pipeline_wrapper.set_fragment_shader(fragment_source); + } + } + break; } ImGui::End(); } - { - ImGui::Begin("SourceEditor"); - auto line_count = std::count(vertex_source.begin(), vertex_source.end(), '\n'); - ImVec2 size = - ImVec2(ImGui::GetContentRegionAvail().x, - std::min(ImGui::GetTextLineHeight() * (line_count + 3), ImGui::GetContentRegionAvail().y)); - if (ImGui::InputTextMultiline("code editor", &vertex_source, size, ImGuiInputTextFlags_AllowTabInput)) - { - pipeline_wrapper.set_vertex_shader(vertex_source); - } - - ImGui::End(); - } ImGui::EndFrame(); return SDL_APP_CONTINUE; From 5e29c2bff0525a416087d1722991dac9e7395b51 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 15 Nov 2025 10:59:07 +0800 Subject: [PATCH 2/5] feat: switch from c array into std array --- main.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 0c61d90..d7ef277 100644 --- a/main.cpp +++ b/main.cpp @@ -135,8 +135,8 @@ void main() { ImGui::Begin("Editor"); static int current = 0; - const char* items[] = {"Node", "Vertex", "Fragment"}; - ImGui::Combo("##Object", ¤t, items, IM_ARRAYSIZE(items)); + std::array items = {"Node", "Vertex", "Fragment"}; + ImGui::Combo("##Object", ¤t, items.data(), items.size()); switch (current) { case 0: From 2161e0a500ce1afbb8c81332ba516bf63f15a9c2 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 15 Nov 2025 10:59:07 +0800 Subject: [PATCH 3/5] feat: switch from c array into std array --- main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/main.cpp b/main.cpp index d7ef277..790d3a6 100644 --- a/main.cpp +++ b/main.cpp @@ -141,7 +141,6 @@ void main() { case 0: { - auto change = ImGui::DragFloat3("##node1", vertices[0].position(), 0.01f, -1.f, 1.f); change = ImGui::DragFloat3("##node2", vertices[1].position(), 0.01f, -1.f, 1.f) || change; change = ImGui::DragFloat3("##node3", vertices[2].position(), 0.01f, -1.f, 1.f) || change; From b240c8d5381b8d873204a68bf8f8eaf7c67513f3 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 15 Nov 2025 11:02:17 +0800 Subject: [PATCH 4/5] fix: add comment --- main.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/main.cpp b/main.cpp index 790d3a6..c74b65a 100644 --- a/main.cpp +++ b/main.cpp @@ -146,6 +146,7 @@ void main() change = ImGui::DragFloat3("##node3", vertices[2].position(), 0.01f, -1.f, 1.f) || change; if (change) { + // TODO: shouldn't upload in tick, we should delay this into draw function. vertex_buffer.upload(&vertices, sizeof(vertices), 0); } } From 50e2a706ccaa674abdd97fdb6a6e40199ec39ae3 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 15 Nov 2025 11:06:17 +0800 Subject: [PATCH 5/5] feat: add default case --- main.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/main.cpp b/main.cpp index c74b65a..fe41282 100644 --- a/main.cpp +++ b/main.cpp @@ -177,6 +177,8 @@ void main() } } break; + default: + break; } ImGui::End(); }