imgui_impl_glfw_vulkan.cpp 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  1. // ImGui GLFW binding with Vulkan + shaders
  2. // You can copy and use unmodified imgui_impl_* files in your project. See main.cpp for an example of using this.
  3. // 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().
  4. // If you are new to ImGui, see examples/README.txt and documentation at the top of imgui.cpp.
  5. // https://github.com/ocornut/imgui
  6. #include <imgui.h>
  7. // GLFW
  8. #define GLFW_INCLUDE_NONE
  9. #define GLFW_INCLUDE_VULKAN
  10. #include <GLFW/glfw3.h>
  11. #ifdef _WIN32
  12. #undef APIENTRY
  13. #define GLFW_EXPOSE_NATIVE_WIN32
  14. #define GLFW_EXPOSE_NATIVE_WGL
  15. #include <GLFW/glfw3native.h>
  16. #endif
  17. #include "imgui_impl_glfw_vulkan.h"
  18. // GLFW Data
  19. static GLFWwindow* g_Window = NULL;
  20. static double g_Time = 0.0f;
  21. static bool g_MousePressed[3] = { false, false, false };
  22. static float g_MouseWheel = 0.0f;
  23. // Vulkan Data
  24. static VkAllocationCallbacks* g_Allocator = NULL;
  25. static VkPhysicalDevice g_Gpu = VK_NULL_HANDLE;
  26. static VkDevice g_Device = VK_NULL_HANDLE;
  27. static VkRenderPass g_RenderPass = VK_NULL_HANDLE;
  28. static VkPipelineCache g_PipelineCache = VK_NULL_HANDLE;
  29. static VkDescriptorPool g_DescriptorPool = VK_NULL_HANDLE;
  30. static void (*g_CheckVkResult)(VkResult err) = NULL;
  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. static VkDescriptorSetLayout g_DescriptorSetLayout = VK_NULL_HANDLE;
  36. static VkPipelineLayout g_PipelineLayout = VK_NULL_HANDLE;
  37. static VkDescriptorSet g_DescriptorSet = VK_NULL_HANDLE;
  38. static VkPipeline g_Pipeline = VK_NULL_HANDLE;
  39. static VkSampler g_FontSampler = VK_NULL_HANDLE;
  40. static VkDeviceMemory g_FontMemory = VK_NULL_HANDLE;
  41. static VkImage g_FontImage = VK_NULL_HANDLE;
  42. static VkImageView g_FontView = VK_NULL_HANDLE;
  43. static VkDeviceMemory g_VertexBufferMemory[IMGUI_VK_QUEUED_FRAMES] = {};
  44. static VkDeviceMemory g_IndexBufferMemory[IMGUI_VK_QUEUED_FRAMES] = {};
  45. static size_t g_VertexBufferSize[IMGUI_VK_QUEUED_FRAMES] = {};
  46. static size_t g_IndexBufferSize[IMGUI_VK_QUEUED_FRAMES] = {};
  47. static VkBuffer g_VertexBuffer[IMGUI_VK_QUEUED_FRAMES] = {};
  48. static VkBuffer g_IndexBuffer[IMGUI_VK_QUEUED_FRAMES] = {};
  49. static VkDeviceMemory g_UploadBufferMemory = VK_NULL_HANDLE;
  50. static VkBuffer g_UploadBuffer = VK_NULL_HANDLE;
  51. static unsigned char __glsl_shader_vert_spv[] =
  52. {
  53. 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00,
  54. 0x6c, 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
  55. 0x01, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, 0x20, 0x00, 0x00, 0x00,
  56. 0x11, 0x00, 0x02, 0x00, 0x21, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00,
  57. 0x01, 0x00, 0x00, 0x00, 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64,
  58. 0x2e, 0x34, 0x35, 0x30, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00,
  59. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x0a, 0x00,
  60. 0x00, 0x00, 0x00, 0x00, 0x1f, 0x16, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e,
  61. 0x00, 0x00, 0x00, 0x00, 0x47, 0x11, 0x00, 0x00, 0x41, 0x14, 0x00, 0x00,
  62. 0x6a, 0x16, 0x00, 0x00, 0x42, 0x13, 0x00, 0x00, 0x80, 0x14, 0x00, 0x00,
  63. 0x47, 0x00, 0x03, 0x00, 0x1a, 0x04, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  64. 0x47, 0x00, 0x04, 0x00, 0x41, 0x14, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00,
  65. 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x6a, 0x16, 0x00, 0x00,
  66. 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00,
  67. 0xb1, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00,
  68. 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0xb1, 0x02, 0x00, 0x00,
  69. 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  70. 0x48, 0x00, 0x05, 0x00, 0xb1, 0x02, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  71. 0x0b, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00,
  72. 0xb1, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00,
  73. 0x04, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0xb1, 0x02, 0x00, 0x00,
  74. 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0x80, 0x14, 0x00, 0x00,
  75. 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00,
  76. 0x06, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00,
  77. 0x00, 0x00, 0x00, 0x00, 0x48, 0x00, 0x05, 0x00, 0x06, 0x04, 0x00, 0x00,
  78. 0x01, 0x00, 0x00, 0x00, 0x23, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  79. 0x47, 0x00, 0x03, 0x00, 0x06, 0x04, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  80. 0x47, 0x00, 0x04, 0x00, 0xfa, 0x16, 0x00, 0x00, 0x22, 0x00, 0x00, 0x00,
  81. 0x00, 0x00, 0x00, 0x00, 0x13, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00,
  82. 0x21, 0x00, 0x03, 0x00, 0x02, 0x05, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
  83. 0x16, 0x00, 0x03, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  84. 0x17, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
  85. 0x04, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00,
  86. 0x0d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x04, 0x00,
  87. 0x1a, 0x04, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
  88. 0x20, 0x00, 0x04, 0x00, 0x97, 0x06, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  89. 0x1a, 0x04, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x97, 0x06, 0x00, 0x00,
  90. 0x47, 0x11, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00,
  91. 0x0c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  92. 0x2b, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0b, 0x0a, 0x00, 0x00,
  93. 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x9a, 0x02, 0x00, 0x00,
  94. 0x01, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00,
  95. 0x9a, 0x02, 0x00, 0x00, 0x41, 0x14, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  96. 0x20, 0x00, 0x04, 0x00, 0x9b, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  97. 0x1d, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
  98. 0x0e, 0x0a, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  99. 0x90, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
  100. 0x3b, 0x00, 0x04, 0x00, 0x90, 0x02, 0x00, 0x00, 0x6a, 0x16, 0x00, 0x00,
  101. 0x01, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x91, 0x02, 0x00, 0x00,
  102. 0x03, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x15, 0x00, 0x04, 0x00,
  103. 0x0b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  104. 0x2b, 0x00, 0x04, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x0d, 0x0a, 0x00, 0x00,
  105. 0x01, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x04, 0x00, 0x7f, 0x02, 0x00, 0x00,
  106. 0x0d, 0x00, 0x00, 0x00, 0x0d, 0x0a, 0x00, 0x00, 0x1e, 0x00, 0x06, 0x00,
  107. 0xb1, 0x02, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
  108. 0x7f, 0x02, 0x00, 0x00, 0x7f, 0x02, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  109. 0x2e, 0x05, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xb1, 0x02, 0x00, 0x00,
  110. 0x3b, 0x00, 0x04, 0x00, 0x2e, 0x05, 0x00, 0x00, 0x42, 0x13, 0x00, 0x00,
  111. 0x03, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x90, 0x02, 0x00, 0x00,
  112. 0x80, 0x14, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1e, 0x00, 0x04, 0x00,
  113. 0x06, 0x04, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
  114. 0x20, 0x00, 0x04, 0x00, 0x83, 0x06, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00,
  115. 0x06, 0x04, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x83, 0x06, 0x00, 0x00,
  116. 0xfa, 0x16, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  117. 0x92, 0x02, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x13, 0x00, 0x00, 0x00,
  118. 0x2b, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0c, 0x0a, 0x00, 0x00,
  119. 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x0d, 0x00, 0x00, 0x00,
  120. 0x8a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3f, 0x36, 0x00, 0x05, 0x00,
  121. 0x08, 0x00, 0x00, 0x00, 0x1f, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  122. 0x02, 0x05, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x6b, 0x60, 0x00, 0x00,
  123. 0x3d, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x71, 0x4e, 0x00, 0x00,
  124. 0x41, 0x14, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x9b, 0x02, 0x00, 0x00,
  125. 0xaa, 0x26, 0x00, 0x00, 0x47, 0x11, 0x00, 0x00, 0x0b, 0x0a, 0x00, 0x00,
  126. 0x3e, 0x00, 0x03, 0x00, 0xaa, 0x26, 0x00, 0x00, 0x71, 0x4e, 0x00, 0x00,
  127. 0x3d, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0xda, 0x35, 0x00, 0x00,
  128. 0x6a, 0x16, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x91, 0x02, 0x00, 0x00,
  129. 0xea, 0x50, 0x00, 0x00, 0x47, 0x11, 0x00, 0x00, 0x0e, 0x0a, 0x00, 0x00,
  130. 0x3e, 0x00, 0x03, 0x00, 0xea, 0x50, 0x00, 0x00, 0xda, 0x35, 0x00, 0x00,
  131. 0x3d, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0xc7, 0x35, 0x00, 0x00,
  132. 0x80, 0x14, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x92, 0x02, 0x00, 0x00,
  133. 0xef, 0x56, 0x00, 0x00, 0xfa, 0x16, 0x00, 0x00, 0x0b, 0x0a, 0x00, 0x00,
  134. 0x3d, 0x00, 0x04, 0x00, 0x13, 0x00, 0x00, 0x00, 0xe0, 0x29, 0x00, 0x00,
  135. 0xef, 0x56, 0x00, 0x00, 0x85, 0x00, 0x05, 0x00, 0x13, 0x00, 0x00, 0x00,
  136. 0xa0, 0x22, 0x00, 0x00, 0xc7, 0x35, 0x00, 0x00, 0xe0, 0x29, 0x00, 0x00,
  137. 0x41, 0x00, 0x05, 0x00, 0x92, 0x02, 0x00, 0x00, 0x42, 0x2c, 0x00, 0x00,
  138. 0xfa, 0x16, 0x00, 0x00, 0x0e, 0x0a, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00,
  139. 0x13, 0x00, 0x00, 0x00, 0x09, 0x60, 0x00, 0x00, 0x42, 0x2c, 0x00, 0x00,
  140. 0x81, 0x00, 0x05, 0x00, 0x13, 0x00, 0x00, 0x00, 0xd1, 0x4e, 0x00, 0x00,
  141. 0xa0, 0x22, 0x00, 0x00, 0x09, 0x60, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00,
  142. 0x0d, 0x00, 0x00, 0x00, 0xa1, 0x41, 0x00, 0x00, 0xd1, 0x4e, 0x00, 0x00,
  143. 0x00, 0x00, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x0d, 0x00, 0x00, 0x00,
  144. 0x84, 0x36, 0x00, 0x00, 0xd1, 0x4e, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  145. 0x50, 0x00, 0x07, 0x00, 0x1d, 0x00, 0x00, 0x00, 0x54, 0x47, 0x00, 0x00,
  146. 0xa1, 0x41, 0x00, 0x00, 0x84, 0x36, 0x00, 0x00, 0x0c, 0x0a, 0x00, 0x00,
  147. 0x8a, 0x00, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00, 0x9b, 0x02, 0x00, 0x00,
  148. 0x17, 0x2f, 0x00, 0x00, 0x42, 0x13, 0x00, 0x00, 0x0b, 0x0a, 0x00, 0x00,
  149. 0x3e, 0x00, 0x03, 0x00, 0x17, 0x2f, 0x00, 0x00, 0x54, 0x47, 0x00, 0x00,
  150. 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00
  151. };
  152. static unsigned int __glsl_shader_vert_spv_len = 1172;
  153. static unsigned char __glsl_shader_frag_spv[] =
  154. {
  155. 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x08, 0x00,
  156. 0x6c, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00,
  157. 0x01, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00,
  158. 0x47, 0x4c, 0x53, 0x4c, 0x2e, 0x73, 0x74, 0x64, 0x2e, 0x34, 0x35, 0x30,
  159. 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00,
  160. 0x01, 0x00, 0x00, 0x00, 0x0f, 0x00, 0x07, 0x00, 0x04, 0x00, 0x00, 0x00,
  161. 0x1f, 0x16, 0x00, 0x00, 0x6d, 0x61, 0x69, 0x6e, 0x00, 0x00, 0x00, 0x00,
  162. 0x7a, 0x0c, 0x00, 0x00, 0x35, 0x16, 0x00, 0x00, 0x10, 0x00, 0x03, 0x00,
  163. 0x1f, 0x16, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
  164. 0x7a, 0x0c, 0x00, 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  165. 0x47, 0x00, 0x04, 0x00, 0x7a, 0x0c, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  166. 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x03, 0x00, 0x1a, 0x04, 0x00, 0x00,
  167. 0x02, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00, 0xec, 0x14, 0x00, 0x00,
  168. 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x00, 0x04, 0x00,
  169. 0xec, 0x14, 0x00, 0x00, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  170. 0x13, 0x00, 0x02, 0x00, 0x08, 0x00, 0x00, 0x00, 0x21, 0x00, 0x03, 0x00,
  171. 0x02, 0x05, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x16, 0x00, 0x03, 0x00,
  172. 0x0d, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00,
  173. 0x1d, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
  174. 0x20, 0x00, 0x04, 0x00, 0x9a, 0x02, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
  175. 0x1d, 0x00, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x9a, 0x02, 0x00, 0x00,
  176. 0x7a, 0x0c, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x17, 0x00, 0x04, 0x00,
  177. 0x13, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
  178. 0x1e, 0x00, 0x04, 0x00, 0x1a, 0x04, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00,
  179. 0x13, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00, 0x97, 0x06, 0x00, 0x00,
  180. 0x01, 0x00, 0x00, 0x00, 0x1a, 0x04, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00,
  181. 0x97, 0x06, 0x00, 0x00, 0x35, 0x16, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  182. 0x15, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00,
  183. 0x01, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00, 0x0c, 0x00, 0x00, 0x00,
  184. 0x0b, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x00, 0x04, 0x00,
  185. 0x9b, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1d, 0x00, 0x00, 0x00,
  186. 0x19, 0x00, 0x09, 0x00, 0x96, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00,
  187. 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  188. 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  189. 0x1b, 0x00, 0x03, 0x00, 0xfe, 0x01, 0x00, 0x00, 0x96, 0x00, 0x00, 0x00,
  190. 0x20, 0x00, 0x04, 0x00, 0x7b, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  191. 0xfe, 0x01, 0x00, 0x00, 0x3b, 0x00, 0x04, 0x00, 0x7b, 0x04, 0x00, 0x00,
  192. 0xec, 0x14, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2b, 0x00, 0x04, 0x00,
  193. 0x0c, 0x00, 0x00, 0x00, 0x0e, 0x0a, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  194. 0x20, 0x00, 0x04, 0x00, 0x90, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
  195. 0x13, 0x00, 0x00, 0x00, 0x36, 0x00, 0x05, 0x00, 0x08, 0x00, 0x00, 0x00,
  196. 0x1f, 0x16, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x05, 0x00, 0x00,
  197. 0xf8, 0x00, 0x02, 0x00, 0x6b, 0x5d, 0x00, 0x00, 0x41, 0x00, 0x05, 0x00,
  198. 0x9b, 0x02, 0x00, 0x00, 0x8d, 0x1b, 0x00, 0x00, 0x35, 0x16, 0x00, 0x00,
  199. 0x0b, 0x0a, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x1d, 0x00, 0x00, 0x00,
  200. 0x0b, 0x40, 0x00, 0x00, 0x8d, 0x1b, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00,
  201. 0xfe, 0x01, 0x00, 0x00, 0xc0, 0x36, 0x00, 0x00, 0xec, 0x14, 0x00, 0x00,
  202. 0x41, 0x00, 0x05, 0x00, 0x90, 0x02, 0x00, 0x00, 0xc2, 0x43, 0x00, 0x00,
  203. 0x35, 0x16, 0x00, 0x00, 0x0e, 0x0a, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00,
  204. 0x13, 0x00, 0x00, 0x00, 0x02, 0x4e, 0x00, 0x00, 0xc2, 0x43, 0x00, 0x00,
  205. 0x57, 0x00, 0x05, 0x00, 0x1d, 0x00, 0x00, 0x00, 0xb9, 0x46, 0x00, 0x00,
  206. 0xc0, 0x36, 0x00, 0x00, 0x02, 0x4e, 0x00, 0x00, 0x85, 0x00, 0x05, 0x00,
  207. 0x1d, 0x00, 0x00, 0x00, 0xe4, 0x23, 0x00, 0x00, 0x0b, 0x40, 0x00, 0x00,
  208. 0xb9, 0x46, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x7a, 0x0c, 0x00, 0x00,
  209. 0xe4, 0x23, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00
  210. };
  211. static unsigned int __glsl_shader_frag_spv_len = 660;
  212. static uint32_t ImGui_ImplGlfwVulkan_MemoryType(VkMemoryPropertyFlags properties, uint32_t type_bits)
  213. {
  214. VkPhysicalDeviceMemoryProperties prop;
  215. vkGetPhysicalDeviceMemoryProperties(g_Gpu, &prop);
  216. for (uint32_t i = 0; i < prop.memoryTypeCount; i++)
  217. if ((prop.memoryTypes[i].propertyFlags & properties) == properties && type_bits & (1<<i))
  218. return i;
  219. return 0xffffffff; // Unable to find memoryType
  220. }
  221. static void ImGui_ImplGlfwVulkan_VkResult(VkResult err)
  222. {
  223. if (g_CheckVkResult)
  224. g_CheckVkResult(err);
  225. }
  226. // This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
  227. void ImGui_ImplGlfwVulkan_RenderDrawLists(ImDrawData* draw_data)
  228. {
  229. VkResult err;
  230. ImGuiIO& io = ImGui::GetIO();
  231. // Create the Vertex Buffer:
  232. size_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
  233. if (!g_VertexBuffer[g_FrameIndex] || g_VertexBufferSize[g_FrameIndex] < vertex_size)
  234. {
  235. if (g_VertexBuffer[g_FrameIndex])
  236. vkDestroyBuffer(g_Device, g_VertexBuffer[g_FrameIndex], g_Allocator);
  237. if (g_VertexBufferMemory[g_FrameIndex])
  238. vkFreeMemory(g_Device, g_VertexBufferMemory[g_FrameIndex], g_Allocator);
  239. size_t vertex_buffer_size = ((vertex_size-1) / g_BufferMemoryAlignment+1) * g_BufferMemoryAlignment;
  240. VkBufferCreateInfo buffer_info = {};
  241. buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
  242. buffer_info.size = vertex_buffer_size;
  243. buffer_info.usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
  244. buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  245. err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_VertexBuffer[g_FrameIndex]);
  246. ImGui_ImplGlfwVulkan_VkResult(err);
  247. VkMemoryRequirements req;
  248. vkGetBufferMemoryRequirements(g_Device, g_VertexBuffer[g_FrameIndex], &req);
  249. g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment;
  250. VkMemoryAllocateInfo alloc_info = {};
  251. alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
  252. alloc_info.allocationSize = req.size;
  253. alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
  254. err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_VertexBufferMemory[g_FrameIndex]);
  255. ImGui_ImplGlfwVulkan_VkResult(err);
  256. err = vkBindBufferMemory(g_Device, g_VertexBuffer[g_FrameIndex], g_VertexBufferMemory[g_FrameIndex], 0);
  257. ImGui_ImplGlfwVulkan_VkResult(err);
  258. g_VertexBufferSize[g_FrameIndex] = vertex_buffer_size;
  259. }
  260. // Create the Index Buffer:
  261. size_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx);
  262. if (!g_IndexBuffer[g_FrameIndex] || g_IndexBufferSize[g_FrameIndex] < index_size)
  263. {
  264. if (g_IndexBuffer[g_FrameIndex])
  265. vkDestroyBuffer(g_Device, g_IndexBuffer[g_FrameIndex], g_Allocator);
  266. if (g_IndexBufferMemory[g_FrameIndex])
  267. vkFreeMemory(g_Device, g_IndexBufferMemory[g_FrameIndex], g_Allocator);
  268. size_t index_buffer_size = ((index_size-1) / g_BufferMemoryAlignment+1) * g_BufferMemoryAlignment;
  269. VkBufferCreateInfo buffer_info = {};
  270. buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
  271. buffer_info.size = index_buffer_size;
  272. buffer_info.usage = VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
  273. buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  274. err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_IndexBuffer[g_FrameIndex]);
  275. ImGui_ImplGlfwVulkan_VkResult(err);
  276. VkMemoryRequirements req;
  277. vkGetBufferMemoryRequirements(g_Device, g_IndexBuffer[g_FrameIndex], &req);
  278. g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment;
  279. VkMemoryAllocateInfo alloc_info = {};
  280. alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
  281. alloc_info.allocationSize = req.size;
  282. alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
  283. err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_IndexBufferMemory[g_FrameIndex]);
  284. ImGui_ImplGlfwVulkan_VkResult(err);
  285. err = vkBindBufferMemory(g_Device, g_IndexBuffer[g_FrameIndex], g_IndexBufferMemory[g_FrameIndex], 0);
  286. ImGui_ImplGlfwVulkan_VkResult(err);
  287. g_IndexBufferSize[g_FrameIndex] = index_buffer_size;
  288. }
  289. // Upload Vertex and index Data:
  290. {
  291. ImDrawVert* vtx_dst;
  292. ImDrawIdx* idx_dst;
  293. err = vkMapMemory(g_Device, g_VertexBufferMemory[g_FrameIndex], 0, vertex_size, 0, (void**)(&vtx_dst));
  294. ImGui_ImplGlfwVulkan_VkResult(err);
  295. err = vkMapMemory(g_Device, g_IndexBufferMemory[g_FrameIndex], 0, index_size, 0, (void**)(&idx_dst));
  296. ImGui_ImplGlfwVulkan_VkResult(err);
  297. for (int n = 0; n < draw_data->CmdListsCount; n++)
  298. {
  299. const ImDrawList* cmd_list = draw_data->CmdLists[n];
  300. memcpy(vtx_dst, cmd_list->VtxBuffer.Data, cmd_list->VtxBuffer.Size * sizeof(ImDrawVert));
  301. memcpy(idx_dst, cmd_list->IdxBuffer.Data, cmd_list->IdxBuffer.Size * sizeof(ImDrawIdx));
  302. vtx_dst += cmd_list->VtxBuffer.Size;
  303. idx_dst += cmd_list->IdxBuffer.Size;
  304. }
  305. VkMappedMemoryRange range[2] = {};
  306. range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
  307. range[0].memory = g_VertexBufferMemory[g_FrameIndex];
  308. range[0].size = vertex_size;
  309. range[1].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
  310. range[1].memory = g_IndexBufferMemory[g_FrameIndex];
  311. range[1].size = index_size;
  312. err = vkFlushMappedMemoryRanges(g_Device, 2, range);
  313. ImGui_ImplGlfwVulkan_VkResult(err);
  314. vkUnmapMemory(g_Device, g_VertexBufferMemory[g_FrameIndex]);
  315. vkUnmapMemory(g_Device, g_IndexBufferMemory[g_FrameIndex]);
  316. }
  317. // Bind pipeline and descriptor sets:
  318. {
  319. vkCmdBindPipeline(g_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_Pipeline);
  320. VkDescriptorSet desc_set[1] = {g_DescriptorSet};
  321. vkCmdBindDescriptorSets(g_CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, g_PipelineLayout, 0, 1, desc_set, 0, NULL);
  322. }
  323. // Bind Vertex And Index Buffer:
  324. {
  325. VkBuffer vertex_buffers[1] = {g_VertexBuffer[g_FrameIndex]};
  326. VkDeviceSize vertex_offset[1] = {0};
  327. vkCmdBindVertexBuffers(g_CommandBuffer, 0, 1, vertex_buffers, vertex_offset);
  328. vkCmdBindIndexBuffer(g_CommandBuffer, g_IndexBuffer[g_FrameIndex], 0, VK_INDEX_TYPE_UINT16);
  329. }
  330. // Setup viewport:
  331. {
  332. VkViewport viewport;
  333. viewport.x = 0;
  334. viewport.y = 0;
  335. viewport.width = ImGui::GetIO().DisplaySize.x;
  336. viewport.height = ImGui::GetIO().DisplaySize.y;
  337. viewport.minDepth = 0.0f;
  338. viewport.maxDepth = 1.0f;
  339. vkCmdSetViewport(g_CommandBuffer, 0, 1, &viewport);
  340. }
  341. // Setup scale and translation:
  342. {
  343. float scale[2];
  344. scale[0] = 2.0f/io.DisplaySize.x;
  345. scale[1] = 2.0f/io.DisplaySize.y;
  346. float translate[2];
  347. translate[0] = -1.0f;
  348. translate[1] = -1.0f;
  349. vkCmdPushConstants(g_CommandBuffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 0, sizeof(float) * 2, scale);
  350. vkCmdPushConstants(g_CommandBuffer, g_PipelineLayout, VK_SHADER_STAGE_VERTEX_BIT, sizeof(float) * 2, sizeof(float) * 2, translate);
  351. }
  352. // Render the command lists:
  353. int vtx_offset = 0;
  354. int idx_offset = 0;
  355. for (int n = 0; n < draw_data->CmdListsCount; n++)
  356. {
  357. const ImDrawList* cmd_list = draw_data->CmdLists[n];
  358. for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
  359. {
  360. const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
  361. if (pcmd->UserCallback)
  362. {
  363. pcmd->UserCallback(cmd_list, pcmd);
  364. }
  365. else
  366. {
  367. VkRect2D scissor;
  368. scissor.offset.x = (int32_t)(pcmd->ClipRect.x);
  369. scissor.offset.y = (int32_t)(pcmd->ClipRect.y);
  370. scissor.extent.width = (uint32_t)(pcmd->ClipRect.z - pcmd->ClipRect.x);
  371. scissor.extent.height = (uint32_t)(pcmd->ClipRect.w - pcmd->ClipRect.y + 1); // TODO: + 1??????
  372. vkCmdSetScissor(g_CommandBuffer, 0, 1, &scissor);
  373. vkCmdDrawIndexed(g_CommandBuffer, pcmd->ElemCount, 1, idx_offset, vtx_offset, 0);
  374. }
  375. idx_offset += pcmd->ElemCount;
  376. }
  377. vtx_offset += cmd_list->VtxBuffer.Size;
  378. }
  379. }
  380. static const char* ImGui_ImplGlfwVulkan_GetClipboardText()
  381. {
  382. return glfwGetClipboardString(g_Window);
  383. }
  384. static void ImGui_ImplGlfwVulkan_SetClipboardText(const char* text)
  385. {
  386. glfwSetClipboardString(g_Window, text);
  387. }
  388. void ImGui_ImplGlfwVulkan_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
  389. {
  390. if (action == GLFW_PRESS && button >= 0 && button < 3)
  391. g_MousePressed[button] = true;
  392. }
  393. void ImGui_ImplGlfwVulkan_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffset)
  394. {
  395. g_MouseWheel += (float)yoffset; // Use fractional mouse wheel, 1.0 unit 5 lines.
  396. }
  397. void ImGui_ImplGlfwVulkan_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
  398. {
  399. ImGuiIO& io = ImGui::GetIO();
  400. if (action == GLFW_PRESS)
  401. io.KeysDown[key] = true;
  402. if (action == GLFW_RELEASE)
  403. io.KeysDown[key] = false;
  404. (void)mods; // Modifiers are not reliable across systems
  405. io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL];
  406. io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT];
  407. io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT];
  408. io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
  409. }
  410. void ImGui_ImplGlfwVulkan_CharCallback(GLFWwindow*, unsigned int c)
  411. {
  412. ImGuiIO& io = ImGui::GetIO();
  413. if (c > 0 && c < 0x10000)
  414. io.AddInputCharacter((unsigned short)c);
  415. }
  416. bool ImGui_ImplGlfwVulkan_CreateFontsTexture(VkCommandBuffer command_buffer)
  417. {
  418. ImGuiIO& io = ImGui::GetIO();
  419. unsigned char* pixels;
  420. int width, height;
  421. io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height);
  422. size_t upload_size = width*height*4*sizeof(char);
  423. VkResult err;
  424. // Create the Image:
  425. {
  426. VkImageCreateInfo info = {};
  427. info.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
  428. info.imageType = VK_IMAGE_TYPE_2D;
  429. info.format = VK_FORMAT_R8G8B8A8_UNORM;
  430. info.extent.width = width;
  431. info.extent.height = height;
  432. info.extent.depth = 1;
  433. info.mipLevels = 1;
  434. info.arrayLayers = 1;
  435. info.samples = VK_SAMPLE_COUNT_1_BIT;
  436. info.tiling = VK_IMAGE_TILING_OPTIMAL;
  437. info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT;
  438. info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  439. info.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
  440. err = vkCreateImage(g_Device, &info, g_Allocator, &g_FontImage);
  441. ImGui_ImplGlfwVulkan_VkResult(err);
  442. VkMemoryRequirements req;
  443. vkGetImageMemoryRequirements(g_Device, g_FontImage, &req);
  444. VkMemoryAllocateInfo alloc_info = {};
  445. alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
  446. alloc_info.allocationSize = req.size;
  447. alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, req.memoryTypeBits);
  448. err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_FontMemory);
  449. ImGui_ImplGlfwVulkan_VkResult(err);
  450. err = vkBindImageMemory(g_Device, g_FontImage, g_FontMemory, 0);
  451. ImGui_ImplGlfwVulkan_VkResult(err);
  452. }
  453. // Create the Image View:
  454. {
  455. VkResult err;
  456. VkImageViewCreateInfo info = {};
  457. info.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
  458. info.image = g_FontImage;
  459. info.viewType = VK_IMAGE_VIEW_TYPE_2D;
  460. info.format = VK_FORMAT_R8G8B8A8_UNORM;
  461. info.subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
  462. info.subresourceRange.levelCount = 1;
  463. info.subresourceRange.layerCount = 1;
  464. err = vkCreateImageView(g_Device, &info, g_Allocator, &g_FontView);
  465. ImGui_ImplGlfwVulkan_VkResult(err);
  466. }
  467. // Update the Descriptor Set:
  468. {
  469. VkDescriptorImageInfo desc_image[1] = {};
  470. desc_image[0].sampler = g_FontSampler;
  471. desc_image[0].imageView = g_FontView;
  472. desc_image[0].imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
  473. VkWriteDescriptorSet write_desc[1] = {};
  474. write_desc[0].sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
  475. write_desc[0].dstSet = g_DescriptorSet;
  476. write_desc[0].descriptorCount = 1;
  477. write_desc[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
  478. write_desc[0].pImageInfo = desc_image;
  479. vkUpdateDescriptorSets(g_Device, 1, write_desc, 0, NULL);
  480. }
  481. // Create the Upload Buffer:
  482. {
  483. VkBufferCreateInfo buffer_info = {};
  484. buffer_info.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
  485. buffer_info.size = upload_size;
  486. buffer_info.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
  487. buffer_info.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
  488. err = vkCreateBuffer(g_Device, &buffer_info, g_Allocator, &g_UploadBuffer);
  489. ImGui_ImplGlfwVulkan_VkResult(err);
  490. VkMemoryRequirements req;
  491. vkGetBufferMemoryRequirements(g_Device, g_UploadBuffer, &req);
  492. g_BufferMemoryAlignment = (g_BufferMemoryAlignment > req.alignment) ? g_BufferMemoryAlignment : req.alignment;
  493. VkMemoryAllocateInfo alloc_info = {};
  494. alloc_info.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
  495. alloc_info.allocationSize = req.size;
  496. alloc_info.memoryTypeIndex = ImGui_ImplGlfwVulkan_MemoryType(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, req.memoryTypeBits);
  497. err = vkAllocateMemory(g_Device, &alloc_info, g_Allocator, &g_UploadBufferMemory);
  498. ImGui_ImplGlfwVulkan_VkResult(err);
  499. err = vkBindBufferMemory(g_Device, g_UploadBuffer, g_UploadBufferMemory, 0);
  500. ImGui_ImplGlfwVulkan_VkResult(err);
  501. }
  502. // Upload to Buffer:
  503. {
  504. char* map = NULL;
  505. err = vkMapMemory(g_Device, g_UploadBufferMemory, 0, upload_size, 0, (void**)(&map));
  506. ImGui_ImplGlfwVulkan_VkResult(err);
  507. memcpy(map, pixels, upload_size);
  508. VkMappedMemoryRange range[1] = {};
  509. range[0].sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
  510. range[0].memory = g_UploadBufferMemory;
  511. range[0].size = upload_size;
  512. err = vkFlushMappedMemoryRanges(g_Device, 1, range);
  513. ImGui_ImplGlfwVulkan_VkResult(err);
  514. vkUnmapMemory(g_Device, g_UploadBufferMemory);
  515. }
  516. // Copy to Image:
  517. {
  518. VkImageMemoryBarrier copy_barrier[1] = {};
  519. copy_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
  520. copy_barrier[0].dstAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
  521. copy_barrier[0].oldLayout = VK_IMAGE_LAYOUT_UNDEFINED;
  522. copy_barrier[0].newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
  523. copy_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
  524. copy_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
  525. copy_barrier[0].image = g_FontImage;
  526. copy_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
  527. copy_barrier[0].subresourceRange.levelCount = 1;
  528. copy_barrier[0].subresourceRange.layerCount = 1;
  529. vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_HOST_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, 0, 0, NULL, 0, NULL, 1, copy_barrier);
  530. VkBufferImageCopy region = {};
  531. region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
  532. region.imageSubresource.layerCount = 1;
  533. region.imageExtent.width = width;
  534. region.imageExtent.height = height;
  535. vkCmdCopyBufferToImage(command_buffer, g_UploadBuffer, g_FontImage, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, &region);
  536. VkImageMemoryBarrier use_barrier[1] = {};
  537. use_barrier[0].sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
  538. use_barrier[0].srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT;
  539. use_barrier[0].dstAccessMask = VK_ACCESS_SHADER_READ_BIT;
  540. use_barrier[0].oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;
  541. use_barrier[0].newLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
  542. use_barrier[0].srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
  543. use_barrier[0].dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
  544. use_barrier[0].image = g_FontImage;
  545. use_barrier[0].subresourceRange.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
  546. use_barrier[0].subresourceRange.levelCount = 1;
  547. use_barrier[0].subresourceRange.layerCount = 1;
  548. vkCmdPipelineBarrier(command_buffer, VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, 0, 0, NULL, 0, NULL, 1, use_barrier);
  549. }
  550. // Store our identifier
  551. io.Fonts->TexID = (void *)(intptr_t)g_FontImage;
  552. return true;
  553. }
  554. bool ImGui_ImplGlfwVulkan_CreateDeviceObjects()
  555. {
  556. VkResult err;
  557. VkShaderModule vert_module;
  558. VkShaderModule frag_module;
  559. // Create The Shader Modules:
  560. {
  561. VkShaderModuleCreateInfo vert_info = {};
  562. vert_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
  563. vert_info.codeSize = __glsl_shader_vert_spv_len;
  564. vert_info.pCode = (uint32_t*)__glsl_shader_vert_spv;
  565. err = vkCreateShaderModule(g_Device, &vert_info, g_Allocator, &vert_module);
  566. ImGui_ImplGlfwVulkan_VkResult(err);
  567. VkShaderModuleCreateInfo frag_info = {};
  568. frag_info.sType = VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO;
  569. frag_info.codeSize = __glsl_shader_frag_spv_len;
  570. frag_info.pCode = (uint32_t*)__glsl_shader_frag_spv;
  571. err = vkCreateShaderModule(g_Device, &frag_info, g_Allocator, &frag_module);
  572. ImGui_ImplGlfwVulkan_VkResult(err);
  573. }
  574. if (!g_FontSampler)
  575. {
  576. VkSamplerCreateInfo info = {};
  577. info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
  578. info.magFilter = VK_FILTER_LINEAR;
  579. info.minFilter = VK_FILTER_LINEAR;
  580. info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
  581. info.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  582. info.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  583. info.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
  584. info.minLod = -1000;
  585. info.maxLod = 1000;
  586. err = vkCreateSampler(g_Device, &info, g_Allocator, &g_FontSampler);
  587. ImGui_ImplGlfwVulkan_VkResult(err);
  588. }
  589. if (!g_DescriptorSetLayout)
  590. {
  591. VkSampler sampler[1] = {g_FontSampler};
  592. VkDescriptorSetLayoutBinding binding[1] = {};
  593. binding[0].descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
  594. binding[0].descriptorCount = 1;
  595. binding[0].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT;
  596. binding[0].pImmutableSamplers = sampler;
  597. VkDescriptorSetLayoutCreateInfo info = {};
  598. info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO;
  599. info.bindingCount = 1;
  600. info.pBindings = binding;
  601. err = vkCreateDescriptorSetLayout(g_Device, &info, g_Allocator, &g_DescriptorSetLayout);
  602. ImGui_ImplGlfwVulkan_VkResult(err);
  603. }
  604. // Create Descriptor Set:
  605. {
  606. VkDescriptorSetAllocateInfo alloc_info = {};
  607. alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
  608. alloc_info.descriptorPool = g_DescriptorPool;
  609. alloc_info.descriptorSetCount = 1;
  610. alloc_info.pSetLayouts = &g_DescriptorSetLayout;
  611. err = vkAllocateDescriptorSets(g_Device, &alloc_info, &g_DescriptorSet);
  612. ImGui_ImplGlfwVulkan_VkResult(err);
  613. }
  614. if (!g_PipelineLayout)
  615. {
  616. VkPushConstantRange push_constants[1] = {};
  617. push_constants[0].stageFlags = VK_SHADER_STAGE_VERTEX_BIT;
  618. push_constants[0].offset = sizeof(float) * 0;
  619. push_constants[0].size = sizeof(float) * 4;
  620. VkDescriptorSetLayout set_layout[1] = {g_DescriptorSetLayout};
  621. VkPipelineLayoutCreateInfo layout_info = {};
  622. layout_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
  623. layout_info.setLayoutCount = 1;
  624. layout_info.pSetLayouts = set_layout;
  625. layout_info.pushConstantRangeCount = 1;
  626. layout_info.pPushConstantRanges = push_constants;
  627. err = vkCreatePipelineLayout(g_Device, &layout_info, g_Allocator, &g_PipelineLayout);
  628. ImGui_ImplGlfwVulkan_VkResult(err);
  629. }
  630. VkPipelineShaderStageCreateInfo stage[2] = {};
  631. stage[0].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
  632. stage[0].stage = VK_SHADER_STAGE_VERTEX_BIT;
  633. stage[0].module = vert_module;
  634. stage[0].pName = "main";
  635. stage[1].sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
  636. stage[1].stage = VK_SHADER_STAGE_FRAGMENT_BIT;
  637. stage[1].module = frag_module;
  638. stage[1].pName = "main";
  639. VkVertexInputBindingDescription binding_desc[1] = {};
  640. binding_desc[0].stride = sizeof(ImDrawVert);
  641. binding_desc[0].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
  642. VkVertexInputAttributeDescription attribute_desc[3] = {};
  643. attribute_desc[0].location = 0;
  644. attribute_desc[0].binding = binding_desc[0].binding;
  645. attribute_desc[0].format = VK_FORMAT_R32G32_SFLOAT;
  646. attribute_desc[0].offset = (size_t)(&((ImDrawVert*)0)->pos);
  647. attribute_desc[1].location = 1;
  648. attribute_desc[1].binding = binding_desc[0].binding;
  649. attribute_desc[1].format = VK_FORMAT_R32G32_SFLOAT;
  650. attribute_desc[1].offset = (size_t)(&((ImDrawVert*)0)->uv);
  651. attribute_desc[2].location = 2;
  652. attribute_desc[2].binding = binding_desc[0].binding;
  653. attribute_desc[2].format = VK_FORMAT_R8G8B8A8_UNORM;
  654. attribute_desc[2].offset = (size_t)(&((ImDrawVert*)0)->col);
  655. VkPipelineVertexInputStateCreateInfo vertex_info = {};
  656. vertex_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
  657. vertex_info.vertexBindingDescriptionCount = 1;
  658. vertex_info.pVertexBindingDescriptions = binding_desc;
  659. vertex_info.vertexAttributeDescriptionCount = 3;
  660. vertex_info.pVertexAttributeDescriptions = attribute_desc;
  661. VkPipelineInputAssemblyStateCreateInfo ia_info = {};
  662. ia_info.sType = VK_STRUCTURE_TYPE_PIPELINE_INPUT_ASSEMBLY_STATE_CREATE_INFO;
  663. ia_info.topology = VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST;
  664. VkPipelineViewportStateCreateInfo viewport_info = {};
  665. viewport_info.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;
  666. viewport_info.viewportCount = 1;
  667. viewport_info.scissorCount = 1;
  668. VkPipelineRasterizationStateCreateInfo raster_info = {};
  669. raster_info.sType = VK_STRUCTURE_TYPE_PIPELINE_RASTERIZATION_STATE_CREATE_INFO;
  670. raster_info.polygonMode = VK_POLYGON_MODE_FILL;
  671. raster_info.cullMode = VK_CULL_MODE_NONE;
  672. raster_info.frontFace = VK_FRONT_FACE_COUNTER_CLOCKWISE;
  673. raster_info.lineWidth = 1.0f;
  674. VkPipelineMultisampleStateCreateInfo ms_info = {};
  675. ms_info.sType = VK_STRUCTURE_TYPE_PIPELINE_MULTISAMPLE_STATE_CREATE_INFO;
  676. ms_info.rasterizationSamples = VK_SAMPLE_COUNT_1_BIT;
  677. VkPipelineColorBlendAttachmentState color_attachment[1] = {};
  678. color_attachment[0].blendEnable = VK_TRUE;
  679. color_attachment[0].srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA;
  680. color_attachment[0].dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  681. color_attachment[0].colorBlendOp = VK_BLEND_OP_ADD;
  682. color_attachment[0].srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA;
  683. color_attachment[0].dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO;
  684. color_attachment[0].alphaBlendOp = VK_BLEND_OP_ADD;
  685. color_attachment[0].colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT;
  686. VkPipelineDepthStencilStateCreateInfo depth_info = {};
  687. depth_info.sType = VK_STRUCTURE_TYPE_PIPELINE_DEPTH_STENCIL_STATE_CREATE_INFO;
  688. VkPipelineColorBlendStateCreateInfo blend_info = {};
  689. blend_info.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO;
  690. blend_info.attachmentCount = 1;
  691. blend_info.pAttachments = color_attachment;
  692. VkDynamicState dynamic_states[2] = { VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR };
  693. VkPipelineDynamicStateCreateInfo dynamic_state = {};
  694. dynamic_state.sType = VK_STRUCTURE_TYPE_PIPELINE_DYNAMIC_STATE_CREATE_INFO;
  695. dynamic_state.dynamicStateCount = 2;
  696. dynamic_state.pDynamicStates = dynamic_states;
  697. VkGraphicsPipelineCreateInfo info = {};
  698. info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
  699. info.flags = g_PipelineCreateFlags;
  700. info.stageCount = 2;
  701. info.pStages = stage;
  702. info.pVertexInputState = &vertex_info;
  703. info.pInputAssemblyState = &ia_info;
  704. info.pViewportState = &viewport_info;
  705. info.pRasterizationState = &raster_info;
  706. info.pMultisampleState = &ms_info;
  707. info.pDepthStencilState = &depth_info;
  708. info.pColorBlendState = &blend_info;
  709. info.pDynamicState = &dynamic_state;
  710. info.layout = g_PipelineLayout;
  711. info.renderPass = g_RenderPass;
  712. err = vkCreateGraphicsPipelines(g_Device, g_PipelineCache, 1, &info, g_Allocator, &g_Pipeline);
  713. ImGui_ImplGlfwVulkan_VkResult(err);
  714. vkDestroyShaderModule(g_Device, vert_module, g_Allocator);
  715. vkDestroyShaderModule(g_Device, frag_module, g_Allocator);
  716. return true;
  717. }
  718. void ImGui_ImplGlfwVulkan_InvalidateFontUploadObjects()
  719. {
  720. if (g_UploadBuffer)
  721. {
  722. vkDestroyBuffer(g_Device, g_UploadBuffer, g_Allocator);
  723. g_UploadBuffer = VK_NULL_HANDLE;
  724. }
  725. if (g_UploadBufferMemory)
  726. {
  727. vkFreeMemory(g_Device, g_UploadBufferMemory, g_Allocator);
  728. g_UploadBufferMemory = VK_NULL_HANDLE;
  729. }
  730. }
  731. void ImGui_ImplGlfwVulkan_InvalidateDeviceObjects()
  732. {
  733. ImGui_ImplGlfwVulkan_InvalidateFontUploadObjects();
  734. for (int i=0; i<IMGUI_VK_QUEUED_FRAMES; i++)
  735. {
  736. if (g_VertexBuffer[i])
  737. vkDestroyBuffer(g_Device, g_VertexBuffer[i], g_Allocator);
  738. if (g_VertexBufferMemory[i])
  739. vkFreeMemory(g_Device, g_VertexBufferMemory[i], g_Allocator);
  740. if (g_IndexBuffer[i])
  741. vkDestroyBuffer(g_Device, g_IndexBuffer[i], g_Allocator);
  742. if (g_IndexBufferMemory[i])
  743. vkFreeMemory(g_Device, g_IndexBufferMemory[i], g_Allocator);
  744. }
  745. if (g_FontView)
  746. vkDestroyImageView(g_Device, g_FontView, g_Allocator);
  747. if (g_FontImage)
  748. vkDestroyImage(g_Device, g_FontImage, g_Allocator);
  749. if (g_FontMemory)
  750. vkFreeMemory(g_Device, g_FontMemory, g_Allocator);
  751. if (g_FontSampler)
  752. vkDestroySampler(g_Device, g_FontSampler, g_Allocator);
  753. if (g_DescriptorSetLayout)
  754. vkDestroyDescriptorSetLayout(g_Device, g_DescriptorSetLayout, g_Allocator);
  755. if (g_PipelineLayout)
  756. vkDestroyPipelineLayout(g_Device, g_PipelineLayout, g_Allocator);
  757. if (g_Pipeline)
  758. vkDestroyPipeline(g_Device, g_Pipeline, g_Allocator);
  759. }
  760. bool ImGui_ImplGlfwVulkan_Init(GLFWwindow* window, bool install_callbacks, ImGui_ImplGlfwVulkan_Init_Data *init_data)
  761. {
  762. g_Allocator = init_data->allocator;
  763. g_Gpu = init_data->gpu;
  764. g_Device = init_data->device;
  765. g_RenderPass = init_data->render_pass;
  766. g_PipelineCache = init_data->pipeline_cache;
  767. g_DescriptorPool = init_data->descriptor_pool;
  768. g_CheckVkResult = init_data->check_vk_result;
  769. g_Window = window;
  770. ImGuiIO& io = ImGui::GetIO();
  771. io.KeyMap[ImGuiKey_Tab] = GLFW_KEY_TAB; // Keyboard mapping. ImGui will use those indices to peek into the io.KeyDown[] array.
  772. io.KeyMap[ImGuiKey_LeftArrow] = GLFW_KEY_LEFT;
  773. io.KeyMap[ImGuiKey_RightArrow] = GLFW_KEY_RIGHT;
  774. io.KeyMap[ImGuiKey_UpArrow] = GLFW_KEY_UP;
  775. io.KeyMap[ImGuiKey_DownArrow] = GLFW_KEY_DOWN;
  776. io.KeyMap[ImGuiKey_PageUp] = GLFW_KEY_PAGE_UP;
  777. io.KeyMap[ImGuiKey_PageDown] = GLFW_KEY_PAGE_DOWN;
  778. io.KeyMap[ImGuiKey_Home] = GLFW_KEY_HOME;
  779. io.KeyMap[ImGuiKey_End] = GLFW_KEY_END;
  780. io.KeyMap[ImGuiKey_Delete] = GLFW_KEY_DELETE;
  781. io.KeyMap[ImGuiKey_Backspace] = GLFW_KEY_BACKSPACE;
  782. io.KeyMap[ImGuiKey_Enter] = GLFW_KEY_ENTER;
  783. io.KeyMap[ImGuiKey_Escape] = GLFW_KEY_ESCAPE;
  784. io.KeyMap[ImGuiKey_A] = GLFW_KEY_A;
  785. io.KeyMap[ImGuiKey_C] = GLFW_KEY_C;
  786. io.KeyMap[ImGuiKey_V] = GLFW_KEY_V;
  787. io.KeyMap[ImGuiKey_X] = GLFW_KEY_X;
  788. io.KeyMap[ImGuiKey_Y] = GLFW_KEY_Y;
  789. io.KeyMap[ImGuiKey_Z] = GLFW_KEY_Z;
  790. 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.
  791. io.SetClipboardTextFn = ImGui_ImplGlfwVulkan_SetClipboardText;
  792. io.GetClipboardTextFn = ImGui_ImplGlfwVulkan_GetClipboardText;
  793. #ifdef _WIN32
  794. io.ImeWindowHandle = glfwGetWin32Window(g_Window);
  795. #endif
  796. if (install_callbacks)
  797. {
  798. glfwSetMouseButtonCallback(window, ImGui_ImplGlfwVulkan_MouseButtonCallback);
  799. glfwSetScrollCallback(window, ImGui_ImplGlfwVulkan_ScrollCallback);
  800. glfwSetKeyCallback(window, ImGui_ImplGlfwVulkan_KeyCallback);
  801. glfwSetCharCallback(window, ImGui_ImplGlfwVulkan_CharCallback);
  802. }
  803. ImGui_ImplGlfwVulkan_CreateDeviceObjects();
  804. return true;
  805. }
  806. void ImGui_ImplGlfwVulkan_Shutdown()
  807. {
  808. ImGui_ImplGlfwVulkan_InvalidateDeviceObjects();
  809. ImGui::Shutdown();
  810. }
  811. void ImGui_ImplGlfwVulkan_NewFrame()
  812. {
  813. ImGuiIO& io = ImGui::GetIO();
  814. // Setup display size (every frame to accommodate for window resizing)
  815. int w, h;
  816. int display_w, display_h;
  817. glfwGetWindowSize(g_Window, &w, &h);
  818. glfwGetFramebufferSize(g_Window, &display_w, &display_h);
  819. io.DisplaySize = ImVec2((float)w, (float)h);
  820. io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0);
  821. // Setup time step
  822. double current_time = glfwGetTime();
  823. io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
  824. g_Time = current_time;
  825. // Setup inputs
  826. // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
  827. if (glfwGetWindowAttrib(g_Window, GLFW_FOCUSED))
  828. {
  829. double mouse_x, mouse_y;
  830. glfwGetCursorPos(g_Window, &mouse_x, &mouse_y);
  831. io.MousePos = ImVec2((float)mouse_x, (float)mouse_y); // Mouse position in screen coordinates (set to -1,-1 if no mouse / on another screen, etc.)
  832. }
  833. else
  834. {
  835. io.MousePos = ImVec2(-1,-1);
  836. }
  837. for (int i = 0; i < 3; i++)
  838. {
  839. io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
  840. g_MousePressed[i] = false;
  841. }
  842. io.MouseWheel = g_MouseWheel;
  843. g_MouseWheel = 0.0f;
  844. // Hide OS mouse cursor if ImGui is drawing it
  845. glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
  846. // Start the frame
  847. ImGui::NewFrame();
  848. }
  849. void ImGui_ImplGlfwVulkan_Render(VkCommandBuffer command_buffer)
  850. {
  851. g_CommandBuffer = command_buffer;
  852. ImGui::Render();
  853. g_CommandBuffer = VK_NULL_HANDLE;
  854. g_FrameIndex = (g_FrameIndex + 1) % IMGUI_VK_QUEUED_FRAMES;
  855. }