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