-
-
Save emctague/3b6ac5740534fb5e7d01b234bae0bb3f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find_package(glm REQUIRED) | |
find_package(Vulkan REQUIRED) | |
find_package(SDL2 REQUIRED) | |
add_library(IMGUI STATIC ../extern/imgui/imgui.cpp ../extern/imgui/imgui_draw.cpp ../extern/imgui/imgui_demo.cpp ../extern/imgui/imgui_tables.cpp ../extern/imgui/imgui_widgets.cpp ../extern/imgui/misc/cpp/imgui_stdlib.cpp ../extern/imgui/backends/imgui_impl_vulkan.cpp ../extern/imgui/backends/imgui_impl_vulkan.h ../extern/imgui/backends/imgui_impl_sdl.cpp ../extern/ImGuiFileDialog/ImGuiFileDialog.cpp) | |
target_include_directories(IMGUI PUBLIC ../extern/imgui ../extern/ImGuiFileDialog) | |
target_link_libraries(IMGUI PUBLIC Vulkan::Vulkan SDL2::SDL2) | |
add_library(SGVK STATIC sgvk/Renderer.cpp sgvk/Renderer.h sgvk/Context.cpp sgvk/vk.h sgvk/Context.h) | |
target_include_directories(SGVK PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) | |
target_link_libraries(SGVK PUBLIC SG glm::glm common SGRENDER Vulkan::Vulkan IMGUI) | |
if (APPLE) | |
target_link_libraries(SGVK PUBLIC "-framework Cocoa" "-framework IOKit") | |
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ImGui_ImplVulkan_InitInfo initInfo{}; | |
initInfo.Instance = ctx.instance; | |
initInfo.PhysicalDevice = ctx.physicalDevice; | |
initInfo.Device = ctx.device; | |
initInfo.QueueFamily = ctx.graphicsIndex; | |
initInfo.Queue = ctx.graphicsQueue; | |
initInfo.DescriptorPool = ctx.descriptorPool; | |
initInfo.MSAASamples = VK_SAMPLE_COUNT_1_BIT; | |
initInfo.MinImageCount = ctx.imageCount; | |
initInfo.ImageCount = ctx.imageCount; | |
initInfo.Subpass = 1; | |
initInfo.CheckVkResultFn = check_vk_result; | |
int w, h; | |
SDL_Vulkan_GetDrawableSize(window, &w, &h); | |
LOG("Renderer: Initializing IMGUI"); | |
IMGUI_CHECKVERSION(); | |
imctx = ImGui::CreateContext(); | |
ImGuiIO &io = ImGui::GetIO(); | |
io.DisplaySize = ImVec2((float) w, (float) h); | |
io.DisplayFramebufferScale = ImVec2(1, 1); | |
io.Fonts->AddFontDefault(); | |
io.Fonts->Build(); | |
ImGui::StyleColorsDark(); | |
ImGui_ImplSDL2_InitForVulkan(window); | |
ImGui_ImplVulkan_Init(&initInfo, renderPass); | |
auto cb = ctx.CreateOneShotCommandBuffer(); | |
assert(ImGui_ImplVulkan_CreateFontsTexture(cb)); | |
ctx.SubmitOneShotCommandBuffer(cb); | |
ImGui_ImplVulkan_DestroyFontUploadObjects(); | |
// stupid workaround | |
ImGui_ImplVulkan_SetMinImageCount(ctx.imageCount); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
auto cb = ctx.CurrentCmdBuf(); | |
cb.nextSubpass(vk::SubpassContents::eInline); | |
cb.bindDescriptorSets(vk::PipelineBindPoint::eGraphics, postPipelineLayout, 0, 1, &postDescriptorSet, 0, nullptr); | |
cb.bindPipeline(vk::PipelineBindPoint::eGraphics, postPipeline); | |
cb.draw(3, 1, 0, 0); | |
// The stuff above is just to show you that this happens in the second subpass of my render pass which has one | |
// color attachment for output. | |
ImGui::Render(); | |
ImDrawData *dd = ImGui::GetDrawData(); | |
if (dd && dd->Valid && dd->DisplaySize.x > 0.0f && dd->DisplaySize.y > 0.0f) { | |
ImGui_ImplVulkan_RenderDrawData(dd, cb); | |
} | |
cb.endRenderPass(); | |
cb.end(); | |
// ctx.endFrame basically just submits: | |
ctx.EndFrame(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ImGui_ImplSDL2_NewFrame(window); | |
ImGui_ImplVulkan_NewFrame(); | |
ImGui::NewFrame(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment