Examples: Vulkan: Updated Changelog, removed debug code, tweaked code, made GLFW/SDL match each others. Initialize FrameDataForRender fields. Added Assertion. Clearing fields on DestroyFrameData(). (#2071)

This commit is contained in:
omar
2019-04-03 15:48:22 +02:00
parent c7eef99a33
commit 317859a3da
5 changed files with 61 additions and 86 deletions

View File

@ -23,7 +23,6 @@
#define IMGUI_VULKAN_DEBUG_REPORT
#endif
static uint32_t g_MinImageCount = 2;
static VkAllocationCallbacks* g_Allocator = NULL;
static VkInstance g_Instance = VK_NULL_HANDLE;
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
@ -35,7 +34,8 @@ static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
static ImGui_ImplVulkanH_WindowData g_WindowData;
static bool g_ResizeWanted = false;
static int g_MinImageCount = 2;
static bool g_WantSwapChainRebuild = false;
static int g_ResizeWidth = 0, g_ResizeHeight = 0;
static void check_vk_result(VkResult err)
@ -214,6 +214,7 @@ static void SetupVulkanWindowData(ImGui_ImplVulkanH_WindowData* wd, VkSurfaceKHR
// Create SwapChain, RenderPass, Framebuffer, etc.
ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, wd, g_Allocator, width, height, g_MinImageCount);
ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(g_PhysicalDevice, g_Device, g_QueueFamily, wd, g_Allocator);
IM_ASSERT(wd->BackBufferCount > 0);
}
static void CleanupVulkan()
@ -314,7 +315,7 @@ static void glfw_error_callback(int error, const char* description)
static void glfw_resize_callback(GLFWwindow*, int w, int h)
{
g_ResizeWanted = true;
g_WantSwapChainRebuild = true;
g_ResizeWidth = w;
g_ResizeHeight = h;
}
@ -373,8 +374,8 @@ int main(int, char**)
init_info.PipelineCache = g_PipelineCache;
init_info.DescriptorPool = g_DescriptorPool;
init_info.Allocator = g_Allocator;
init_info.QueuedFramesCount = (int)wd->BackBufferCount;
init_info.CheckVkResultFn = check_vk_result;
init_info.QueuedFrames = wd->BackBufferCount;
ImGui_ImplVulkan_Init(&init_info, wd->RenderPass);
// Load Fonts
@ -435,13 +436,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_ResizeWanted)
if (g_WantSwapChainRebuild)
{
ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, g_ResizeWidth, g_ResizeHeight, g_MinImageCount);
ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(g_PhysicalDevice, g_Device, g_QueueFamily, &g_WindowData, g_Allocator);
ImGui_ImplVulkan_SetQueuedFramesCount(g_WindowData.BackBufferCount);
g_WindowData.FrameIndex = 0;
g_ResizeWanted = false;
g_WantSwapChainRebuild = false;
}
// Start the Dear ImGui frame
@ -483,28 +484,6 @@ int main(int, char**)
ImGui::Text("Hello from another window!");
if (ImGui::Button("Close Me"))
show_another_window = false;
if (ImGui::Button("Increase"))
{
g_MinImageCount++;
g_ResizeWanted = true;
}
ImGui::SameLine();
if (ImGui::Button("Decrease"))
{
if (g_MinImageCount != 2)
{
g_MinImageCount--;
g_ResizeWanted = true;
}
}
ImGui::SameLine();
ImGui::Text("Back Buffers: %i", g_MinImageCount);
ImGui::Text("Frame Index %i", wd->FrameIndex);
ImGui::End();
}