// not needed yet -- add custom cpp functions first #include "cplusplus.h" #include "vksetup.h" #define VMA_DEBUG_INITIALIZE_ALLOCATIONS 1 #define VMA_STATIC_VULKAN_FUNCTIONS 0 #define VMA_DYNAMIC_VULKAN_FUNCTIONS 1 #define VMA_IMPLEMENTATION #include "vk_mem_alloc.h" #include #include #include static void check_vk_result(VkResult err) { if (err == 0) return; fprintf(stderr, "[vulkan] Error: VkResult = %d\n", err); if (err < 0) abort(); } void imgui_draw_cmd(VkCommandBuffer cmd) { ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd); } void imgui_draw() { ImGui::Render(); } void imgui_new_frame(vks_context vk) { ImGui_ImplVulkan_NewFrame(); ImGui_ImplSDL2_NewFrame(); ImGui::NewFrame(); ImGui::ShowDemoWindow(); ImGui::Text("dear imgui says hello! (%s) (%d)", IMGUI_VERSION, IMGUI_VERSION_NUM); } bool imgui_proc_event(SDL_Event* e) { return ImGui_ImplSDL2_ProcessEvent(e); } static VkDescriptorPool imguiPool; void init_imgui(vks_context *vk) { VkDescriptorPoolSize pool_sizes[] = { { VK_DESCRIPTOR_TYPE_SAMPLER, 1000 }, { VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1000 }, { VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 1000 }, { VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, 1000 }, { VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER, 1000 }, { VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER, 1000 }, { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1000 }, { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1000 }, { VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC, 1000 }, { VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC, 1000 }, { VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, 1000 } }; VkDescriptorPoolCreateInfo pool_info = {}; pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO; pool_info.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT; pool_info.maxSets = 1000; pool_info.poolSizeCount = std::size(pool_sizes); pool_info.pPoolSizes = pool_sizes; VK_CHECK(vkCreateDescriptorPool(vk->device, &pool_info, nullptr, &imguiPool)); IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO& io = ImGui::GetIO(); io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls ImGui_ImplSDL2_InitForVulkan(vk->window); ImGui_ImplVulkan_InitInfo init_info = {}; init_info.Instance = vk->instance; init_info.PhysicalDevice = vk->physical_device; init_info.Device = vk->device; //init_info.QueueFamily = ; init_info.Queue = vk->graphics_and_compute_queue; //init_info.PipelineCache = YOUR_PIPELINE_CACHE; init_info.DescriptorPool = imguiPool; init_info.Subpass = 0; init_info.MinImageCount = 2; init_info.ImageCount = 2; init_info.MSAASamples = vk->msaa_samples; init_info.CheckVkResultFn = check_vk_result; init_info.UseDynamicRendering = true; //init_info. init_info.PipelineRenderingCreateInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO_KHR; init_info.PipelineRenderingCreateInfo.colorAttachmentCount = 1; init_info.PipelineRenderingCreateInfo.pColorAttachmentFormats = &vk->swapchain.image_format; init_info.PipelineRenderingCreateInfo.depthAttachmentFormat = vks_find_depth_format(*vk); ImGui_ImplVulkan_Init(&init_info); // (this gets a bit more complicated, see example app for full reference) ImGui_ImplVulkan_CreateFontsTexture(); // (your code submit a queue) ImGui_ImplVulkan_DestroyFontsTexture(); } void imgui_destroy(vks_context vk) { ImGui_ImplVulkan_Shutdown(); vkDestroyDescriptorPool(vk.device, imguiPool, nullptr); }