From 600d7ff8eb2bbc6b28bcbc0feb83df06d33f85a1 Mon Sep 17 00:00:00 2001 From: Sophomore <17792626+WSQS@users.noreply.github.com> Date: Sat, 15 Nov 2025 09:20:53 +0800 Subject: [PATCH 1/2] feat: split tick function and draw function --- main.cpp | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/main.cpp b/main.cpp index 9819628..af710d6 100644 --- a/main.cpp +++ b/main.cpp @@ -114,17 +114,7 @@ void main() return SDL_APP_CONTINUE; } - /** - * @brief Advance the application by one frame: update UI, apply vertex edits and live shader recompilation, render, - * and submit GPU work. - * - * Processes ImGui frames, uploads vertex data when edited, recompiles and replaces the vertex shader and graphics - * pipeline on shader edits, records a render pass that draws the triangle and ImGui draw lists, and submits the GPU - * command buffer for presentation. - * - * @return `SDL_APP_CONTINUE` to continue the main loop. - */ - virtual SDL_AppResult iterate() override + SDL_AppResult tick() { ImGui_ImplSDLGPU3_NewFrame(); ImGui_ImplSDL3_NewFrame(); @@ -157,6 +147,12 @@ void main() ImGui::End(); } + ImGui::EndFrame(); + return SDL_APP_CONTINUE; + } + + SDL_AppResult draw() + { ImGui::Render(); ImDrawData* draw_data = ImGui::GetDrawData(); @@ -213,6 +209,27 @@ void main() return SDL_APP_CONTINUE; } + /** + * @brief Advance the application by one frame: update UI, apply vertex edits and live shader recompilation, render, + * and submit GPU work. + * + * Processes ImGui frames, uploads vertex data when edited, recompiles and replaces the vertex shader and graphics + * pipeline on shader edits, records a render pass that draws the triangle and ImGui draw lists, and submits the GPU + * command buffer for presentation. + * + * @return `SDL_APP_CONTINUE` to continue the main loop. + */ + virtual SDL_AppResult iterate() override + { + + auto result = tick(); + if (result == SDL_APP_CONTINUE) + { + result = draw(); + } + return result; + } + /** * @brief Handle an SDL event by forwarding it to ImGui and handling window-close requests. * From e50e077cd205fd300f86e4c45c25462cc696bf3b Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Sat, 15 Nov 2025 09:31:09 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`tic?= =?UTF-8?q?k=5Fdraw`=20(#28)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 📝 Add docstrings to `tick_draw` Docstrings generation was requested by @WSQS. * https://github.com/WSQS/sdl_test/pull/27#issuecomment-3535276739 The following files were modified: * `main.cpp` * style: format code with ClangFormat This commit fixes the style issues introduced in 7f55a49 according to the output from ClangFormat. Details: https://github.com/WSQS/sdl_test/pull/28 --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com> --- main.cpp | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/main.cpp b/main.cpp index af710d6..3e70027 100644 --- a/main.cpp +++ b/main.cpp @@ -114,6 +114,16 @@ void main() return SDL_APP_CONTINUE; } + /** + * @brief Advance the UI frame, present interactive editors for triangle vertices and shader source, and apply + * edits. + * + * Presents a NodeEditor with draggable 3D position editors for each vertex and a SourceEditor with a multiline + * shader text editor. If a vertex position is modified, the vertex buffer is updated with the new vertex data. + * If the shader source is modified, the pipeline's vertex shader source is updated. + * + * @return SDL_AppResult SDL_APP_CONTINUE to indicate the application should continue running. + */ SDL_AppResult tick() { ImGui_ImplSDLGPU3_NewFrame(); @@ -151,6 +161,16 @@ void main() return SDL_APP_CONTINUE; } + /** + * @brief Render ImGui draw data and the application's triangle to the GPU, then present the swapchain texture. + * + * Prepares ImGui draw data, submits the graphics pipeline, acquires a GPU command buffer and the current + * swapchain texture, records rendering commands (including binding the pipeline and vertex buffer and issuing + * a draw call), executes ImGui rendering into the render pass, and submits the command buffer for presentation. + * If no swapchain texture is available the function still submits the command buffer and continues. + * + * @return SDL_AppResult `SDL_APP_CONTINUE` to continue the application main loop. + */ SDL_AppResult draw() { ImGui::Render(); @@ -210,14 +230,12 @@ void main() } /** - * @brief Advance the application by one frame: update UI, apply vertex edits and live shader recompilation, render, - * and submit GPU work. + * @brief Advance the application one iteration by performing per-frame updates and rendering. * - * Processes ImGui frames, uploads vertex data when edited, recompiles and replaces the vertex shader and graphics - * pipeline on shader edits, records a render pass that draws the triangle and ImGui draw lists, and submits the GPU - * command buffer for presentation. + * Performs per-frame UI and state updates; if those updates indicate continuation, executes rendering and submits + * GPU work for presentation. * - * @return `SDL_APP_CONTINUE` to continue the main loop. + * @return `SDL_APP_CONTINUE` to continue the main loop, or another `SDL_AppResult` to terminate. */ virtual SDL_AppResult iterate() override {