changes for ImGui

This commit is contained in:
2026-09-15 02:23:22 -07:00
parent 12a1e6eca9
commit 05fe3c2ee8
14 changed files with 593 additions and 6 deletions
+85
View File
@@ -0,0 +1,85 @@
#include "imgui_renderer.hpp"
#include <imgui.h>
#include <imgui_impl_glfw.h>
#include <imgui_impl_vulkan.h>
namespace sophia {
ImGuiRenderer::ImGuiRenderer(Window& window, Device& device,
vk::Format colorAttachmentFormat,
u32 minImageCount) {
// 1. Construct ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGui_ImplGlfw_InitForVulkan(window.getGLFWwindow(), true);
ImGui_ImplVulkan_InitInfo initInfo = {};
device.populateImGuiInitInfo(initInfo);
initInfo.DescriptorPoolSize =
IMGUI_IMPL_VULKAN_MINIMUM_SAMPLED_IMAGE_POOL_SIZE + 5;
initInfo.MinImageCount = minImageCount;
initInfo.ImageCount = minImageCount;
VkFormat rawColorAttachmentFormat =
static_cast<VkFormat>(colorAttachmentFormat);
initInfo.UseDynamicRendering = true;
initInfo.PipelineInfoMain.PipelineRenderingCreateInfo.sType =
VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR;
initInfo.PipelineInfoMain.PipelineRenderingCreateInfo.colorAttachmentCount =
1;
initInfo.PipelineInfoMain.PipelineRenderingCreateInfo
.pColorAttachmentFormats = &rawColorAttachmentFormat;
ImGui_ImplVulkan_Init(&initInfo);
// 2. Enable dark theme
ImGui::StyleColorsDark();
// 3. Enable docking / keyboard
ImGuiIO& io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad;
/**
* When viewports are enabled we tweak WindowRounding/WindowBg so
* platform windows can look identical to regular ones.
*/
ImGuiStyle& style = ImGui::GetStyle();
if (ImGui::GetIO().ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
style.WindowRounding = 0.0f;
style.Colors[ImGuiCol_WindowBg].w = 1.0f;
}
}
ImGuiRenderer::~ImGuiRenderer() {
ImGui_ImplVulkan_Shutdown();
ImGui_ImplGlfw_Shutdown();
ImGui::DestroyContext();
}
void ImGuiRenderer::beginFrame() {
ImGui_ImplVulkan_NewFrame();
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(),
ImGuiDockNodeFlags_PassthruCentralNode);
}
void ImGuiRenderer::endFrame(vk::CommandBuffer commandBuffer) {
ImGui::Render();
ImDrawData* mainDrawData = ImGui::GetDrawData();
ImGuiIO& io = ImGui::GetIO();
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable) {
ImGui::UpdatePlatformWindows();
ImGui::RenderPlatformWindowsDefault();
}
ImGui_ImplVulkan_RenderDrawData(mainDrawData, commandBuffer);
}
} // namespace sophia