Engine
Frameworkcreatedbymeusableforthecreationofsimplegames.CurrentlysupportsOpenGL(Verysimple)andVulkan.
imgui_impl_glfw_vulkan.cpp
Go to the documentation of this file.
1 // ImGui GLFW binding with Vulkan + shaders
2 // FIXME: Changes of ImTextureID aren't supported by this binding! Please, someone add it!
3 
4 // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
5 // If you use this binding you'll need to call 5 functions: ImGui_ImplXXXX_Init(), ImGui_ImplXXX_CreateFontsTexture(), ImGui_ImplXXXX_NewFrame(), ImGui_ImplXXXX_Render() and ImGui_ImplXXXX_Shutdown().
6 // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
7 // https://github.com/ocornut/imgui
8 
10 #ifdef USING_VULKAN
11 
12 #include "IMGUI/imgui.h"
13 
14 #include "Engine/engine.hpp"
16 #include "imgui_impl_glfw_vulkan.h"
17 
18 // GLFW Data
19 static GLFWwindow* g_Window = NULL;
20 static double g_Time = 0.0f;
21 
22 // Vulkan Data
23 static VkAllocationCallbacks* g_Allocator = NULL;
24 static VkPhysicalDevice g_Gpu = VK_NULL_HANDLE;
25 static VkDevice g_Device = VK_NULL_HANDLE;
26 static VkRenderPass g_RenderPass = VK_NULL_HANDLE;
27 static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
28 static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
29 static void(*g_CheckVkResult)(VkResult err) = NULL;
30 
31 static VkCommandBuffer g_CommandBuffer = VK_NULL_HANDLE;
32 static size_t g_BufferMemoryAlignment = 256;
33 static VkPipelineCreateFlags g_PipelineCreateFlags = 0;
34 static int g_FrameIndex = 0;
35 
36 static VkDescriptorSetLayout g_DescriptorSetLayout = VK_NULL_HANDLE;
37 static VkPipelineLayout g_PipelineLayout = VK_NULL_HANDLE;
38 static VkDescriptorSet g_DescriptorSet = VK_NULL_HANDLE;
39 static VkPipeline g_Pipeline = VK_NULL_HANDLE;
40 
41 static VkSampler g_FontSampler = VK_NULL_HANDLE;
42 static VkDeviceMemory g_FontMemory = VK_NULL_HANDLE;
43 static VkImage g_FontImage = VK_NULL_HANDLE;
44 static VkImageView g_FontView = VK_NULL_HANDLE;
45 
46 static VkDeviceMemory g_VertexBufferMemory[IMGUI_VK_QUEUED_FRAMES] = {};
47 static VkDeviceMemory g_IndexBufferMemory[IMGUI_VK_QUEUED_FRAMES] = {};
48 static size_t g_VertexBufferSize[IMGUI_VK_QUEUED_FRAMES] = {};
49 static size_t g_IndexBufferSize[IMGUI_VK_QUEUED_FRAMES] = {};
50 static VkBuffer g_VertexBuffer[IMGUI_VK_QUEUED_FRAMES] = {};
51 static VkBuffer g_IndexBuffer[IMGUI_VK_QUEUED_FRAMES] = {};
52 
53 static VkDeviceMemory g_UploadBufferMemory = VK_NULL_HANDLE;
54 static VkBuffer g_UploadBuffer = VK_NULL_HANDLE;
55 
56 static uint32_t __glsl_shader_vert_spv[] =
57 {
58  0x07230203,0x00010000,0x00080001,0x0000002e,0x00000000,0x00020011,0x00000001,0x0006000b,
59  0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
60  0x000a000f,0x00000000,0x00000004,0x6e69616d,0x00000000,0x0000000b,0x0000000f,0x00000015,
61  0x0000001b,0x0000001c,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
62  0x00000000,0x00030005,0x00000009,0x00000000,0x00050006,0x00000009,0x00000000,0x6f6c6f43,
63  0x00000072,0x00040006,0x00000009,0x00000001,0x00005655,0x00030005,0x0000000b,0x0074754f,
64  0x00040005,0x0000000f,0x6c6f4361,0x0000726f,0x00030005,0x00000015,0x00565561,0x00060005,
65  0x00000019,0x505f6c67,0x65567265,0x78657472,0x00000000,0x00060006,0x00000019,0x00000000,
66  0x505f6c67,0x7469736f,0x006e6f69,0x00030005,0x0000001b,0x00000000,0x00040005,0x0000001c,
67  0x736f5061,0x00000000,0x00060005,0x0000001e,0x73755075,0x6e6f4368,0x6e617473,0x00000074,
68  0x00050006,0x0000001e,0x00000000,0x61635375,0x0000656c,0x00060006,0x0000001e,0x00000001,
69  0x61725475,0x616c736e,0x00006574,0x00030005,0x00000020,0x00006370,0x00040047,0x0000000b,
70  0x0000001e,0x00000000,0x00040047,0x0000000f,0x0000001e,0x00000002,0x00040047,0x00000015,
71  0x0000001e,0x00000001,0x00050048,0x00000019,0x00000000,0x0000000b,0x00000000,0x00030047,
72  0x00000019,0x00000002,0x00040047,0x0000001c,0x0000001e,0x00000000,0x00050048,0x0000001e,
73  0x00000000,0x00000023,0x00000000,0x00050048,0x0000001e,0x00000001,0x00000023,0x00000008,
74  0x00030047,0x0000001e,0x00000002,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,
75  0x00030016,0x00000006,0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040017,
76  0x00000008,0x00000006,0x00000002,0x0004001e,0x00000009,0x00000007,0x00000008,0x00040020,
77  0x0000000a,0x00000003,0x00000009,0x0004003b,0x0000000a,0x0000000b,0x00000003,0x00040015,
78  0x0000000c,0x00000020,0x00000001,0x0004002b,0x0000000c,0x0000000d,0x00000000,0x00040020,
79  0x0000000e,0x00000001,0x00000007,0x0004003b,0x0000000e,0x0000000f,0x00000001,0x00040020,
80  0x00000011,0x00000003,0x00000007,0x0004002b,0x0000000c,0x00000013,0x00000001,0x00040020,
81  0x00000014,0x00000001,0x00000008,0x0004003b,0x00000014,0x00000015,0x00000001,0x00040020,
82  0x00000017,0x00000003,0x00000008,0x0003001e,0x00000019,0x00000007,0x00040020,0x0000001a,
83  0x00000003,0x00000019,0x0004003b,0x0000001a,0x0000001b,0x00000003,0x0004003b,0x00000014,
84  0x0000001c,0x00000001,0x0004001e,0x0000001e,0x00000008,0x00000008,0x00040020,0x0000001f,
85  0x00000009,0x0000001e,0x0004003b,0x0000001f,0x00000020,0x00000009,0x00040020,0x00000021,
86  0x00000009,0x00000008,0x0004002b,0x00000006,0x00000028,0x00000000,0x0004002b,0x00000006,
87  0x00000029,0x3f800000,0x00050036,0x00000002,0x00000004,0x00000000,0x00000003,0x000200f8,
88  0x00000005,0x0004003d,0x00000007,0x00000010,0x0000000f,0x00050041,0x00000011,0x00000012,
89  0x0000000b,0x0000000d,0x0003003e,0x00000012,0x00000010,0x0004003d,0x00000008,0x00000016,
90  0x00000015,0x00050041,0x00000017,0x00000018,0x0000000b,0x00000013,0x0003003e,0x00000018,
91  0x00000016,0x0004003d,0x00000008,0x0000001d,0x0000001c,0x00050041,0x00000021,0x00000022,
92  0x00000020,0x0000000d,0x0004003d,0x00000008,0x00000023,0x00000022,0x00050085,0x00000008,
93  0x00000024,0x0000001d,0x00000023,0x00050041,0x00000021,0x00000025,0x00000020,0x00000013,
94  0x0004003d,0x00000008,0x00000026,0x00000025,0x00050081,0x00000008,0x00000027,0x00000024,
95  0x00000026,0x00050051,0x00000006,0x0000002a,0x00000027,0x00000000,0x00050051,0x00000006,
96  0x0000002b,0x00000027,0x00000001,0x00070050,0x00000007,0x0000002c,0x0000002a,0x0000002b,
97  0x00000028,0x00000029,0x00050041,0x00000011,0x0000002d,0x0000001b,0x0000000d,0x0003003e,
98  0x0000002d,0x0000002c,0x000100fd,0x00010038
99 };
100 
101 static uint32_t __glsl_shader_frag_spv[] =
102 {
103  0x07230203,0x00010000,0x00080001,0x0000001e,0x00000000,0x00020011,0x00000001,0x0006000b,
104  0x00000001,0x4c534c47,0x6474732e,0x3035342e,0x00000000,0x0003000e,0x00000000,0x00000001,
105  0x0007000f,0x00000004,0x00000004,0x6e69616d,0x00000000,0x00000009,0x0000000d,0x00030010,
106  0x00000004,0x00000007,0x00030003,0x00000002,0x000001c2,0x00040005,0x00000004,0x6e69616d,
107  0x00000000,0x00040005,0x00000009,0x6c6f4366,0x0000726f,0x00030005,0x0000000b,0x00000000,
108  0x00050006,0x0000000b,0x00000000,0x6f6c6f43,0x00000072,0x00040006,0x0000000b,0x00000001,
109  0x00005655,0x00030005,0x0000000d,0x00006e49,0x00050005,0x00000016,0x78655473,0x65727574,
110  0x00000000,0x00040047,0x00000009,0x0000001e,0x00000000,0x00040047,0x0000000d,0x0000001e,
111  0x00000000,0x00040047,0x00000016,0x00000022,0x00000000,0x00040047,0x00000016,0x00000021,
112  0x00000000,0x00020013,0x00000002,0x00030021,0x00000003,0x00000002,0x00030016,0x00000006,
113  0x00000020,0x00040017,0x00000007,0x00000006,0x00000004,0x00040020,0x00000008,0x00000003,
114  0x00000007,0x0004003b,0x00000008,0x00000009,0x00000003,0x00040017,0x0000000a,0x00000006,
115  0x00000002,0x0004001e,0x0000000b,0x00000007,0x0000000a,0x00040020,0x0000000c,0x00000001,
116  0x0000000b,0x0004003b,0x0000000c,0x0000000d,0x00000001,0x00040015,0x0000000e,0x00000020,
117  0x00000001,0x0004002b,0x0000000e,0x0000000f,0x00000000,0x00040020,0x00000010,0x00000001,
118  0x00000007,0x00090019,0x00000013,0x00000006,0x00000001,0x00000000,0x00000000,0x00000000,
119  0x00000001,0x00000000,0x0003001b,0x00000014,0x00000013,0x00040020,0x00000015,0x00000000,
120  0x00000014,0x0004003b,0x00000015,0x00000016,0x00000000,0x0004002b,0x0000000e,0x00000018,
121  0x00000001,0x00040020,0x00000019,0x00000001,0x0000000a,0x00050036,0x00000002,0x00000004,
122  0x00000000,0x00000003,0x000200f8,0x00000005,0x00050041,0x00000010,0x00000011,0x0000000d,
123  0x0000000f,0x0004003d,0x00000007,0x00000012,0x00000011,0x0004003d,0x00000014,0x00000017,
124  0x00000016,0x00050041,0x00000019,0x0000001a,0x0000000d,0x00000018,0x0004003d,0x0000000a,
125  0x0000001b,0x0000001a,0x00050057,0x00000007,0x0000001c,0x00000017,0x0000001b,0x00050085,
126  0x00000007,0x0000001d,0x00000012,0x0000001c,0x0003003e,0x00000009,0x0000001d,0x000100fd,
127  0x00010038
128 };
129 
130 static uint32_t ImGui_ImplGlfwVulkan_MemoryType(VkMemoryPropertyFlags properties, uint32_t type_bits)
131 {
132  VkPhysicalDeviceMemoryProperties prop;
133  vkGetPhysicalDeviceMemoryProperties(g_Gpu, &prop);
134  for (uint32_t i = 0; i < prop.memoryTypeCount; i++)
135  if ((prop.memoryTypes[i].propertyFlags & properties) == properties && type_bits & (1 << i))
136  return i;
137  return 0xffffffff; // Unable to find memoryType
138 }
139 
140 static void ImGui_ImplGlfwVulkan_VkResult(VkResult err)
141 {
142  if (g_CheckVkResult)
143  g_CheckVkResult(err);
144 }
145 
146 // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
147 void ImGui_ImplGlfwVulkan_RenderDrawLists(ImDrawData* draw_data)
148 {
149  VkResult err;
150  ImGuiIO& io = ImGui::GetIO();
151 
152  // Create the Vertex Buffer:
153  size_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
154  if (!g_VertexBuffer[g_FrameIndex] || g_VertexBufferSize[g_FrameIndex] < vertex_size)
155  {
156  if (g_VertexBuffer[g_FrameIndex])
157  vkDestroyBuffer(g_Device, g_VertexBuffer[g_FrameIndex], g_Allocator);
158  if (g_VertexBufferMemory[g_FrameIndex])
159  vkFreeMemory(g_Device, g_VertexBufferMemory[g_FrameIndex], g_Allocator);
160  size_t vertex_buffer_size = ((vertex_size - 1) / g_BufferMemoryAlignment + 1) * g_BufferMemoryAlignment;
161  VkBufferCreateInfo buffer_info = {};
162  buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
163  buffer_info.size = vertex_buffer_size;
164  buffer_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
165  buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
166  err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_VertexBuffer[g_FrameIndex]);
167  ImGui_ImplGlfwVulkan_VkResult(err);
168  VkMemoryRequirements req;
169  vkGetBufferMemoryRequirements(g_Device, g_VertexBuffer[g_FrameIndex], &req);
170  g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment;
171  VkMemoryAllocateInfo alloc_info = {};
172  alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
173  alloc_info.allocationSize = req.size;
174  alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
175  err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_VertexBufferMemory[g_FrameIndex]);
176  ImGui_ImplGlfwVulkan_VkResult(err);
177  err = vkBindBufferMemory(g_Device, g_VertexBuffer[g_FrameIndex], g_VertexBufferMemory[g_FrameIndex], 0);
178  ImGui_ImplGlfwVulkan_VkResult(err);
179  g_VertexBufferSize[g_FrameIndex] = vertex_buffer_size;
180  }
181 
182  // Create the Index Buffer:
183  size_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx);
184  if (!g_IndexBuffer[g_FrameIndex] || g_IndexBufferSize[g_FrameIndex] < index_size)
185  {
186  if (g_IndexBuffer[g_FrameIndex])
187  vkDestroyBuffer(g_Device, g_IndexBuffer[g_FrameIndex], g_Allocator);
188  if (g_IndexBufferMemory[g_FrameIndex])
189  vkFreeMemory(g_Device, g_IndexBufferMemory[g_FrameIndex], g_Allocator);
190  size_t index_buffer_size = ((index_size - 1) / g_BufferMemoryAlignment + 1) * g_BufferMemoryAlignment;
191  VkBufferCreateInfo buffer_info = {};
192  buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
193  buffer_info.size = index_buffer_size;
194  buffer_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
195  buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
196  err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_IndexBuffer[g_FrameIndex]);
197  ImGui_ImplGlfwVulkan_VkResult(err);
198  VkMemoryRequirements req;
199  vkGetBufferMemoryRequirements(g_Device, g_IndexBuffer[g_FrameIndex], &req);
200  g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment;
201  VkMemoryAllocateInfo alloc_info = {};
202  alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
203  alloc_info.allocationSize = req.size;
204  alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
205  err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_IndexBufferMemory[g_FrameIndex]);
206  ImGui_ImplGlfwVulkan_VkResult(err);
207  err = vkBindBufferMemory(g_Device, g_IndexBuffer[g_FrameIndex], g_IndexBufferMemory[g_FrameIndex], 0);
208  ImGui_ImplGlfwVulkan_VkResult(err);
209  g_IndexBufferSize[g_FrameIndex] = index_buffer_size;
210  }
211 
212  // Upload Vertex and index Data:
213  {
214  ImDrawVert* vtx_dst;
215  ImDrawIdx* idx_dst;
216  err = vkMapMemory(g_Device, g_VertexBufferMemory[g_FrameIndex], 0, vertex_size, 0, (void**)(&vtx_dst));
217  ImGui_ImplGlfwVulkan_VkResult(err);
218  err = vkMapMemory(g_Device, g_IndexBufferMemory[g_FrameIndex], 0, index_size, 0, (void**)(&idx_dst));
219  ImGui_ImplGlfwVulkan_VkResult(err);
220  for (int n = 0; n < draw_data->CmdListsCount; n++)
221  {
222  const ImDrawList* cmd_list = draw_data->CmdLists[n];
223  memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
224  memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
225  vtx_dst += cmd_list->VtxBuffer.Size;
226  idx_dst += cmd_list->IdxBuffer.Size;
227  }
228  VkMappedMemoryRange range[2] = {};
229  range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
230  range[0].memory = g_VertexBufferMemory[g_FrameIndex];
231  range[0].size = VK_WHOLE_SIZE;
232  range[1].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
233  range[1].memory = g_IndexBufferMemory[g_FrameIndex];
234  range[1].size = VK_WHOLE_SIZE;
235  err = vkFlushMappedMemoryRanges(g_Device, 2, range);
236  ImGui_ImplGlfwVulkan_VkResult(err);
237  vkUnmapMemory(g_Device, g_VertexBufferMemory[g_FrameIndex]);
238  vkUnmapMemory(g_Device, g_IndexBufferMemory[g_FrameIndex]);
239  }
240 
241  // Bind pipeline and descriptor sets:
242  {
243  vkCmdBindPipeline(g_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Pipeline);
244  VkDescriptorSet desc_set[1] = { g_DescriptorSet };
245  vkCmdBindDescriptorSets(g_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_PipelineLayout, 0, 1, desc_set, 0, NULL);
246  }
247 
248  // Bind Vertex And Index Buffer:
249  {
250  VkBuffer vertex_buffers[1] = { g_VertexBuffer[g_FrameIndex] };
251  VkDeviceSize vertex_offset[1] = { 0 };
252  vkCmdBindVertexBuffers(g_CommandBuffer, 0, 1, vertex_buffers, vertex_offset);
253  vkCmdBindIndexBuffer(g_CommandBuffer, g_IndexBuffer[g_FrameIndex], 0, VK_INDEX_TYPE_UINT16);
254  }
255 
256  // Setup viewport:
257  {
258  VkViewport viewport;
259  viewport.x = 0;
260  viewport.y = 0;
261  viewport.width = ImGui::GetIO().DisplaySize.x;
262  viewport.height = ImGui::GetIO().DisplaySize.y;
263  viewport.minDepth = 0.0f;
264  viewport.maxDepth = 1.0f;
265  vkCmdSetViewport(g_CommandBuffer, 0, 1, &viewport);
266  }
267 
268  // Setup scale and translation:
269  {
270  float scale[2];
271  scale[0] = 2.0f / io.DisplaySize.x;
272  scale[1] = 2.0f / io.DisplaySize.y;
273  float translate[2];
274  translate[0] = -1.0f;
275  translate[1] = -1.0f;
276  vkCmdPushConstants(g_CommandBuffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 0, sizeof(float) * 2, scale);
277  vkCmdPushConstants(g_CommandBuffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 2, sizeof(float) * 2, translate);
278  }
279 
280  // Render the command lists:
281  int vtx_offset = 0;
282  int idx_offset = 0;
283  for (int n = 0; n < draw_data->CmdListsCount; n++)
284  {
285  const ImDrawList* cmd_list = draw_data->CmdLists[n];
286  for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
287  {
288  const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
289  if (pcmd->UserCallback)
290  {
291  pcmd->UserCallback(cmd_list, pcmd);
292  }
293  else
294  {
295  VkRect2D scissor;
296  scissor.offset.x = (int32_t)(pcmd->ClipRect.x) > 0 ? (int32_t)(pcmd->ClipRect.x) : 0;
297  scissor.offset.y = (int32_t)(pcmd->ClipRect.y) > 0 ? (int32_t)(pcmd->ClipRect.y) : 0;
298  scissor.extent.width = (uint32_t)(pcmd->ClipRect.z - pcmd->ClipRect.x);
299  scissor.extent.height = (uint32_t)(pcmd->ClipRect.w - pcmd->ClipRect.y + 1); // FIXME: Why +1 here?
300  vkCmdSetScissor(g_CommandBuffer, 0, 1, &scissor);
301  vkCmdDrawIndexed(g_CommandBuffer, pcmd->ElemCount, 1, idx_offset, vtx_offset, 0);
302  }
303  idx_offset += pcmd->ElemCount;
304  }
305  vtx_offset += cmd_list->VtxBuffer.Size;
306  }
307 }
308 
309 static const char* ImGui_ImplGlfwVulkan_GetClipboardText(void* user_data)
310 {
311  return glfwGetClipboardString((GLFWwindow*)user_data);
312 }
313 
314 static void ImGui_ImplGlfwVulkan_SetClipboardText(void* user_data, const char* text)
315 {
316  glfwSetClipboardString((GLFWwindow*)user_data, text);
317 }
318 
319 bool ImGui_ImplGlfwVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
320 {
321  ImGuiIO& io = ImGui::GetIO();
322 
323  unsigned char* pixels;
324  int width, height;
325  io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
326  size_t upload_size = width*height * 4 * sizeof(char);
327 
328  VkResult err;
329 
330  // Create the Image:
331  {
332  VkImageCreateInfo info = {};
333  info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
334  info.imageType = VK_IMAGE_TYPE_2D;
335  info.format = VK_FORMAT_R8G8B8A8_UNORM;
336  info.extent.width = width;
337  info.extent.height = height;
338  info.extent.depth = 1;
339  info.mipLevels = 1;
340  info.arrayLayers = 1;
341  info.samples = VK_SAMPLE_COUNT_1_BIT;
342  info.tiling = VK_IMAGE_TILING_OPTIMAL;
343  info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
344  info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
345  info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
346  err = vkCreateImage(g_Device, &info, g_Allocator, &g_FontImage);
347  ImGui_ImplGlfwVulkan_VkResult(err);
348  VkMemoryRequirements req;
349  vkGetImageMemoryRequirements(g_Device, g_FontImage, &req);
350  VkMemoryAllocateInfo alloc_info = {};
351  alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
352  alloc_info.allocationSize = req.size;
353  alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits);
354  err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_FontMemory);
355  ImGui_ImplGlfwVulkan_VkResult(err);
356  err = vkBindImageMemory(g_Device, g_FontImage, g_FontMemory, 0);
357  ImGui_ImplGlfwVulkan_VkResult(err);
358  }
359 
360  // Create the Image View:
361  {
362  VkImageViewCreateInfo info = {};
363  info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
364  info.image = g_FontImage;
365  info.viewType = VK_IMAGE_VIEW_TYPE_2D;
366  info.format = VK_FORMAT_R8G8B8A8_UNORM;
367  info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
368  info.subresourceRange.levelCount = 1;
369  info.subresourceRange.layerCount = 1;
370  err = vkCreateImageView(g_Device, &info, g_Allocator, &g_FontView);
371  ImGui_ImplGlfwVulkan_VkResult(err);
372  }
373 
374  // Update the Descriptor Set:
375  {
376  VkDescriptorImageInfo desc_image[1] = {};
377  desc_image[0].sampler = g_FontSampler;
378  desc_image[0].imageView = g_FontView;
379  desc_image[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
380  VkWriteDescriptorSet write_desc[1] = {};
381  write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
382  write_desc[0].dstSet = g_DescriptorSet;
383  write_desc[0].descriptorCount = 1;
384  write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
385  write_desc[0].pImageInfo = desc_image;
386  vkUpdateDescriptorSets(g_Device, 1, write_desc, 0, NULL);
387  }
388 
389  // Create the Upload Buffer:
390  {
391  VkBufferCreateInfo buffer_info = {};
392  buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
393  buffer_info.size = upload_size;
394  buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
395  buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
396  err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_UploadBuffer);
397  ImGui_ImplGlfwVulkan_VkResult(err);
398  VkMemoryRequirements req;
399  vkGetBufferMemoryRequirements(g_Device, g_UploadBuffer, &req);
400  g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment;
401  VkMemoryAllocateInfo alloc_info = {};
402  alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
403  alloc_info.allocationSize = req.size;
404  alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
405  err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_UploadBufferMemory);
406  ImGui_ImplGlfwVulkan_VkResult(err);
407  err = vkBindBufferMemory(g_Device, g_UploadBuffer, g_UploadBufferMemory, 0);
408  ImGui_ImplGlfwVulkan_VkResult(err);
409  }
410 
411  // Upload to Buffer:
412  {
413  char* map = NULL;
414  err = vkMapMemory(g_Device, g_UploadBufferMemory, 0, upload_size, 0, (void**)(&map));
415  ImGui_ImplGlfwVulkan_VkResult(err);
416  memcpy(map, pixels, upload_size);
417  VkMappedMemoryRange range[1] = {};
418  range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
419  range[0].memory = g_UploadBufferMemory;
420  range[0].size = upload_size;
421  err = vkFlushMappedMemoryRanges(g_Device, 1, range);
422  ImGui_ImplGlfwVulkan_VkResult(err);
423  vkUnmapMemory(g_Device, g_UploadBufferMemory);
424  }
425  // Copy to Image:
426  {
427  VkImageMemoryBarrier copy_barrier[1] = {};
428  copy_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
429  copy_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
430  copy_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
431  copy_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
432  copy_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
433  copy_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
434  copy_barrier[0].image = g_FontImage;
435  copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
436  copy_barrier[0].subresourceRange.levelCount = 1;
437  copy_barrier[0].subresourceRange.layerCount = 1;
438  vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, copy_barrier);
439 
440  VkBufferImageCopy region = {};
441  region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
442  region.imageSubresource.layerCount = 1;
443  region.imageExtent.width = width;
444  region.imageExtent.height = height;
445  region.imageExtent.depth = 1;
446  vkCmdCopyBufferToImage(command_buffer, g_UploadBuffer, g_FontImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
447 
448  VkImageMemoryBarrier use_barrier[1] = {};
449  use_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
450  use_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
451  use_barrier[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
452  use_barrier[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
453  use_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
454  use_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
455  use_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
456  use_barrier[0].image = g_FontImage;
457  use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
458  use_barrier[0].subresourceRange.levelCount = 1;
459  use_barrier[0].subresourceRange.layerCount = 1;
460  vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, use_barrier);
461  }
462 
463  // Store our identifier
464  io.Fonts->TexID = (void *)(intptr_t)g_FontImage;
465 
466  return true;
467 }
468 
469 bool ImGui_ImplGlfwVulkan_CreateDeviceObjects()
470 {
471  VkResult err;
472  VkShaderModule vert_module;
473  VkShaderModule frag_module;
474 
475  // Create The Shader Modules:
476  {
477  VkShaderModuleCreateInfo vert_info = {};
478  vert_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
479  vert_info.codeSize = sizeof(__glsl_shader_vert_spv);
480  vert_info.pCode = (uint32_t*)__glsl_shader_vert_spv;
481  err = vkCreateShaderModule(g_Device, &vert_info, g_Allocator, &vert_module);
482  ImGui_ImplGlfwVulkan_VkResult(err);
483  VkShaderModuleCreateInfo frag_info = {};
484  frag_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
485  frag_info.codeSize = sizeof(__glsl_shader_frag_spv);
486  frag_info.pCode = (uint32_t*)__glsl_shader_frag_spv;
487  err = vkCreateShaderModule(g_Device, &frag_info, g_Allocator, &frag_module);
488  ImGui_ImplGlfwVulkan_VkResult(err);
489  }
490 
491  if (!g_FontSampler)
492  {
493  VkSamplerCreateInfo info = {};
494  info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
495  info.magFilter = VK_FILTER_LINEAR;
496  info.minFilter = VK_FILTER_LINEAR;
497  info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
498  info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
499  info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
500  info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
501  info.minLod = -1000;
502  info.maxLod = 1000;
503  info.maxAnisotropy = 1.0f;
504  err = vkCreateSampler(g_Device, &info, g_Allocator, &g_FontSampler);
505  ImGui_ImplGlfwVulkan_VkResult(err);
506  }
507 
508  if (!g_DescriptorSetLayout)
509  {
510  VkSampler sampler[1] = { g_FontSampler };
511  VkDescriptorSetLayoutBinding binding[1] = {};
512  binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
513  binding[0].descriptorCount = 1;
514  binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
515  binding[0].pImmutableSamplers = sampler;
516  VkDescriptorSetLayoutCreateInfo info = {};
517  info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
518  info.bindingCount = 1;
519  info.pBindings = binding;
520  err = vkCreateDescriptorSetLayout(g_Device, &info, g_Allocator, &g_DescriptorSetLayout);
521  ImGui_ImplGlfwVulkan_VkResult(err);
522  }
523 
524  // Create Descriptor Set:
525  {
526  VkDescriptorSetAllocateInfo alloc_info = {};
527  alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
528  alloc_info.descriptorPool = g_DescriptorPool;
529  alloc_info.descriptorSetCount = 1;
530  alloc_info.pSetLayouts = &g_DescriptorSetLayout;
531  err = vkAllocateDescriptorSets(g_Device, &alloc_info, &g_DescriptorSet);
532  ImGui_ImplGlfwVulkan_VkResult(err);
533  }
534 
535  if (!g_PipelineLayout)
536  {
537  VkPushConstantRange push_constants[1] = {};
538  push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
539  push_constants[0].offset = sizeof(float) * 0;
540  push_constants[0].size = sizeof(float) * 4;
541  VkDescriptorSetLayout set_layout[1] = { g_DescriptorSetLayout };
542  VkPipelineLayoutCreateInfo layout_info = {};
543  layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
544  layout_info.setLayoutCount = 1;
545  layout_info.pSetLayouts = set_layout;
546  layout_info.pushConstantRangeCount = 1;
547  layout_info.pPushConstantRanges = push_constants;
548  err = vkCreatePipelineLayout(g_Device, &layout_info, g_Allocator, &g_PipelineLayout);
549  ImGui_ImplGlfwVulkan_VkResult(err);
550  }
551 
552  VkPipelineShaderStageCreateInfo stage[2] = {};
553  stage[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
554  stage[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
555  stage[0].module = vert_module;
556  stage[0].pName = "main";
557  stage[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
558  stage[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
559  stage[1].module = frag_module;
560  stage[1].pName = "main";
561 
562  VkVertexInputBindingDescription binding_desc[1] = {};
563  binding_desc[0].stride = sizeof(ImDrawVert);
564  binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
565 
566  VkVertexInputAttributeDescription attribute_desc[3] = {};
567  attribute_desc[0].location = 0;
568  attribute_desc[0].binding = binding_desc[0].binding;
569  attribute_desc[0].format = VK_FORMAT_R32G32_SFLOAT;
570  attribute_desc[0].offset = (size_t)(&((ImDrawVert*)0)->pos);
571  attribute_desc[1].location = 1;
572  attribute_desc[1].binding = binding_desc[0].binding;
573  attribute_desc[1].format = VK_FORMAT_R32G32_SFLOAT;
574  attribute_desc[1].offset = (size_t)(&((ImDrawVert*)0)->uv);
575  attribute_desc[2].location = 2;
576  attribute_desc[2].binding = binding_desc[0].binding;
577  attribute_desc[2].format = VK_FORMAT_R8G8B8A8_UNORM;
578  attribute_desc[2].offset = (size_t)(&((ImDrawVert*)0)->col);
579 
580  VkPipelineVertexInputStateCreateInfo vertex_info = {};
581  vertex_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
582  vertex_info.vertexBindingDescriptionCount = 1;
583  vertex_info.pVertexBindingDescriptions = binding_desc;
584  vertex_info.vertexAttributeDescriptionCount = 3;
585  vertex_info.pVertexAttributeDescriptions = attribute_desc;
586 
587  VkPipelineInputAssemblyStateCreateInfo ia_info = {};
588  ia_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
589  ia_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
590 
591  VkPipelineViewportStateCreateInfo viewport_info = {};
592  viewport_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
593  viewport_info.viewportCount = 1;
594  viewport_info.scissorCount = 1;
595 
596  VkPipelineRasterizationStateCreateInfo raster_info = {};
597  raster_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
598  raster_info.polygonMode = VK_POLYGON_MODE_FILL;
599  raster_info.cullMode = VK_CULL_MODE_NONE;
600  raster_info.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
601  raster_info.lineWidth = 1.0f;
602 
603  VkPipelineMultisampleStateCreateInfo ms_info = {};
604  ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
605  ms_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
606 
607  VkPipelineColorBlendAttachmentState color_attachment[1] = {};
608  color_attachment[0].blendEnable = VK_TRUE;
609  color_attachment[0].srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
610  color_attachment[0].dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
611  color_attachment[0].colorBlendOp = VK_BLEND_OP_ADD;
612  color_attachment[0].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
613  color_attachment[0].dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
614  color_attachment[0].alphaBlendOp = VK_BLEND_OP_ADD;
615  color_attachment[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
616 
617  VkPipelineDepthStencilStateCreateInfo depth_info = {};
618  depth_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
619 
620  VkPipelineColorBlendStateCreateInfo blend_info = {};
621  blend_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
622  blend_info.attachmentCount = 1;
623  blend_info.pAttachments = color_attachment;
624 
625  VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
626  VkPipelineDynamicStateCreateInfo dynamic_state = {};
627  dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
628  dynamic_state.dynamicStateCount = 2;
629  dynamic_state.pDynamicStates = dynamic_states;
630 
631  VkGraphicsPipelineCreateInfo info = {};
632  info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
633  info.flags = g_PipelineCreateFlags;
634  info.stageCount = 2;
635  info.pStages = stage;
636  info.pVertexInputState = &vertex_info;
637  info.pInputAssemblyState = &ia_info;
638  info.pViewportState = &viewport_info;
639  info.pRasterizationState = &raster_info;
640  info.pMultisampleState = &ms_info;
641  info.pDepthStencilState = &depth_info;
642  info.pColorBlendState = &blend_info;
643  info.pDynamicState = &dynamic_state;
644  info.layout = g_PipelineLayout;
645  info.renderPass = g_RenderPass;
646  err = vkCreateGraphicsPipelines(g_Device, g_PipelineCache, 1, &info, g_Allocator, &g_Pipeline);
647  ImGui_ImplGlfwVulkan_VkResult(err);
648 
649  vkDestroyShaderModule(g_Device, vert_module, g_Allocator);
650  vkDestroyShaderModule(g_Device, frag_module, g_Allocator);
651 
652  return true;
653 }
654 
655 void ImGui_ImplGlfwVulkan_InvalidateFontUploadObjects()
656 {
657  if (g_UploadBuffer)
658  {
659  vkDestroyBuffer(g_Device, g_UploadBuffer, g_Allocator);
660  g_UploadBuffer = VK_NULL_HANDLE;
661  }
662  if (g_UploadBufferMemory)
663  {
664  vkFreeMemory(g_Device, g_UploadBufferMemory, g_Allocator);
665  g_UploadBufferMemory = VK_NULL_HANDLE;
666  }
667 }
668 
669 void ImGui_ImplGlfwVulkan_InvalidateDeviceObjects()
670 {
671  ImGui_ImplGlfwVulkan_InvalidateFontUploadObjects();
672 
673  for (int i = 0; i < IMGUI_VK_QUEUED_FRAMES; i++)
674  {
675  if (g_VertexBuffer[i]) { vkDestroyBuffer(g_Device, g_VertexBuffer[i], g_Allocator); g_VertexBuffer[i] = VK_NULL_HANDLE; }
676  if (g_VertexBufferMemory[i]) { vkFreeMemory(g_Device, g_VertexBufferMemory[i], g_Allocator); g_VertexBufferMemory[i] = VK_NULL_HANDLE; }
677  if (g_IndexBuffer[i]) { vkDestroyBuffer(g_Device, g_IndexBuffer[i], g_Allocator); g_IndexBuffer[i] = VK_NULL_HANDLE; }
678  if (g_IndexBufferMemory[i]) { vkFreeMemory(g_Device, g_IndexBufferMemory[i], g_Allocator); g_IndexBufferMemory[i] = VK_NULL_HANDLE; }
679  }
680 
681  if (g_FontView) { vkDestroyImageView(g_Device, g_FontView, g_Allocator); g_FontView = VK_NULL_HANDLE; }
682  if (g_FontImage) { vkDestroyImage(g_Device, g_FontImage, g_Allocator); g_FontImage = VK_NULL_HANDLE; }
683  if (g_FontMemory) { vkFreeMemory(g_Device, g_FontMemory, g_Allocator); g_FontMemory = VK_NULL_HANDLE; }
684  if (g_FontSampler) { vkDestroySampler(g_Device, g_FontSampler, g_Allocator); g_FontSampler = VK_NULL_HANDLE; }
685  if (g_DescriptorSetLayout) { vkDestroyDescriptorSetLayout(g_Device, g_DescriptorSetLayout, g_Allocator); g_DescriptorSetLayout = VK_NULL_HANDLE; }
686  if (g_PipelineLayout) { vkDestroyPipelineLayout(g_Device, g_PipelineLayout, g_Allocator); g_PipelineLayout = VK_NULL_HANDLE; }
687  if (g_Pipeline) { vkDestroyPipeline(g_Device, g_Pipeline, g_Allocator); g_Pipeline = VK_NULL_HANDLE; }
688 }
689 
690 bool ImGui_ImplGlfwVulkan_Init(GLFWwindow* window, ImGui_ImplGlfwVulkan_Init_Data *init_data)
691 {
692  g_Allocator = init_data->allocator;
693  g_Gpu = init_data->gpu;
694  g_Device = init_data->device;
695  g_RenderPass = init_data->render_pass;
696  g_PipelineCache = init_data->pipeline_cache;
697  g_DescriptorPool = init_data->descriptor_pool;
698  g_CheckVkResult = init_data->check_vk_result;
699 
700  g_Window = window;
701 
702  ImGuiIO& io = ImGui::GetIO();
703 
704  io.RenderDrawListsFn = ImGui_ImplGlfwVulkan_RenderDrawLists; // Alternatively you can set this to NULL and call ImGui::GetDrawData() after ImGui::Render() to get the same ImDrawData pointer.
705  io.SetClipboardTextFn = ImGui_ImplGlfwVulkan_SetClipboardText;
706  io.GetClipboardTextFn = ImGui_ImplGlfwVulkan_GetClipboardText;
707  io.ClipboardUserData = g_Window;
708 #ifdef _WIN32
709  io.ImeWindowHandle = Engine::Engine::GetEngine().lock()->GetWindow().lock()->GetWindowHandle();
710 #endif
711 
712  ImGui_ImplGlfwVulkan_CreateDeviceObjects();
713 
714  return true;
715 }
716 
717 void ImGui_ImplGlfwVulkan_Shutdown()
718 {
719  ImGui_ImplGlfwVulkan_InvalidateDeviceObjects();
720  ImGui::Shutdown();
721 }
722 
723 void ImGui_ImplGlfwVulkan_NewFrame()
724 {
725  ImGuiIO& io = ImGui::GetIO();
726  glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
727 
728  // TODO pass in delta time in Time class
729  //double current_time = glfwGetTime();
730  //io.DeltaTime = g_Time > 0.0 ? float(current_time - g_Time) : float(1.0f / 60.0f);
731  //g_Time = current_time;
732  io.DeltaTime = Engine::Engine::GetEngine().lock()->GetTime().lock()->GetDeltaTime();
733 
734  // Start the frame
735  ImGui::NewFrame();
736 }
737 
738 void ImGui_ImplGlfwVulkan_Render(VkCommandBuffer command_buffer)
739 {
740  g_CommandBuffer = command_buffer;
741  ImGui::Render();
742  g_CommandBuffer = VK_NULL_HANDLE;
743  g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES;
744 }
745 #endif // USING_VULKAN
const char *(* GetClipboardTextFn)(void *user_data)
Definition: imgui.h:818
bool MouseDrawCursor
Definition: imgui.h:839
ImDrawList ** CmdLists
Definition: imgui.h:1316
void(* SetClipboardTextFn)(void *user_data, const char *text)
Definition: imgui.h:819
ImVec2 DisplaySize
Definition: imgui.h:783
IMGUI_API void NewFrame()
Definition: imgui.cpp:2170
ImVec4 ClipRect
Definition: imgui.h:1183
int CmdListsCount
Definition: imgui.h:1317
T * Data
Definition: imgui.h:899
float DeltaTime
Definition: imgui.h:784
unsigned short ImDrawIdx
Definition: imgui.h:1193
int Size
Definition: imgui.h:897
float w
Definition: imgui.h:108
ImVector< ImDrawCmd > CmdBuffer
Definition: imgui.h:1230
void * ClipboardUserData
Definition: imgui.h:820
IMGUI_API ImGuiIO & GetIO()
Definition: imgui.cpp:2144
float z
Definition: imgui.h:108
IMGUI_API void GetTexDataAsRGBA32(unsigned char **out_pixels, int *out_width, int *out_height, int *out_bytes_per_pixel=NULL)
ImTextureID TexID
Definition: imgui.h:1443
float x
Definition: imgui.h:108
float y
Definition: imgui.h:98
ImDrawCallback UserCallback
Definition: imgui.h:1185
int TotalIdxCount
Definition: imgui.h:1319
IMGUI_API void Shutdown()
Definition: imgui.cpp:2414
void(* RenderDrawListsFn)(ImDrawData *data)
Definition: imgui.h:814
int TotalVtxCount
Definition: imgui.h:1318
void * ImeWindowHandle
Definition: imgui.h:830
Definition: imgui.h:777
ImVector< ImDrawVert > VtxBuffer
Definition: imgui.h:1232
unsigned int ElemCount
Definition: imgui.h:1182
static eastl::weak_ptr< Engine > GetEngine() noexcept
This method allows you to get the instance of the Engine. This method will automatically initialize t...
Definition: engine.cpp:130
ImVector< ImDrawIdx > IdxBuffer
Definition: imgui.h:1231
ImFontAtlas * Fonts
Definition: imgui.h:796
float y
Definition: imgui.h:108
IMGUI_API void Render()
Definition: imgui.cpp:2769
float x
Definition: imgui.h:98