source: opengl-game/IMGUI/imgui_impl_vulkan.h@ 6493e43

feature/imgui-sdl
Last change on this file since 6493e43 was 6493e43, checked in by Dmitry Portnoy <dportnoy@…>, 4 years ago

In sdl-game, add support for using separate graphics and present queues, and move the example ImGui code for (re)creating the swapchain into my own files

  • Property mode set to 100644
File size: 6.7 KB
Line 
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// Implemented features:
5// [X] Renderer: Support for large meshes (64k+ vertices) with 16-bit indices.
6// Missing features:
7// [ ] Renderer: User texture binding. Changes of ImTextureID aren't supported by this binding! See https://github.com/ocornut/imgui/pull/914
8
9// You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
10// If you are new to dear imgui, read examples/README.txt and read the documentation at the top of imgui.cpp.
11// https://github.com/ocornut/imgui
12
13// The aim of imgui_impl_vulkan.h/.cpp is to be usable in your engine without any modification.
14// IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
15
16// Important note to the reader who wish to integrate imgui_impl_vulkan.cpp/.h in their own engine/app.
17// - Common ImGui_ImplVulkan_XXX functions and structures are used to interface with imgui_impl_vulkan.cpp/.h.
18// You will use those if you want to use this rendering back-end in your engine/app.
19// - Helper ImGui_ImplVulkanH_XXX functions and structures are only used by this example (main.cpp) and by
20// the back-end itself (imgui_impl_vulkan.cpp), but should PROBABLY NOT be used by your own engine/app code.
21// Read comments in imgui_impl_vulkan.h.
22
23#pragma once
24#include "imgui.h" // IMGUI_IMPL_API
25#include <vulkan/vulkan.h>
26
27// Initialization data, for ImGui_ImplVulkan_Init()
28// [Please zero-clear before use!]
29struct ImGui_ImplVulkan_InitInfo
30{
31 VkInstance Instance;
32 VkPhysicalDevice PhysicalDevice;
33 VkDevice Device;
34 VkPipelineCache PipelineCache;
35 VkDescriptorPool DescriptorPool;
36 uint32_t MinImageCount; // >= 2
37 uint32_t ImageCount; // >= MinImageCount
38 VkSampleCountFlagBits MSAASamples; // >= VK_SAMPLE_COUNT_1_BIT
39 const VkAllocationCallbacks* Allocator;
40 void (*CheckVkResultFn)(VkResult err);
41};
42
43// Called by user code
44IMGUI_IMPL_API bool ImGui_ImplVulkan_Init(ImGui_ImplVulkan_InitInfo* info, VkRenderPass render_pass);
45IMGUI_IMPL_API void ImGui_ImplVulkan_Shutdown();
46IMGUI_IMPL_API void ImGui_ImplVulkan_NewFrame();
47IMGUI_IMPL_API void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer command_buffer, VkPipeline pipeline = VK_NULL_HANDLE);
48IMGUI_IMPL_API bool ImGui_ImplVulkan_CreateFontsTexture(VkCommandBuffer command_buffer);
49IMGUI_IMPL_API void ImGui_ImplVulkan_DestroyFontUploadObjects();
50IMGUI_IMPL_API void ImGui_ImplVulkan_SetMinImageCount(uint32_t min_image_count); // To override MinImageCount after initialization (e.g. if swap chain is recreated)
51
52
53//-------------------------------------------------------------------------
54// Internal / Miscellaneous Vulkan Helpers
55// (Used by example's main.cpp. Used by multi-viewport features. PROBABLY NOT used by your own engine/app.)
56//-------------------------------------------------------------------------
57// You probably do NOT need to use or care about those functions.
58// Those functions only exist because:
59// 1) they facilitate the readability and maintenance of the multiple main.cpp examples files.
60// 2) the upcoming multi-viewport feature will need them internally.
61// Generally we avoid exposing any kind of superfluous high-level helpers in the bindings,
62// but it is too much code to duplicate everywhere so we exceptionally expose them.
63//
64// Your engine/app will likely _already_ have code to setup all that stuff (swap chain, render pass, frame buffers, etc.).
65// You may read this code to learn about Vulkan, but it is recommended you use you own custom tailored code to do equivalent work.
66// (The ImGui_ImplVulkanH_XXX functions do not interact with any of the state used by the regular ImGui_ImplVulkan_XXX functions)
67//-------------------------------------------------------------------------
68
69struct ImGui_ImplVulkanH_Frame;
70struct ImGui_ImplVulkanH_Window;
71
72// Helpers
73IMGUI_IMPL_API void ImGui_ImplVulkanH_DestroyWindow(VkInstance instance, VkDevice device, ImGui_ImplVulkanH_Window* wnd, const VkAllocationCallbacks* allocator);
74IMGUI_IMPL_API VkSurfaceFormatKHR ImGui_ImplVulkanH_SelectSurfaceFormat(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkFormat* request_formats, int request_formats_count, VkColorSpaceKHR request_color_space);
75IMGUI_IMPL_API VkPresentModeKHR ImGui_ImplVulkanH_SelectPresentMode(VkPhysicalDevice physical_device, VkSurfaceKHR surface, const VkPresentModeKHR* request_modes, int request_modes_count);
76IMGUI_IMPL_API int ImGui_ImplVulkanH_GetMinImageCountFromPresentMode(VkPresentModeKHR present_mode);
77
78// Helper structure to hold the data needed by one rendering frame
79// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
80// [Please zero-clear before use!]
81struct ImGui_ImplVulkanH_Frame
82{
83 VkCommandPool CommandPool;
84 VkCommandBuffer CommandBuffer;
85 VkFence Fence;
86 VkImage Backbuffer;
87 VkImageView BackbufferView;
88 VkFramebuffer Framebuffer;
89};
90
91struct ImGui_ImplVulkanH_FrameSemaphores
92{
93 VkSemaphore ImageAcquiredSemaphore;
94 VkSemaphore RenderCompleteSemaphore;
95};
96
97// Helper structure to hold the data needed by one rendering context into one OS window
98// (Used by example's main.cpp. Used by multi-viewport features. Probably NOT used by your own engine/app.)
99struct ImGui_ImplVulkanH_Window
100{
101 int Width;
102 int Height;
103 VkSwapchainKHR Swapchain;
104 VkSurfaceKHR Surface;
105 VkSurfaceFormatKHR SurfaceFormat;
106 VkPresentModeKHR PresentMode;
107 VkRenderPass RenderPass;
108 VkPipeline Pipeline; // The window pipeline may uses a different VkRenderPass than the one passed in ImGui_ImplVulkan_InitInfo
109 bool ClearEnable;
110 VkClearValue ClearValue;
111 uint32_t FrameIndex; // Current frame being rendered to (0 <= FrameIndex < FrameInFlightCount)
112 uint32_t ImageCount; // Number of simultaneous in-flight frames (returned by vkGetSwapchainImagesKHR, usually derived from min_image_count)
113 uint32_t SemaphoreIndex; // Current set of swapchain wait semaphores we're using (needs to be distinct from per frame data)
114 ImGui_ImplVulkanH_Frame* Frames;
115 ImGui_ImplVulkanH_FrameSemaphores* FrameSemaphores;
116
117 ImGui_ImplVulkanH_Window()
118 {
119 memset(this, 0, sizeof(*this));
120 PresentMode = VK_PRESENT_MODE_MAX_ENUM_KHR;
121 ClearEnable = true;
122 }
123};
124
Note: See TracBrowser for help on using the repository browser.