Skip to content

Commit

Permalink
rendering_vulkan.cpp: add notes / custom_background & clear_color
Browse files Browse the repository at this point in the history
  • Loading branch information
pthom committed Jan 4, 2024
1 parent 2a0a25f commit cd4de2c
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/hello_imgui/internal/backend_impls/rendering_vulkan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit cd4de2c

Please sign in to comment.