mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-04 12:08:47 +02:00
Vulkan: Renaming demo/helper structures. Tidying up examples main.cpp.
This commit is contained in:
@ -30,20 +30,21 @@
|
||||
#define IMGUI_VULKAN_DEBUG_REPORT
|
||||
#endif
|
||||
|
||||
static VkAllocationCallbacks* g_Allocator = NULL;
|
||||
static VkInstance g_Instance = VK_NULL_HANDLE;
|
||||
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
|
||||
static VkDevice g_Device = VK_NULL_HANDLE;
|
||||
static uint32_t g_QueueFamily = (uint32_t)-1;
|
||||
static VkQueue g_Queue = VK_NULL_HANDLE;
|
||||
static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
|
||||
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
||||
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
||||
static VkAllocationCallbacks* g_Allocator = NULL;
|
||||
static VkInstance g_Instance = VK_NULL_HANDLE;
|
||||
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
|
||||
static VkDevice g_Device = VK_NULL_HANDLE;
|
||||
static uint32_t g_QueueFamily = (uint32_t)-1;
|
||||
static VkQueue g_Queue = VK_NULL_HANDLE;
|
||||
static VkDebugReportCallbackEXT g_DebugReport = VK_NULL_HANDLE;
|
||||
static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
|
||||
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
|
||||
|
||||
static ImGui_ImplVulkanH_WindowData g_WindowData;
|
||||
static int g_MinImageCount = 2;
|
||||
static bool g_WantSwapChainRebuild = false;
|
||||
static int g_ResizeWidth = 0, g_ResizeHeight = 0;
|
||||
static ImGui_ImplVulkanH_Window g_WindowData;
|
||||
static int g_MinImageCount = 2;
|
||||
static bool g_SwapChainRebuild = false;
|
||||
static int g_SwapChainResizeWidth = 0;
|
||||
static int g_SwapChainResizeHeight = 0;
|
||||
|
||||
static void check_vk_result(VkResult err)
|
||||
{
|
||||
@ -192,7 +193,7 @@ static void SetupVulkan(const char** extensions, uint32_t extensions_count)
|
||||
}
|
||||
}
|
||||
|
||||
static void SetupVulkanWindow(ImGui_ImplVulkanH_WindowData* wd, VkSurfaceKHR surface, int width, int height)
|
||||
static void SetupVulkanWindow(ImGui_ImplVulkanH_Window* wd, VkSurfaceKHR surface, int width, int height)
|
||||
{
|
||||
wd->Surface = surface;
|
||||
|
||||
@ -220,8 +221,8 @@ static void SetupVulkanWindow(ImGui_ImplVulkanH_WindowData* wd, VkSurfaceKHR sur
|
||||
//printf("[vulkan] Selected PresentMode = %d\n", wd->PresentMode);
|
||||
|
||||
// Create SwapChain, RenderPass, Framebuffer, etc.
|
||||
ImGui_ImplVulkanH_CreateWindowData(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
|
||||
IM_ASSERT(wd->FramesQueueSize >= 2);
|
||||
IM_ASSERT(g_MinImageCount >= 2);
|
||||
ImGui_ImplVulkanH_CreateWindow(g_Instance, g_PhysicalDevice, g_Device, wd, g_QueueFamily, g_Allocator, width, height, g_MinImageCount);
|
||||
}
|
||||
|
||||
static void CleanupVulkan()
|
||||
@ -240,14 +241,14 @@ static void CleanupVulkan()
|
||||
|
||||
static void CleanupVulkanWindow()
|
||||
{
|
||||
// In a normal engine/app integration, you wouldn't use the ImGui_ImplVulkanH_WindowData helpers,
|
||||
// In a normal engine/app integration, you wouldn't use the ImGui_ImplVulkanH_Window helpers,
|
||||
// however you would instead need to call ImGui_ImplVulkan_DestroyFrameRenderBuffers() on each
|
||||
// ImGui_ImplVulkan_FrameRenderBuffers structure that you own.
|
||||
ImGui_ImplVulkanH_WindowData* wd = &g_WindowData;
|
||||
ImGui_ImplVulkanH_DestroyWindowData(g_Instance, g_Device, wd, g_Allocator);
|
||||
ImGui_ImplVulkanH_Window* wd = &g_WindowData;
|
||||
ImGui_ImplVulkanH_DestroyWindow(g_Instance, g_Device, wd, g_Allocator);
|
||||
}
|
||||
|
||||
static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
|
||||
static void FrameRender(ImGui_ImplVulkanH_Window* wd)
|
||||
{
|
||||
VkResult err;
|
||||
|
||||
@ -255,7 +256,7 @@ static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
|
||||
err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
|
||||
check_vk_result(err);
|
||||
|
||||
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
|
||||
ImGui_ImplVulkanH_Frame* fd = &wd->Frames[wd->FrameIndex];
|
||||
{
|
||||
err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
|
||||
check_vk_result(err);
|
||||
@ -308,9 +309,9 @@ static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
|
||||
}
|
||||
}
|
||||
|
||||
static void FramePresent(ImGui_ImplVulkanH_WindowData* wd)
|
||||
static void FramePresent(ImGui_ImplVulkanH_Window* wd)
|
||||
{
|
||||
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
|
||||
ImGui_ImplVulkanH_Frame* fd = &wd->Frames[wd->FrameIndex];
|
||||
VkPresentInfoKHR info = {};
|
||||
info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
|
||||
info.waitSemaphoreCount = 1;
|
||||
@ -329,14 +330,14 @@ static void glfw_error_callback(int error, const char* description)
|
||||
|
||||
static void glfw_resize_callback(GLFWwindow*, int w, int h)
|
||||
{
|
||||
g_WantSwapChainRebuild = true;
|
||||
g_ResizeWidth = w;
|
||||
g_ResizeHeight = h;
|
||||
g_SwapChainRebuild = true;
|
||||
g_SwapChainResizeWidth = w;
|
||||
g_SwapChainResizeHeight = h;
|
||||
}
|
||||
|
||||
int main(int, char**)
|
||||
{
|
||||
// Setup window
|
||||
// Setup GLFW window
|
||||
glfwSetErrorCallback(glfw_error_callback);
|
||||
if (!glfwInit())
|
||||
return 1;
|
||||
@ -363,7 +364,7 @@ int main(int, char**)
|
||||
int w, h;
|
||||
glfwGetFramebufferSize(window, &w, &h);
|
||||
glfwSetFramebufferSizeCallback(window, glfw_resize_callback);
|
||||
ImGui_ImplVulkanH_WindowData* wd = &g_WindowData;
|
||||
ImGui_ImplVulkanH_Window* wd = &g_WindowData;
|
||||
SetupVulkanWindow(wd, surface, w, h);
|
||||
|
||||
// Setup Dear ImGui context
|
||||
@ -450,12 +451,13 @@ int main(int, char**)
|
||||
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application.
|
||||
// Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
|
||||
glfwPollEvents();
|
||||
if (g_WantSwapChainRebuild)
|
||||
|
||||
if (g_SwapChainRebuild)
|
||||
{
|
||||
ImGui_ImplVulkanH_CreateWindowData(g_Instance, g_PhysicalDevice, g_Device, &g_WindowData, g_QueueFamily, g_Allocator, g_ResizeWidth, g_ResizeHeight, g_MinImageCount);
|
||||
g_SwapChainRebuild = false;
|
||||
ImGui_ImplVulkanH_CreateWindow(g_Instance, g_PhysicalDevice, g_Device, &g_WindowData, g_QueueFamily, g_Allocator, g_SwapChainResizeWidth, g_SwapChainResizeHeight, g_MinImageCount);
|
||||
ImGui_ImplVulkan_SetSwapChainMinImageCount(g_MinImageCount);
|
||||
g_WindowData.FrameIndex = 0;
|
||||
g_WantSwapChainRebuild = false;
|
||||
}
|
||||
|
||||
// Start the Dear ImGui frame
|
||||
|
Reference in New Issue
Block a user