Vulkan集成DearImgui傻瓜版

651 阅读1分钟

在Vulkan中集成imgui需要做的事:

draw_frame前\

准备imgui所需要的descriptor pool
创建imgui的context (ImGui::CreateContext)
绑定具体的surface (ImGui_ImplGlfw_InitForVulkan)
绑定相应的Vulkan上下文 (ImGui_ImplVulkan_Init)
绑定相应的字体资源 (ImGui_ImplVulkan_CreateFontsTexture),需要command buffer,并进行queueSubmit (清理字体资源)

draw_frame中进行queue_submit之前

    //生成Imgui的new frame
        ImGui_ImplVulkan_NewFrame();
        ImGui_ImplGlfw_NewFrame();
        ImGui::NewFrame(); 
    //具体的UI生成
        ;
    //render后获取ImDrawData
        ImGui::Render();
        ImDrawData* draw_data = ImGui::GetDrawData();

在draw_frame的command buffer中加入

ImGui_ImplVulkan_RenderDrawData(draw_data,m_command_buffer);// CORE!!

draw_frame后的资源清理

    vkDestroyDescriptorPool(m_device, imgui_descriptor_pool, m_allocator);
    ImGui_ImplVulkan_Shutdown();
    ImGui_ImplGlfw_Shutdown();
    ImGui::DestroyContext();

完成Vulkan+GLFW对DearImgui的集成