diff --git a/src/hello_imgui/internal/backend_impls/rendering_vulkan.cpp b/src/hello_imgui/internal/backend_impls/rendering_vulkan.cpp index cc41426f..903143a5 100644 --- a/src/hello_imgui/internal/backend_impls/rendering_vulkan.cpp +++ b/src/hello_imgui/internal/backend_impls/rendering_vulkan.cpp @@ -56,14 +56,28 @@ namespace HelloImGui // ImGui_ImplGlfw_NewFrame(); }; - callbacks->Impl_Frame_3D_ClearColor = [] (ImVec4) {}; + callbacks->Impl_Frame_3D_ClearColor = [] (ImVec4) + { + // Note: at this moment, Impl_Frame_3D_ClearColor is empty, because the clearing is done in Impl_RenderDrawData_To_3D + // + // If you want to skip the clearing because you provided a CustomBackground() callback + // some adaptations are probably needed. + // For example: + // - Impl_NewFrame_3D could set loadOp to VK_ATTACHMENT_LOAD_OP_LOAD to preserve the existing content + // - Impl_Frame_3D_ClearColor(), if called, would then set it to VK_ATTACHMENT_LOAD_OP_CLEAR + // (Impl_Frame_3D_ClearColor is not called if CustomBackground() is provided) + // + // However, this requires that the render pass in Vulkan is configured to support dynamic changes. + // (probably by setting ImGui_ImplVulkan_InitInfo init_info.UseDynamicRendering = true; inside + // PrepareGlfwForVulkan() and PrepareSdlForVulkan() (see rendering_vulkan_glfw.cpp and rendering_vulkan_sdl.cpp) + }; callbacks->Impl_RenderDrawData_To_3D = [] { auto & gVkGlobals = HelloImGui::GetVulkanGlobals(); + ImGui_ImplVulkanH_Window* wd = &gVkGlobals.ImGuiMainWindowData; ImVec4 clear_color = HelloImGui::GetRunnerParams()->imGuiWindowParams.backgroundColor; - ImDrawData* main_draw_data = ImGui::GetDrawData(); const bool main_is_minimized = (main_draw_data->DisplaySize.x <= 0.0f || main_draw_data->DisplaySize.y <= 0.0f); wd->ClearValue.color.float32[0] = clear_color.x * clear_color.w;