Tabs to Spaces, comments.

docking
omar 6 years ago
parent cdb109f617
commit fc52364652

@ -233,77 +233,77 @@ static void CleanupVulkan()
static void FrameRender(ImGui_ImplVulkanH_WindowData* wd) static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
{ {
VkResult err; VkResult err;
VkSemaphore& image_acquired_semaphore = wd->Frames[wd->FrameIndex].ImageAcquiredSemaphore; VkSemaphore& image_acquired_semaphore = wd->Frames[wd->FrameIndex].ImageAcquiredSemaphore;
err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex); err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
check_vk_result(err); check_vk_result(err);
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex]; ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
{ {
err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
check_vk_result(err); check_vk_result(err);
err = vkResetFences(g_Device, 1, &fd->Fence); err = vkResetFences(g_Device, 1, &fd->Fence);
check_vk_result(err); check_vk_result(err);
} }
{ {
err = vkResetCommandPool(g_Device, fd->CommandPool, 0); err = vkResetCommandPool(g_Device, fd->CommandPool, 0);
check_vk_result(err); check_vk_result(err);
VkCommandBufferBeginInfo info = {}; VkCommandBufferBeginInfo info = {};
info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; info.flags |= VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT;
err = vkBeginCommandBuffer(fd->CommandBuffer, &info); err = vkBeginCommandBuffer(fd->CommandBuffer, &info);
check_vk_result(err); check_vk_result(err);
} }
{ {
VkRenderPassBeginInfo info = {}; VkRenderPassBeginInfo info = {};
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
info.renderPass = wd->RenderPass; info.renderPass = wd->RenderPass;
info.framebuffer = wd->Framebuffer[wd->FrameIndex]; info.framebuffer = wd->Framebuffer[wd->FrameIndex];
info.renderArea.extent.width = wd->Width; info.renderArea.extent.width = wd->Width;
info.renderArea.extent.height = wd->Height; info.renderArea.extent.height = wd->Height;
info.clearValueCount = 1; info.clearValueCount = 1;
info.pClearValues = &wd->ClearValue; info.pClearValues = &wd->ClearValue;
vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE); vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE);
} }
// Record Imgui Draw Data and draw funcs into command buffer // Record Imgui Draw Data and draw funcs into command buffer
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer);
// Submit command buffer // Submit command buffer
vkCmdEndRenderPass(fd->CommandBuffer); vkCmdEndRenderPass(fd->CommandBuffer);
{ {
VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkSubmitInfo info = {}; VkSubmitInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
info.waitSemaphoreCount = 1; info.waitSemaphoreCount = 1;
info.pWaitSemaphores = &image_acquired_semaphore; info.pWaitSemaphores = &image_acquired_semaphore;
info.pWaitDstStageMask = &wait_stage; info.pWaitDstStageMask = &wait_stage;
info.commandBufferCount = 1; info.commandBufferCount = 1;
info.pCommandBuffers = &fd->CommandBuffer; info.pCommandBuffers = &fd->CommandBuffer;
info.signalSemaphoreCount = 1; info.signalSemaphoreCount = 1;
info.pSignalSemaphores = &fd->RenderCompleteSemaphore; info.pSignalSemaphores = &fd->RenderCompleteSemaphore;
err = vkEndCommandBuffer(fd->CommandBuffer); err = vkEndCommandBuffer(fd->CommandBuffer);
check_vk_result(err); check_vk_result(err);
err = vkQueueSubmit(g_Queue, 1, &info, fd->Fence); err = vkQueueSubmit(g_Queue, 1, &info, fd->Fence);
check_vk_result(err); check_vk_result(err);
} }
} }
static void FramePresent(ImGui_ImplVulkanH_WindowData* wd) static void FramePresent(ImGui_ImplVulkanH_WindowData* wd)
{ {
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex]; ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
VkPresentInfoKHR info = {}; VkPresentInfoKHR info = {};
info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
info.waitSemaphoreCount = 1; info.waitSemaphoreCount = 1;
info.pWaitSemaphores = &fd->RenderCompleteSemaphore; info.pWaitSemaphores = &fd->RenderCompleteSemaphore;
info.swapchainCount = 1; info.swapchainCount = 1;
info.pSwapchains = &wd->Swapchain; info.pSwapchains = &wd->Swapchain;
info.pImageIndices = &wd->FrameIndex; info.pImageIndices = &wd->FrameIndex;
VkResult err = vkQueuePresentKHR(g_Queue, &info); VkResult err = vkQueuePresentKHR(g_Queue, &info);
check_vk_result(err); check_vk_result(err);
} }
static void glfw_error_callback(int error, const char* description) static void glfw_error_callback(int error, const char* description)
@ -315,12 +315,12 @@ static void glfw_resize_callback(GLFWwindow*, int w, int h)
{ {
g_ResizeWanted = true; g_ResizeWanted = true;
g_ResizeWidth = w; g_ResizeWidth = w;
g_ResizeHeight = h; g_ResizeHeight = h;
} }
int main(int, char**) int main(int, char**)
{ {
// Setup window // Setup window
glfwSetErrorCallback(glfw_error_callback); glfwSetErrorCallback(glfw_error_callback);
if (!glfwInit()) if (!glfwInit())
return 1; return 1;
@ -433,11 +433,11 @@ int main(int, char**)
// - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. // - 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. // Generally you may always pass all inputs to dear imgui, and hide them from your application based on those two flags.
glfwPollEvents(); glfwPollEvents();
if (g_ResizeWanted) if (g_ResizeWanted)
{ {
ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, g_ResizeWidth, g_ResizeHeight); ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(g_PhysicalDevice, g_Device, &g_WindowData, g_Allocator, g_ResizeWidth, g_ResizeHeight);
g_ResizeWanted = false; g_ResizeWanted = false;
} }
// Start the Dear ImGui frame // Start the Dear ImGui frame
ImGui_ImplVulkan_NewFrame(); ImGui_ImplVulkan_NewFrame();
@ -484,7 +484,7 @@ int main(int, char**)
// Rendering // Rendering
ImGui::Render(); ImGui::Render();
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float)); memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
FrameRender(wd); FrameRender(wd);
FramePresent(wd); FramePresent(wd);
} }

@ -223,18 +223,18 @@ static void CleanupVulkan()
static void FrameRender(ImGui_ImplVulkanH_WindowData* wd) static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
{ {
VkResult err; VkResult err;
VkSemaphore& image_acquired_semaphore = wd->Frames[wd->FrameIndex].ImageAcquiredSemaphore; VkSemaphore& image_acquired_semaphore = wd->Frames[wd->FrameIndex].ImageAcquiredSemaphore;
err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex); err = vkAcquireNextImageKHR(g_Device, wd->Swapchain, UINT64_MAX, image_acquired_semaphore, VK_NULL_HANDLE, &wd->FrameIndex);
check_vk_result(err); check_vk_result(err);
ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex]; ImGui_ImplVulkanH_FrameData* fd = &wd->Frames[wd->FrameIndex];
{ {
err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking err = vkWaitForFences(g_Device, 1, &fd->Fence, VK_TRUE, UINT64_MAX); // wait indefinitely instead of periodically checking
check_vk_result(err); check_vk_result(err);
err = vkResetFences(g_Device, 1, &fd->Fence); err = vkResetFences(g_Device, 1, &fd->Fence);
check_vk_result(err); check_vk_result(err);
} }
{ {
@ -250,7 +250,7 @@ static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
VkRenderPassBeginInfo info = {}; VkRenderPassBeginInfo info = {};
info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO; info.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
info.renderPass = wd->RenderPass; info.renderPass = wd->RenderPass;
info.framebuffer = wd->Framebuffer[wd->FrameIndex]; info.framebuffer = wd->Framebuffer[wd->FrameIndex];
info.renderArea.extent.width = wd->Width; info.renderArea.extent.width = wd->Width;
info.renderArea.extent.height = wd->Height; info.renderArea.extent.height = wd->Height;
info.clearValueCount = 1; info.clearValueCount = 1;
@ -258,17 +258,17 @@ static void FrameRender(ImGui_ImplVulkanH_WindowData* wd)
vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE); vkCmdBeginRenderPass(fd->CommandBuffer, &info, VK_SUBPASS_CONTENTS_INLINE);
} }
// Record Imgui Draw Data and draw funcs into command buffer // Record Imgui Draw Data and draw funcs into command buffer
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), fd->CommandBuffer);
// Submit command buffer // Submit command buffer
vkCmdEndRenderPass(fd->CommandBuffer); vkCmdEndRenderPass(fd->CommandBuffer);
{ {
VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT; VkPipelineStageFlags wait_stage = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkSubmitInfo info = {}; VkSubmitInfo info = {};
info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
info.waitSemaphoreCount = 1; info.waitSemaphoreCount = 1;
info.pWaitSemaphores = &image_acquired_semaphore; info.pWaitSemaphores = &image_acquired_semaphore;
info.pWaitDstStageMask = &wait_stage; info.pWaitDstStageMask = &wait_stage;
info.commandBufferCount = 1; info.commandBufferCount = 1;
info.pCommandBuffers = &fd->CommandBuffer; info.pCommandBuffers = &fd->CommandBuffer;
@ -291,8 +291,8 @@ static void FramePresent(ImGui_ImplVulkanH_WindowData* wd)
info.pWaitSemaphores = &fd->RenderCompleteSemaphore; info.pWaitSemaphores = &fd->RenderCompleteSemaphore;
info.swapchainCount = 1; info.swapchainCount = 1;
info.pSwapchains = &wd->Swapchain; info.pSwapchains = &wd->Swapchain;
info.pImageIndices = &wd->FrameIndex; info.pImageIndices = &wd->FrameIndex;
VkResult err = vkQueuePresentKHR(g_Queue, &info); VkResult err = vkQueuePresentKHR(g_Queue, &info);
check_vk_result(err); check_vk_result(err);
} }
@ -470,7 +470,7 @@ int main(int, char**)
// Rendering // Rendering
ImGui::Render(); ImGui::Render();
memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float)); memcpy(&wd->ClearValue.color.float32[0], &clear_color, 4 * sizeof(float));
FrameRender(wd); FrameRender(wd);
FramePresent(wd); FramePresent(wd);
} }

@ -18,7 +18,7 @@
#include "imgui_impl_metal.h" #include "imgui_impl_metal.h"
#import <Metal/Metal.h> #import <Metal/Metal.h>
// #import <QuartzCore/CAMetalLayer.h> // Not suported in XCode 9.2. Maybe a macro to detect the SDK version can be used (something like #if MACOS_SDK >= 10.13 ...) // #import <QuartzCore/CAMetalLayer.h> // Not supported in XCode 9.2. Maybe a macro to detect the SDK version can be used (something like #if MACOS_SDK >= 10.13 ...)
#import <simd/simd.h> #import <simd/simd.h>
#pragma mark - Support classes #pragma mark - Support classes

@ -946,7 +946,7 @@ int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_m
void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator, int w, int h) void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator, int w, int h)
{ {
uint32_t min_image_count = 2; // FIXME: this should become a function parameter uint32_t min_image_count = 2; // FIXME: this should become a function parameter
VkResult err; VkResult err;
VkSwapchainKHR old_swapchain = wd->Swapchain; VkSwapchainKHR old_swapchain = wd->Swapchain;
@ -974,7 +974,7 @@ void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice
VkSwapchainCreateInfoKHR info = {}; VkSwapchainCreateInfoKHR info = {};
info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR; info.sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR;
info.surface = wd->Surface; info.surface = wd->Surface;
info.minImageCount = min_image_count; info.minImageCount = min_image_count;
info.imageFormat = wd->SurfaceFormat.format; info.imageFormat = wd->SurfaceFormat.format;
info.imageColorSpace = wd->SurfaceFormat.colorSpace; info.imageColorSpace = wd->SurfaceFormat.colorSpace;
info.imageArrayLayers = 1; info.imageArrayLayers = 1;
@ -989,9 +989,9 @@ void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice
err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, wd->Surface, &cap); err = vkGetPhysicalDeviceSurfaceCapabilitiesKHR(physical_device, wd->Surface, &cap);
check_vk_result(err); check_vk_result(err);
if (info.minImageCount < cap.minImageCount) if (info.minImageCount < cap.minImageCount)
info.minImageCount = cap.minImageCount; info.minImageCount = cap.minImageCount;
else if (cap.maxImageCount != 0 && info.minImageCount > cap.maxImageCount) else if (cap.maxImageCount != 0 && info.minImageCount > cap.maxImageCount)
info.minImageCount = cap.maxImageCount; info.minImageCount = cap.maxImageCount;
if (cap.currentExtent.width == 0xffffffff) if (cap.currentExtent.width == 0xffffffff)
{ {

@ -46,6 +46,7 @@ IMGUI_IMPL_API void ImGui_ImplVulkan_InvalidateDeviceObjects();
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// Internal / Miscellaneous Vulkan Helpers // Internal / Miscellaneous Vulkan Helpers
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own app.)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
// You probably do NOT need to use or care about those functions. // You probably do NOT need to use or care about those functions.
// Those functions only exist because: // Those functions only exist because:
@ -69,6 +70,7 @@ IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysic
IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode); IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
// Helper structure to hold the data needed by one rendering frame // Helper structure to hold the data needed by one rendering frame
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own app.)
struct ImGui_ImplVulkanH_FrameData struct ImGui_ImplVulkanH_FrameData
{ {
uint32_t BackbufferIndex; // Keep track of recently rendered swapchain frame indices uint32_t BackbufferIndex; // Keep track of recently rendered swapchain frame indices
@ -82,6 +84,7 @@ struct ImGui_ImplVulkanH_FrameData
}; };
// Helper structure to hold the data needed by one rendering context into one OS window // Helper structure to hold the data needed by one rendering context into one OS window
// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own app.)
struct ImGui_ImplVulkanH_WindowData struct ImGui_ImplVulkanH_WindowData
{ {
int Width; int Width;

@ -1333,7 +1333,7 @@ const char* ImStrchrRange(const char* str, const char* str_end, char c)
int ImStrlenW(const ImWchar* str) int ImStrlenW(const ImWchar* str)
{ {
//return (int)wcslen((const wchar_t*)str); // FIXME-OPT: Could use this when wchar_t are 16-bits //return (int)wcslen((const wchar_t*)str); // FIXME-OPT: Could use this when wchar_t are 16-bits
int n = 0; int n = 0;
while (*str++) n++; while (*str++) n++;
return n; return n;

Loading…
Cancel
Save