Examples: Vulkan: Fixed tabs->space, removed extraneous braces and empty lines. (#2071)

This commit is contained in:
omar 2018-09-11 22:18:24 +02:00
parent b88a3b2711
commit c7eef99a33
4 changed files with 91 additions and 107 deletions

View File

@ -23,7 +23,7 @@
#define IMGUI_VULKAN_DEBUG_REPORT
#endif
static uint32_t g_MinImageCount = 2;
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;
@ -213,7 +213,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);
ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(g_PhysicalDevice, g_Device, g_QueueFamily, wd, g_Allocator);
}
static void CleanupVulkan()
@ -374,7 +374,7 @@ int main(int, char**)
init_info.DescriptorPool = g_DescriptorPool;
init_info.Allocator = g_Allocator;
init_info.CheckVkResultFn = check_vk_result;
init_info.QueuedFrames = wd->BackBufferCount;
init_info.QueuedFrames = wd->BackBufferCount;
ImGui_ImplVulkan_Init(&init_info, wd->RenderPass);
// Load Fonts
@ -435,14 +435,14 @@ 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)
{
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;
}
if (g_ResizeWanted)
{
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;
}
// Start the Dear ImGui frame
ImGui_ImplVulkan_NewFrame();
@ -484,26 +484,26 @@ int main(int, char**)
if (ImGui::Button("Close Me"))
show_another_window = false;
if (ImGui::Button("Increase"))
{
g_MinImageCount++;
g_ResizeWanted = true;
}
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();
if (ImGui::Button("Decrease"))
{
if (g_MinImageCount != 2)
{
g_MinImageCount--;
g_ResizeWanted = true;
}
}
ImGui::SameLine();
ImGui::Text("Back Buffers: %i", g_MinImageCount);
ImGui::SameLine();
ImGui::Text("Back Buffers: %i", g_MinImageCount);
ImGui::Text("Frame Index %i", wd->FrameIndex);
ImGui::Text("Frame Index %i", wd->FrameIndex);
ImGui::End();
}

View File

@ -15,8 +15,8 @@
#define IMGUI_VULKAN_DEBUG_REPORT
#endif
static uint32_t g_MinImageCount = 2;
static bool g_PendingSwapchainRebuild = false;
static uint32_t g_MinImageCount = 2;
static bool g_PendingSwapchainRebuild = false;
static VkAllocationCallbacks* g_Allocator = NULL;
static VkInstance g_Instance = VK_NULL_HANDLE;
static VkPhysicalDevice g_PhysicalDevice = VK_NULL_HANDLE;
@ -204,7 +204,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);
ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(g_PhysicalDevice, g_Device, g_QueueFamily, wd, g_Allocator);
}
static void CleanupVulkan()
@ -300,16 +300,11 @@ static void FramePresent(ImGui_ImplVulkanH_WindowData* wd)
static void RebuildSwapChain(int width, int height)
{
ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, width, height, 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_PendingSwapchainRebuild = false;
}
static void RebuildSwapChain()
{
RebuildSwapChain(g_WindowData.Width, g_WindowData.Height);
ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, width, height, 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_PendingSwapchainRebuild = false;
}
int main(int, char**)
@ -370,7 +365,7 @@ int main(int, char**)
init_info.PipelineCache = g_PipelineCache;
init_info.DescriptorPool = g_DescriptorPool;
init_info.Allocator = g_Allocator;
init_info.QueuedFrames = wd->BackBufferCount;
init_info.QueuedFrames = wd->BackBufferCount;
init_info.CheckVkResultFn = check_vk_result;
ImGui_ImplVulkan_Init(&init_info, wd->RenderPass);
@ -439,11 +434,11 @@ int main(int, char**)
if (event.type == SDL_QUIT)
done = true;
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_RESIZED && event.window.windowID == SDL_GetWindowID(window))
RebuildSwapChain((int)event.window.data1, (int)event.window.data2);
RebuildSwapChain((int)event.window.data1, (int)event.window.data2);
}
if (g_PendingSwapchainRebuild)
RebuildSwapChain();
if (g_PendingSwapchainRebuild)
RebuildSwapChain(g_WindowData.Width, g_WindowData.Height);
// Start the Dear ImGui frame
ImGui_ImplVulkan_NewFrame();
@ -485,26 +480,26 @@ int main(int, char**)
if (ImGui::Button("Close Me"))
show_another_window = false;
if (ImGui::Button("Increase"))
{
g_MinImageCount++;
g_PendingSwapchainRebuild = true;
}
if (ImGui::Button("Increase"))
{
g_MinImageCount++;
g_PendingSwapchainRebuild = true;
}
ImGui::SameLine();
if (ImGui::Button("Decrease"))
{
if (g_MinImageCount != 2)
{
g_MinImageCount--;
g_PendingSwapchainRebuild = true;
}
}
ImGui::SameLine();
if (ImGui::Button("Decrease"))
{
if (g_MinImageCount != 2)
{
g_MinImageCount--;
g_PendingSwapchainRebuild = true;
}
}
ImGui::SameLine();
ImGui::Text("Back Buffers: %i", g_MinImageCount);
ImGui::SameLine();
ImGui::Text("Back Buffers: %i", g_MinImageCount);
ImGui::Text("Frame Index %i", wd->FrameIndex);
ImGui::Text("Frame Index %i", wd->FrameIndex);
ImGui::End();
}

View File

@ -739,14 +739,14 @@ void ImGui_ImplVulkan_InvalidateDeviceObjects()
void ImGui_ImplVulkan_InvalidateFrameDeviceObjects()
{
for (int i = 0; i < g_FramesDataBuffers.size(); i++)
{
FrameDataForRender* fd = &g_FramesDataBuffers[i];
if (fd->VertexBuffer) { vkDestroyBuffer(g_Device, fd->VertexBuffer, g_Allocator); fd->VertexBuffer = VK_NULL_HANDLE; }
if (fd->VertexBufferMemory) { vkFreeMemory (g_Device, fd->VertexBufferMemory, g_Allocator); fd->VertexBufferMemory = VK_NULL_HANDLE; }
if (fd->IndexBuffer) { vkDestroyBuffer(g_Device, fd->IndexBuffer, g_Allocator); fd->IndexBuffer = VK_NULL_HANDLE; }
if (fd->IndexBufferMemory) { vkFreeMemory (g_Device, fd->IndexBufferMemory, g_Allocator); fd->IndexBufferMemory = VK_NULL_HANDLE; }
}
for (int i = 0; i < g_FramesDataBuffers.size(); i++)
{
FrameDataForRender* fd = &g_FramesDataBuffers[i];
if (fd->VertexBuffer) { vkDestroyBuffer(g_Device, fd->VertexBuffer, g_Allocator); fd->VertexBuffer = VK_NULL_HANDLE; }
if (fd->VertexBufferMemory) { vkFreeMemory (g_Device, fd->VertexBufferMemory, g_Allocator); fd->VertexBufferMemory = VK_NULL_HANDLE; }
if (fd->IndexBuffer) { vkDestroyBuffer(g_Device, fd->IndexBuffer, g_Allocator); fd->IndexBuffer = VK_NULL_HANDLE; }
if (fd->IndexBufferMemory) { vkFreeMemory (g_Device, fd->IndexBufferMemory, g_Allocator); fd->IndexBufferMemory = VK_NULL_HANDLE; }
}
}
bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass)
@ -771,11 +771,9 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend
g_DescriptorPool = info->DescriptorPool;
g_Allocator = info->Allocator;
g_CheckVkResultFn = info->CheckVkResultFn;
g_FramesDataBuffers.resize(info->QueuedFrames);
for (int i = 0; i < g_FramesDataBuffers.size(); i++)
{
g_FramesDataBuffers[i] = FrameDataForRender();
}
g_FramesDataBuffers.resize(info->QueuedFrames);
for (int i = 0; i < g_FramesDataBuffers.size(); i++)
g_FramesDataBuffers[i] = FrameDataForRender();
ImGui_ImplVulkan_CreateDeviceObjects();
@ -784,7 +782,7 @@ bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass rend
void ImGui_ImplVulkan_Shutdown()
{
ImGui_ImplVulkan_InvalidateFrameDeviceObjects();
ImGui_ImplVulkan_InvalidateFrameDeviceObjects();
ImGui_ImplVulkan_InvalidateDeviceObjects();
}
@ -794,20 +792,15 @@ void ImGui_ImplVulkan_NewFrame()
void ImGui_ImplVulkan_SetQueuedFramesCount(uint32_t count)
{
if (count == g_FramesDataBuffers.size())
{
return;
}
ImGui_ImplVulkan_InvalidateFrameDeviceObjects();
if (count == g_FramesDataBuffers.size())
return;
ImGui_ImplVulkan_InvalidateFrameDeviceObjects();
uint32_t old_size = g_FramesDataBuffers.size();
g_FramesDataBuffers.resize(count);
for (uint32_t i = old_size; i < count; i++)
{
g_FramesDataBuffers[i] = FrameDataForRender();
}
g_FrameIndex = 0;
uint32_t old_size = g_FramesDataBuffers.size();
g_FramesDataBuffers.resize(count);
for (uint32_t i = old_size; i < count; i++)
g_FramesDataBuffers[i] = FrameDataForRender();
g_FrameIndex = 0;
}
@ -1040,18 +1033,14 @@ void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice
err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->BackBufferCount, NULL);
check_vk_result(err);
err = vkGetSwapchainImagesKHR(device, wd->Swapchain, &wd->BackBufferCount, wd->BackBuffer);
check_vk_result(err);
check_vk_result(err);
for (uint32_t i = 0; i < wd->Frames.size(); i++)
{
ImGui_ImplVulkanH_DestroyFrameData(g_Instance, device, &wd->Frames[i], allocator);
}
uint32_t old_size = wd->Frames.size();
wd->Frames.resize(wd->BackBufferCount);
for (uint32_t i = 0; i < wd->Frames.size(); i++)
{
wd->Frames[i] = ImGui_ImplVulkanH_FrameData();
}
for (uint32_t i = 0; i < wd->Frames.size(); i++)
ImGui_ImplVulkanH_DestroyFrameData(g_Instance, device, &wd->Frames[i], allocator);
uint32_t old_size = wd->Frames.size();
wd->Frames.resize(wd->BackBufferCount);
for (uint32_t i = 0; i < wd->Frames.size(); i++)
wd->Frames[i] = ImGui_ImplVulkanH_FrameData();
}
if (old_swapchain)
vkDestroySwapchainKHR(device, old_swapchain, allocator);
@ -1141,7 +1130,7 @@ void ImGui_ImplVulkanH_DestroyWindowData(VkInstance instance, VkDevice device, I
for (int i = 0; i < wd->Frames.size(); i++)
{
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[i];
ImGui_ImplVulkanH_DestroyFrameData(instance, device, fd, allocator);
ImGui_ImplVulkanH_DestroyFrameData(instance, device, fd, allocator);
}
for (uint32_t i = 0; i < wd->BackBufferCount; i++)
{
@ -1156,9 +1145,9 @@ void ImGui_ImplVulkanH_DestroyWindowData(VkInstance instance, VkDevice device, I
void ImGui_ImplVulkanH_DestroyFrameData(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_FrameData* fd, const VkAllocationCallbacks* allocator)
{
vkDestroyFence(device, fd->Fence, allocator);
vkFreeCommandBuffers(device, fd->CommandPool, 1, &fd->CommandBuffer);
vkDestroyCommandPool(device, fd->CommandPool, allocator);
vkDestroySemaphore(device, fd->ImageAcquiredSemaphore, allocator);
vkDestroySemaphore(device, fd->RenderCompleteSemaphore, allocator);
vkDestroyFence(device, fd->Fence, allocator);
vkFreeCommandBuffers(device, fd->CommandPool, 1, &fd->CommandBuffer);
vkDestroyCommandPool(device, fd->CommandPool, allocator);
vkDestroySemaphore(device, fd->ImageAcquiredSemaphore, allocator);
vkDestroySemaphore(device, fd->RenderCompleteSemaphore, allocator);
}

View File

@ -27,7 +27,7 @@ struct ImGui_ImplVulkan_InitInfo
VkQueue Queue;
VkPipelineCache PipelineCache;
VkDescriptorPool DescriptorPool;
int QueuedFrames;
int QueuedFrames;
const VkAllocationCallbacks* Allocator;
void (*CheckVkResultFn)(VkResult err);
};