imgui_impl_vulkan.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // ImGui Renderer for: Vulkan
  2. // This needs to be used along with a Platform Binding (e.g. GLFW, SDL, Win32, custom..)
  3. // Missing features:
  4. // [ ] Platform: Multi-viewport / platform windows.
  5. // [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914
  6. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
  7. // If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
  8. // https://github.com/ocornut/imgui
  9. // The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
  10. // IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
  11. #include <vulkan/vulkan.h>
  12. #define IMGUI_VK_QUEUED_FRAMES 2
  13. struct ImGui_ImplVulkan_InitInfo
  14. {
  15. VkInstance Instance;
  16. VkPhysicalDevice PhysicalDevice;
  17. VkDevice Device;
  18. uint32_t QueueFamily;
  19. VkQueue Queue;
  20. VkPipelineCache PipelineCache;
  21. VkDescriptorPool DescriptorPool;
  22. const VkAllocationCallbacks* Allocator;
  23. void (*CheckVkResultFn)(VkResult err);
  24. };
  25. // Called by user code
  26. IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass);
  27. IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
  28. IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
  29. IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer);
  30. IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer);
  31. IMGUI_IMPL_API void ImGui_ImplVulkan_InvalidateFontUploadObjects();
  32. // Called by ImGui_ImplVulkan_Init() might be useful elsewhere.
  33. IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateDeviceObjects();
  34. IMGUI_IMPL_API void ImGui_ImplVulkan_InvalidateDeviceObjects();
  35. //-------------------------------------------------------------------------
  36. // Internal / Miscellaneous Vulkan Helpers
  37. //-------------------------------------------------------------------------
  38. // You probably do NOT need to use or care about those functions.
  39. // Those functions only exist because:
  40. // 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
  41. // 2) the multi-viewport / platform window implementation needs them internally.
  42. // Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
  43. // but it is too much code to duplicate everywhere so we exceptionally expose them.
  44. // Your application/engine will likely already have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
  45. // You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
  46. // (those functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
  47. //-------------------------------------------------------------------------
  48. struct ImGui_ImplVulkanH_FrameData;
  49. struct ImGui_ImplVulkanH_WindowData;
  50. IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateWindowDataCommandBuffers(VkPhysicalDevice physical_device, VkDevice device, uint32_t queue_family, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator);
  51. IMGUI_IMPL_API void ImGui_ImplVulkanH_CreateWindowDataSwapChainAndFramebuffer(VkPhysicalDevice physical_device, VkDevice device, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator, int w, int h);
  52. IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindowData(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_WindowData* wd, const VkAllocationCallbacks* allocator);
  53. IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
  54. IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
  55. IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
  56. // Helper structure to hold the data needed by one rendering frame
  57. struct ImGui_ImplVulkanH_FrameData
  58. {
  59. uint32_t BackbufferIndex; // Keep track of recently rendered swapchain frame indices
  60. VkCommandPool CommandPool;
  61. VkCommandBuffer CommandBuffer;
  62. VkFence Fence;
  63. VkSemaphore ImageAcquiredSemaphore;
  64. VkSemaphore RenderCompleteSemaphore;
  65. IMGUI_IMPL_API ImGui_ImplVulkanH_FrameData();
  66. };
  67. // Helper structure to hold the data needed by one rendering context into one OS window
  68. struct ImGui_ImplVulkanH_WindowData
  69. {
  70. int Width;
  71. int Height;
  72. VkSwapchainKHR Swapchain;
  73. VkSurfaceKHR Surface;
  74. VkSurfaceFormatKHR SurfaceFormat;
  75. VkPresentModeKHR PresentMode;
  76. VkRenderPass RenderPass;
  77. bool ClearEnable;
  78. VkClearValue ClearValue;
  79. uint32_t BackBufferCount;
  80. VkImage BackBuffer[16];
  81. VkImageView BackBufferView[16];
  82. VkFramebuffer Framebuffer[16];
  83. uint32_t FrameIndex;
  84. ImGui_ImplVulkanH_FrameData Frames[IMGUI_VK_QUEUED_FRAMES];
  85. IMGUI_IMPL_API ImGui_ImplVulkanH_WindowData();
  86. };