From fe8bc91b56677409be94804eb321c2bac4774091 Mon Sep 17 00:00:00 2001 From: Karn Kaul Date: Sun, 23 Mar 2025 18:38:16 -0700 Subject: [PATCH] Issue ImGui API calls inside app render pass --- guide/src/dear_imgui/imgui_integration.md | 6 ++++++ src/app.cpp | 3 +-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/guide/src/dear_imgui/imgui_integration.md b/guide/src/dear_imgui/imgui_integration.md index c7ce6db..b52d402 100644 --- a/guide/src/dear_imgui/imgui_integration.md +++ b/guide/src/dear_imgui/imgui_integration.md @@ -33,9 +33,15 @@ Start a new ImGui frame after resetting the render fence, and show the demo wind m_device->resetFences(*render_sync.drawn); m_imgui->new_frame(); +// ... +render_sync.command_buffer.beginRendering(rendering_info); ImGui::ShowDemoWindow(); +// draw stuff here. +render_sync.command_buffer.endRendering(); ``` +ImGui doesn't draw anything here (the actual draw command requires the Command Buffer), it's just a good customization point to use indirection at later. + We use a separate render pass for Dear ImGui, again for isolation, and to enable us to change the main render pass later, eg by adding a depth buffer attachment (`DearImGui` is setup assuming its render pass will only use a single color attachment). ```cpp diff --git a/src/app.cpp b/src/app.cpp index 98c273d..5aa85b2 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -183,8 +183,6 @@ void App::main_loop() { m_device->resetFences(*render_sync.drawn); m_imgui->new_frame(); - ImGui::ShowDemoWindow(); - auto command_buffer_bi = vk::CommandBufferBeginInfo{}; // this flag means recorded commands will not be reused. command_buffer_bi.setFlags( @@ -222,6 +220,7 @@ void App::main_loop() { .setLayerCount(1); render_sync.command_buffer.beginRendering(rendering_info); + ImGui::ShowDemoWindow(); // draw stuff here. render_sync.command_buffer.endRendering();