imgui_impl_sdlgpu3.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. // dear imgui: Renderer Backend for SDL_GPU
  2. // This needs to be used along with the SDL3 Platform Backend
  3. // Implemented features:
  4. // [X] Renderer: User texture binding. Use 'SDL_GPUTexture*' as texture identifier. Read the FAQ about ImTextureID/ImTextureRef! **IMPORTANT** Before 2025/08/08, ImTextureID was a reference to a SDL_GPUTextureSamplerBinding struct.
  5. // [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
  6. // [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
  7. // [X] Renderer: Multi-viewport support (multiple windows). Enable with 'io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable'.
  8. // The aim of imgui_impl_sdlgpu3.h/.cpp is to be usable in your engine without any modification.
  9. // IF YOU FEEL YOU NEED TO MAKE ANY CHANGE TO THIS CODE, please share them and your feedback at https://github.com/ocornut/imgui/
  10. // You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
  11. // Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
  12. // Learn about Dear ImGui:
  13. // - FAQ https://dearimgui.com/faq
  14. // - Getting Started https://dearimgui.com/getting-started
  15. // - Documentation https://dearimgui.com/docs (same as your local docs/ folder).
  16. // - Introduction, links and more at the top of imgui.cpp
  17. // Important note to the reader who wish to integrate imgui_impl_sdlgpu3.cpp/.h in their own engine/app.
  18. // - Unlike other backends, the user must call the function ImGui_ImplSDLGPU3_PrepareDrawData() BEFORE issuing a SDL_GPURenderPass containing ImGui_ImplSDLGPU3_RenderDrawData.
  19. // Calling the function is MANDATORY, otherwise the ImGui will not upload neither the vertex nor the index buffer for the GPU. See imgui_impl_sdlgpu3.cpp for more info.
  20. // CHANGELOG
  21. // 2025-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
  22. // 2025-08-08: *BREAKING* Changed ImTextureID type from SDL_GPUTextureSamplerBinding* to SDL_GPUTexture*, which is more natural and easier for user to manage. If you need to change the current sampler, you can access the ImGui_ImplSDLGPU3_RenderState struct. (#8866, #8163, #7998, #7988)
  23. // 2025-08-08: Expose SamplerDefault and SamplerCurrent in ImGui_ImplSDLGPU3_RenderState. Allow callback to change sampler.
  24. // 2025-06-25: Mapping transfer buffer for texture update use cycle=true. Fixes artifacts e.g. on Metal backend.
  25. // 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplSDLGPU3_CreateFontsTexture() and ImGui_ImplSDLGPU3_DestroyFontsTexture().
  26. // 2025-04-28: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
  27. // 2025-03-30: Made ImGui_ImplSDLGPU3_PrepareDrawData() reuse GPU Transfer Buffers which were unusually slow to recreate every frame. Much faster now.
  28. // 2025-03-21: Fixed typo in function name Imgui_ImplSDLGPU3_PrepareDrawData() -> ImGui_ImplSDLGPU3_PrepareDrawData().
  29. // 2025-01-16: Renamed ImGui_ImplSDLGPU3_InitInfo::GpuDevice to Device.
  30. // 2025-01-09: SDL_GPU: Added the SDL_GPU3 backend.
  31. #include "imgui.h"
  32. #ifndef IMGUI_DISABLE
  33. #include "imgui_impl_sdlgpu3.h"
  34. #include "imgui_impl_sdlgpu3_shaders.h"
  35. // SDL_GPU Data
  36. // Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplSDLGPU3_RenderDrawData()
  37. struct ImGui_ImplSDLGPU3_FrameData
  38. {
  39. SDL_GPUBuffer* VertexBuffer = nullptr;
  40. SDL_GPUTransferBuffer* VertexTransferBuffer = nullptr;
  41. uint32_t VertexBufferSize = 0;
  42. SDL_GPUBuffer* IndexBuffer = nullptr;
  43. SDL_GPUTransferBuffer* IndexTransferBuffer = nullptr;
  44. uint32_t IndexBufferSize = 0;
  45. };
  46. struct ImGui_ImplSDLGPU3_Data
  47. {
  48. ImGui_ImplSDLGPU3_InitInfo InitInfo;
  49. // Graphics pipeline & shaders
  50. SDL_GPUShader* VertexShader = nullptr;
  51. SDL_GPUShader* FragmentShader = nullptr;
  52. SDL_GPUGraphicsPipeline* Pipeline = nullptr;
  53. SDL_GPUSampler* TexSampler = nullptr;
  54. SDL_GPUTransferBuffer* TexTransferBuffer = nullptr;
  55. uint32_t TexTransferBufferSize = 0;
  56. // Frame data for main window
  57. ImGui_ImplSDLGPU3_FrameData MainWindowFrameData;
  58. };
  59. // Forward Declarations
  60. static void ImGui_ImplSDLGPU3_DestroyFrameData();
  61. //-----------------------------------------------------------------------------
  62. // FUNCTIONS
  63. //-----------------------------------------------------------------------------
  64. // Backend data stored in io.BackendRendererUserData to allow support for multiple Dear ImGui contexts
  65. // It is STRONGLY preferred that you use docking branch with multi-viewports (== single Dear ImGui context + multiple windows) instead of multiple Dear ImGui contexts.
  66. // FIXME: multi-context support has never been tested.
  67. static ImGui_ImplSDLGPU3_Data* ImGui_ImplSDLGPU3_GetBackendData()
  68. {
  69. return ImGui::GetCurrentContext() ? (ImGui_ImplSDLGPU3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
  70. }
  71. static void ImGui_ImplSDLGPU3_SetupRenderState(ImDrawData* draw_data, ImGui_ImplSDLGPU3_RenderState* render_state, SDL_GPUGraphicsPipeline* pipeline, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, ImGui_ImplSDLGPU3_FrameData* fd, uint32_t fb_width, uint32_t fb_height)
  72. {
  73. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  74. render_state->SamplerCurrent = render_state->SamplerCurrent = bd->TexSampler;
  75. // Bind graphics pipeline
  76. SDL_BindGPUGraphicsPipeline(render_pass, pipeline);
  77. // Bind Vertex And Index Buffers
  78. if (draw_data->TotalVtxCount > 0)
  79. {
  80. SDL_GPUBufferBinding vertex_buffer_binding = {};
  81. vertex_buffer_binding.buffer = fd->VertexBuffer;
  82. vertex_buffer_binding.offset = 0;
  83. SDL_GPUBufferBinding index_buffer_binding = {};
  84. index_buffer_binding.buffer = fd->IndexBuffer;
  85. index_buffer_binding.offset = 0;
  86. SDL_BindGPUVertexBuffers(render_pass,0, &vertex_buffer_binding, 1);
  87. SDL_BindGPUIndexBuffer(render_pass, &index_buffer_binding, sizeof(ImDrawIdx) == 2 ? SDL_GPU_INDEXELEMENTSIZE_16BIT : SDL_GPU_INDEXELEMENTSIZE_32BIT);
  88. }
  89. // Setup viewport
  90. SDL_GPUViewport viewport = {};
  91. viewport.x = 0;
  92. viewport.y = 0;
  93. viewport.w = (float)fb_width;
  94. viewport.h = (float)fb_height;
  95. viewport.min_depth = 0.0f;
  96. viewport.max_depth = 1.0f;
  97. SDL_SetGPUViewport(render_pass, &viewport);
  98. // Setup scale and translation
  99. // Our visible imgui space lies from draw_data->DisplayPps (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right). DisplayPos is (0,0) for single viewport apps.
  100. struct UBO { float scale[2]; float translation[2]; } ubo;
  101. ubo.scale[0] = 2.0f / draw_data->DisplaySize.x;
  102. ubo.scale[1] = 2.0f / draw_data->DisplaySize.y;
  103. ubo.translation[0] = -1.0f - draw_data->DisplayPos.x * ubo.scale[0];
  104. ubo.translation[1] = -1.0f - draw_data->DisplayPos.y * ubo.scale[1];
  105. SDL_PushGPUVertexUniformData(command_buffer, 0, &ubo, sizeof(UBO));
  106. }
  107. static void CreateOrResizeBuffers(SDL_GPUBuffer** buffer, SDL_GPUTransferBuffer** transferbuffer, uint32_t* old_size, uint32_t new_size, SDL_GPUBufferUsageFlags usage)
  108. {
  109. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  110. ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
  111. // FIXME-OPT: Not optimal, but this is fairly rarely called.
  112. SDL_WaitForGPUIdle(v->Device);
  113. SDL_ReleaseGPUBuffer(v->Device, *buffer);
  114. SDL_ReleaseGPUTransferBuffer(v->Device, *transferbuffer);
  115. SDL_GPUBufferCreateInfo buffer_info = {};
  116. buffer_info.usage = usage;
  117. buffer_info.size = new_size;
  118. buffer_info.props = 0;
  119. *buffer = SDL_CreateGPUBuffer(v->Device, &buffer_info);
  120. *old_size = new_size;
  121. IM_ASSERT(*buffer != nullptr && "Failed to create GPU Buffer, call SDL_GetError() for more information");
  122. SDL_GPUTransferBufferCreateInfo transferbuffer_info = {};
  123. transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
  124. transferbuffer_info.size = new_size;
  125. *transferbuffer = SDL_CreateGPUTransferBuffer(v->Device, &transferbuffer_info);
  126. IM_ASSERT(*transferbuffer != nullptr && "Failed to create GPU Transfer Buffer, call SDL_GetError() for more information");
  127. }
  128. // SDL_GPU doesn't allow copy passes to occur while a render or compute pass is bound!
  129. // The only way to allow a user to supply their own RenderPass (to render to a texture instead of the window for example),
  130. // is to split the upload part of ImGui_ImplSDLGPU3_RenderDrawData() to another function that needs to be called by the user before rendering.
  131. void ImGui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer)
  132. {
  133. // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
  134. int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
  135. int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
  136. if (fb_width <= 0 || fb_height <= 0 || draw_data->TotalVtxCount <= 0)
  137. return;
  138. // Catch up with texture updates. Most of the times, the list will have 1 element with an OK status, aka nothing to do.
  139. // (This almost always points to ImGui::GetPlatformIO().Textures[] but is part of ImDrawData to allow overriding or disabling texture updates).
  140. if (draw_data->Textures != nullptr)
  141. for (ImTextureData* tex : *draw_data->Textures)
  142. if (tex->Status != ImTextureStatus_OK)
  143. ImGui_ImplSDLGPU3_UpdateTexture(tex);
  144. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  145. ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
  146. ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
  147. uint32_t vertex_size = draw_data->TotalVtxCount * sizeof(ImDrawVert);
  148. uint32_t index_size = draw_data->TotalIdxCount * sizeof(ImDrawIdx);
  149. if (fd->VertexBuffer == nullptr || fd->VertexBufferSize < vertex_size)
  150. CreateOrResizeBuffers(&fd->VertexBuffer, &fd->VertexTransferBuffer, &fd->VertexBufferSize, vertex_size, SDL_GPU_BUFFERUSAGE_VERTEX);
  151. if (fd->IndexBuffer == nullptr || fd->IndexBufferSize < index_size)
  152. CreateOrResizeBuffers(&fd->IndexBuffer, &fd->IndexTransferBuffer, &fd->IndexBufferSize, index_size, SDL_GPU_BUFFERUSAGE_INDEX);
  153. ImDrawVert* vtx_dst = (ImDrawVert*)SDL_MapGPUTransferBuffer(v->Device, fd->VertexTransferBuffer, true);
  154. ImDrawIdx* idx_dst = (ImDrawIdx*)SDL_MapGPUTransferBuffer(v->Device, fd->IndexTransferBuffer, true);
  155. for (const ImDrawList* draw_list : draw_data->CmdLists)
  156. {
  157. memcpy(vtx_dst, draw_list->VtxBuffer.Data, draw_list->VtxBuffer.Size * sizeof(ImDrawVert));
  158. memcpy(idx_dst, draw_list->IdxBuffer.Data, draw_list->IdxBuffer.Size * sizeof(ImDrawIdx));
  159. vtx_dst += draw_list->VtxBuffer.Size;
  160. idx_dst += draw_list->IdxBuffer.Size;
  161. }
  162. SDL_UnmapGPUTransferBuffer(v->Device, fd->VertexTransferBuffer);
  163. SDL_UnmapGPUTransferBuffer(v->Device, fd->IndexTransferBuffer);
  164. SDL_GPUTransferBufferLocation vertex_buffer_location = {};
  165. vertex_buffer_location.offset = 0;
  166. vertex_buffer_location.transfer_buffer = fd->VertexTransferBuffer;
  167. SDL_GPUTransferBufferLocation index_buffer_location = {};
  168. index_buffer_location.offset = 0;
  169. index_buffer_location.transfer_buffer = fd->IndexTransferBuffer;
  170. SDL_GPUBufferRegion vertex_buffer_region = {};
  171. vertex_buffer_region.buffer = fd->VertexBuffer;
  172. vertex_buffer_region.offset = 0;
  173. vertex_buffer_region.size = vertex_size;
  174. SDL_GPUBufferRegion index_buffer_region = {};
  175. index_buffer_region.buffer = fd->IndexBuffer;
  176. index_buffer_region.offset = 0;
  177. index_buffer_region.size = index_size;
  178. SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(command_buffer);
  179. SDL_UploadToGPUBuffer(copy_pass, &vertex_buffer_location, &vertex_buffer_region, true);
  180. SDL_UploadToGPUBuffer(copy_pass, &index_buffer_location, &index_buffer_region, true);
  181. SDL_EndGPUCopyPass(copy_pass);
  182. }
  183. void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline)
  184. {
  185. // Avoid rendering when minimized, scale coordinates for retina displays (screen coordinates != framebuffer coordinates)
  186. int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x);
  187. int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y);
  188. if (fb_width <= 0 || fb_height <= 0)
  189. return;
  190. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  191. ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
  192. if (pipeline == nullptr)
  193. pipeline = bd->Pipeline;
  194. // Will project scissor/clipping rectangles into framebuffer space
  195. ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
  196. ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
  197. // Setup render state structure (for callbacks and custom texture bindings)
  198. ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
  199. ImGui_ImplSDLGPU3_RenderState render_state;
  200. render_state.Device = bd->InitInfo.Device;
  201. render_state.SamplerDefault = render_state.SamplerCurrent = bd->TexSampler;
  202. platform_io.Renderer_RenderState = &render_state;
  203. ImGui_ImplSDLGPU3_SetupRenderState(draw_data, &render_state, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
  204. // Render command lists
  205. // (Because we merged all buffers into a single one, we maintain our own offset into them)
  206. int global_vtx_offset = 0;
  207. int global_idx_offset = 0;
  208. for (const ImDrawList* draw_list : draw_data->CmdLists)
  209. {
  210. for (int cmd_i = 0; cmd_i < draw_list->CmdBuffer.Size; cmd_i++)
  211. {
  212. const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i];
  213. if (pcmd->UserCallback != nullptr)
  214. {
  215. // User callback, registered via ImDrawList::AddCallback()
  216. // (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
  217. if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
  218. ImGui_ImplSDLGPU3_SetupRenderState(draw_data, &render_state, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
  219. else
  220. pcmd->UserCallback(draw_list, pcmd);
  221. }
  222. else
  223. {
  224. // Project scissor/clipping rectangles into framebuffer space
  225. ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
  226. ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
  227. // Clamp to viewport as SDL_SetGPUScissor() won't accept values that are off bounds
  228. if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
  229. if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
  230. if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; }
  231. if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; }
  232. if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y)
  233. continue;
  234. // Apply scissor/clipping rectangle
  235. SDL_Rect scissor_rect = {};
  236. scissor_rect.x = (int)clip_min.x;
  237. scissor_rect.y = (int)clip_min.y;
  238. scissor_rect.w = (int)(clip_max.x - clip_min.x);
  239. scissor_rect.h = (int)(clip_max.y - clip_min.y);
  240. SDL_SetGPUScissor(render_pass,&scissor_rect);
  241. // Bind DescriptorSet with font or user texture
  242. SDL_GPUTextureSamplerBinding texture_sampler_binding;
  243. texture_sampler_binding.texture = (SDL_GPUTexture*)(intptr_t)pcmd->GetTexID();
  244. texture_sampler_binding.sampler = render_state.SamplerCurrent;
  245. SDL_BindGPUFragmentSamplers(render_pass, 0, &texture_sampler_binding, 1);
  246. // Draw
  247. // **IF YOU GET A CRASH HERE** In 1.92.2 on 2025/08/08 we have changed ImTextureID to store 'SDL_GPUTexture*' instead of storing 'SDL_GPUTextureSamplerBinding'.
  248. // Any code loading custom texture using this backend needs to be updated.
  249. SDL_DrawGPUIndexedPrimitives(render_pass, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
  250. }
  251. }
  252. global_idx_offset += draw_list->IdxBuffer.Size;
  253. global_vtx_offset += draw_list->VtxBuffer.Size;
  254. }
  255. // Note: at this point both SDL_SetGPUViewport() and SDL_SetGPUScissor() have been called.
  256. // Our last values will leak into user/application rendering if you forgot to call SDL_SetGPUViewport() and SDL_SetGPUScissor() yourself to explicitly set that state
  257. // In theory we should aim to backup/restore those values but I am not sure this is possible.
  258. // We perform a call to SDL_SetGPUScissor() to set back a full viewport which is likely to fix things for 99% users but technically this is not perfect. (See github #4644)
  259. SDL_Rect scissor_rect { 0, 0, fb_width, fb_height };
  260. SDL_SetGPUScissor(render_pass, &scissor_rect);
  261. }
  262. static void ImGui_ImplSDLGPU3_DestroyTexture(ImTextureData* tex)
  263. {
  264. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  265. SDL_GPUTexture* raw_tex = (SDL_GPUTexture*)(intptr_t)tex->GetTexID();
  266. if (raw_tex != nullptr)
  267. SDL_ReleaseGPUTexture(bd->InitInfo.Device, raw_tex);
  268. // Clear identifiers and mark as destroyed (in order to allow e.g. calling InvalidateDeviceObjects while running)
  269. tex->SetTexID(ImTextureID_Invalid);
  270. tex->SetStatus(ImTextureStatus_Destroyed);
  271. }
  272. void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex)
  273. {
  274. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  275. ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
  276. if (tex->Status == ImTextureStatus_WantCreate)
  277. {
  278. // Create and upload new texture to graphics system
  279. //IMGUI_DEBUG_LOG("UpdateTexture #%03d: WantCreate %dx%d\n", tex->UniqueID, tex->Width, tex->Height);
  280. IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == nullptr);
  281. IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
  282. // Create texture
  283. SDL_GPUTextureCreateInfo texture_info = {};
  284. texture_info.type = SDL_GPU_TEXTURETYPE_2D;
  285. texture_info.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
  286. texture_info.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER;
  287. texture_info.width = tex->Width;
  288. texture_info.height = tex->Height;
  289. texture_info.layer_count_or_depth = 1;
  290. texture_info.num_levels = 1;
  291. texture_info.sample_count = SDL_GPU_SAMPLECOUNT_1;
  292. SDL_GPUTexture* raw_tex = SDL_CreateGPUTexture(v->Device, &texture_info);
  293. IM_ASSERT(raw_tex != nullptr && "Failed to create font texture, call SDL_GetError() for more info");
  294. // Store identifiers
  295. tex->SetTexID((ImTextureID)(intptr_t)raw_tex);
  296. }
  297. if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates)
  298. {
  299. SDL_GPUTexture* raw_tex = (SDL_GPUTexture*)(intptr_t)tex->GetTexID();
  300. IM_ASSERT(tex->Format == ImTextureFormat_RGBA32);
  301. // Update full texture or selected blocks. We only ever write to textures regions which have never been used before!
  302. // This backend choose to use tex->UpdateRect but you can use tex->Updates[] to upload individual regions.
  303. // We could use the smaller rect on _WantCreate but using the full rect allows us to clear the texture.
  304. const int upload_x = (tex->Status == ImTextureStatus_WantCreate) ? 0 : tex->UpdateRect.x;
  305. const int upload_y = (tex->Status == ImTextureStatus_WantCreate) ? 0 : tex->UpdateRect.y;
  306. const int upload_w = (tex->Status == ImTextureStatus_WantCreate) ? tex->Width : tex->UpdateRect.w;
  307. const int upload_h = (tex->Status == ImTextureStatus_WantCreate) ? tex->Height : tex->UpdateRect.h;
  308. uint32_t upload_pitch = upload_w * tex->BytesPerPixel;
  309. uint32_t upload_size = upload_w * upload_h * tex->BytesPerPixel;
  310. // Create transfer buffer
  311. if (bd->TexTransferBufferSize < upload_size)
  312. {
  313. SDL_ReleaseGPUTransferBuffer(v->Device, bd->TexTransferBuffer);
  314. SDL_GPUTransferBufferCreateInfo transferbuffer_info = {};
  315. transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD;
  316. transferbuffer_info.size = upload_size + 1024;
  317. bd->TexTransferBufferSize = upload_size + 1024;
  318. bd->TexTransferBuffer = SDL_CreateGPUTransferBuffer(v->Device, &transferbuffer_info);
  319. IM_ASSERT(bd->TexTransferBuffer != nullptr && "Failed to create font transfer buffer, call SDL_GetError() for more information");
  320. }
  321. // Copy to transfer buffer
  322. {
  323. void* texture_ptr = SDL_MapGPUTransferBuffer(v->Device, bd->TexTransferBuffer, true);
  324. for (int y = 0; y < upload_h; y++)
  325. memcpy((void*)((uintptr_t)texture_ptr + y * upload_pitch), tex->GetPixelsAt(upload_x, upload_y + y), upload_pitch);
  326. SDL_UnmapGPUTransferBuffer(v->Device, bd->TexTransferBuffer);
  327. }
  328. SDL_GPUTextureTransferInfo transfer_info = {};
  329. transfer_info.offset = 0;
  330. transfer_info.transfer_buffer = bd->TexTransferBuffer;
  331. SDL_GPUTextureRegion texture_region = {};
  332. texture_region.texture = raw_tex;
  333. texture_region.x = (Uint32)upload_x;
  334. texture_region.y = (Uint32)upload_y;
  335. texture_region.w = (Uint32)upload_w;
  336. texture_region.h = (Uint32)upload_h;
  337. texture_region.d = 1;
  338. // Upload
  339. {
  340. SDL_GPUCommandBuffer* cmd = SDL_AcquireGPUCommandBuffer(v->Device);
  341. SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(cmd);
  342. SDL_UploadToGPUTexture(copy_pass, &transfer_info, &texture_region, false);
  343. SDL_EndGPUCopyPass(copy_pass);
  344. SDL_SubmitGPUCommandBuffer(cmd);
  345. }
  346. tex->SetStatus(ImTextureStatus_OK);
  347. }
  348. if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0)
  349. ImGui_ImplSDLGPU3_DestroyTexture(tex);
  350. }
  351. static void ImGui_ImplSDLGPU3_CreateShaders()
  352. {
  353. // Create the shader modules
  354. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  355. ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
  356. const char* driver = SDL_GetGPUDeviceDriver(v->Device);
  357. SDL_GPUShaderCreateInfo vertex_shader_info = {};
  358. vertex_shader_info.entrypoint = "main";
  359. vertex_shader_info.stage = SDL_GPU_SHADERSTAGE_VERTEX;
  360. vertex_shader_info.num_uniform_buffers = 1;
  361. vertex_shader_info.num_storage_buffers = 0;
  362. vertex_shader_info.num_storage_textures = 0;
  363. vertex_shader_info.num_samplers = 0;
  364. SDL_GPUShaderCreateInfo fragment_shader_info = {};
  365. fragment_shader_info.entrypoint = "main";
  366. fragment_shader_info.stage = SDL_GPU_SHADERSTAGE_FRAGMENT;
  367. fragment_shader_info.num_samplers = 1;
  368. fragment_shader_info.num_storage_buffers = 0;
  369. fragment_shader_info.num_storage_textures = 0;
  370. fragment_shader_info.num_uniform_buffers = 0;
  371. if (strcmp(driver, "vulkan") == 0)
  372. {
  373. vertex_shader_info.format = SDL_GPU_SHADERFORMAT_SPIRV;
  374. vertex_shader_info.code = spirv_vertex;
  375. vertex_shader_info.code_size = sizeof(spirv_vertex);
  376. fragment_shader_info.format = SDL_GPU_SHADERFORMAT_SPIRV;
  377. fragment_shader_info.code = spirv_fragment;
  378. fragment_shader_info.code_size = sizeof(spirv_fragment);
  379. }
  380. else if (strcmp(driver, "direct3d12") == 0)
  381. {
  382. vertex_shader_info.format = SDL_GPU_SHADERFORMAT_DXBC;
  383. vertex_shader_info.code = dxbc_vertex;
  384. vertex_shader_info.code_size = sizeof(dxbc_vertex);
  385. fragment_shader_info.format = SDL_GPU_SHADERFORMAT_DXBC;
  386. fragment_shader_info.code = dxbc_fragment;
  387. fragment_shader_info.code_size = sizeof(dxbc_fragment);
  388. }
  389. #ifdef __APPLE__
  390. else
  391. {
  392. vertex_shader_info.entrypoint = "main0";
  393. vertex_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
  394. vertex_shader_info.code = metallib_vertex;
  395. vertex_shader_info.code_size = sizeof(metallib_vertex);
  396. fragment_shader_info.entrypoint = "main0";
  397. fragment_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB;
  398. fragment_shader_info.code = metallib_fragment;
  399. fragment_shader_info.code_size = sizeof(metallib_fragment);
  400. }
  401. #endif
  402. bd->VertexShader = SDL_CreateGPUShader(v->Device, &vertex_shader_info);
  403. bd->FragmentShader = SDL_CreateGPUShader(v->Device, &fragment_shader_info);
  404. IM_ASSERT(bd->VertexShader != nullptr && "Failed to create vertex shader, call SDL_GetError() for more information");
  405. IM_ASSERT(bd->FragmentShader != nullptr && "Failed to create fragment shader, call SDL_GetError() for more information");
  406. }
  407. static void ImGui_ImplSDLGPU3_CreateGraphicsPipeline()
  408. {
  409. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  410. ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
  411. ImGui_ImplSDLGPU3_CreateShaders();
  412. SDL_GPUVertexBufferDescription vertex_buffer_desc[1];
  413. vertex_buffer_desc[0].slot = 0;
  414. vertex_buffer_desc[0].input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX;
  415. vertex_buffer_desc[0].instance_step_rate = 0;
  416. vertex_buffer_desc[0].pitch = sizeof(ImDrawVert);
  417. SDL_GPUVertexAttribute vertex_attributes[3];
  418. vertex_attributes[0].buffer_slot = 0;
  419. vertex_attributes[0].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
  420. vertex_attributes[0].location = 0;
  421. vertex_attributes[0].offset = offsetof(ImDrawVert,pos);
  422. vertex_attributes[1].buffer_slot = 0;
  423. vertex_attributes[1].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2;
  424. vertex_attributes[1].location = 1;
  425. vertex_attributes[1].offset = offsetof(ImDrawVert, uv);
  426. vertex_attributes[2].buffer_slot = 0;
  427. vertex_attributes[2].format = SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM;
  428. vertex_attributes[2].location = 2;
  429. vertex_attributes[2].offset = offsetof(ImDrawVert, col);
  430. SDL_GPUVertexInputState vertex_input_state = {};
  431. vertex_input_state.num_vertex_attributes = 3;
  432. vertex_input_state.vertex_attributes = vertex_attributes;
  433. vertex_input_state.num_vertex_buffers = 1;
  434. vertex_input_state.vertex_buffer_descriptions = vertex_buffer_desc;
  435. SDL_GPURasterizerState rasterizer_state = {};
  436. rasterizer_state.fill_mode = SDL_GPU_FILLMODE_FILL;
  437. rasterizer_state.cull_mode = SDL_GPU_CULLMODE_NONE;
  438. rasterizer_state.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE;
  439. rasterizer_state.enable_depth_bias = false;
  440. rasterizer_state.enable_depth_clip = false;
  441. SDL_GPUMultisampleState multisample_state = {};
  442. multisample_state.sample_count = v->MSAASamples;
  443. multisample_state.enable_mask = false;
  444. SDL_GPUDepthStencilState depth_stencil_state = {};
  445. depth_stencil_state.enable_depth_test = false;
  446. depth_stencil_state.enable_depth_write = false;
  447. depth_stencil_state.enable_stencil_test = false;
  448. SDL_GPUColorTargetBlendState blend_state = {};
  449. blend_state.enable_blend = true;
  450. blend_state.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA;
  451. blend_state.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
  452. blend_state.color_blend_op = SDL_GPU_BLENDOP_ADD;
  453. blend_state.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE;
  454. blend_state.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA;
  455. blend_state.alpha_blend_op = SDL_GPU_BLENDOP_ADD;
  456. blend_state.color_write_mask = SDL_GPU_COLORCOMPONENT_R | SDL_GPU_COLORCOMPONENT_G | SDL_GPU_COLORCOMPONENT_B | SDL_GPU_COLORCOMPONENT_A;
  457. SDL_GPUColorTargetDescription color_target_desc[1];
  458. color_target_desc[0].format = v->ColorTargetFormat;
  459. color_target_desc[0].blend_state = blend_state;
  460. SDL_GPUGraphicsPipelineTargetInfo target_info = {};
  461. target_info.num_color_targets = 1;
  462. target_info.color_target_descriptions = color_target_desc;
  463. target_info.has_depth_stencil_target = false;
  464. SDL_GPUGraphicsPipelineCreateInfo pipeline_info = {};
  465. pipeline_info.vertex_shader = bd->VertexShader;
  466. pipeline_info.fragment_shader = bd->FragmentShader;
  467. pipeline_info.vertex_input_state = vertex_input_state;
  468. pipeline_info.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST;
  469. pipeline_info.rasterizer_state = rasterizer_state;
  470. pipeline_info.multisample_state = multisample_state;
  471. pipeline_info.depth_stencil_state = depth_stencil_state;
  472. pipeline_info.target_info = target_info;
  473. bd->Pipeline = SDL_CreateGPUGraphicsPipeline(v->Device, &pipeline_info);
  474. IM_ASSERT(bd->Pipeline != nullptr && "Failed to create graphics pipeline, call SDL_GetError() for more information");
  475. }
  476. void ImGui_ImplSDLGPU3_CreateDeviceObjects()
  477. {
  478. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  479. ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
  480. ImGui_ImplSDLGPU3_DestroyDeviceObjects();
  481. if (bd->TexSampler == nullptr)
  482. {
  483. // Bilinear sampling is required by default. Set 'io.Fonts->Flags |= ImFontAtlasFlags_NoBakedLines' or 'style.AntiAliasedLinesUseTex = false' to allow point/nearest sampling.
  484. SDL_GPUSamplerCreateInfo sampler_info = {};
  485. sampler_info.min_filter = SDL_GPU_FILTER_LINEAR;
  486. sampler_info.mag_filter = SDL_GPU_FILTER_LINEAR;
  487. sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR;
  488. sampler_info.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
  489. sampler_info.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
  490. sampler_info.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE;
  491. sampler_info.mip_lod_bias = 0.0f;
  492. sampler_info.min_lod = -1000.0f;
  493. sampler_info.max_lod = 1000.0f;
  494. sampler_info.enable_anisotropy = false;
  495. sampler_info.max_anisotropy = 1.0f;
  496. sampler_info.enable_compare = false;
  497. bd->TexSampler = SDL_CreateGPUSampler(v->Device, &sampler_info);
  498. IM_ASSERT(bd->TexSampler != nullptr && "Failed to create font sampler, call SDL_GetError() for more information");
  499. }
  500. ImGui_ImplSDLGPU3_CreateGraphicsPipeline();
  501. }
  502. void ImGui_ImplSDLGPU3_DestroyFrameData()
  503. {
  504. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  505. ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
  506. ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData;
  507. SDL_ReleaseGPUBuffer(v->Device, fd->VertexBuffer);
  508. SDL_ReleaseGPUBuffer(v->Device, fd->IndexBuffer);
  509. SDL_ReleaseGPUTransferBuffer(v->Device, fd->VertexTransferBuffer);
  510. SDL_ReleaseGPUTransferBuffer(v->Device, fd->IndexTransferBuffer);
  511. fd->VertexBuffer = fd->IndexBuffer = nullptr;
  512. fd->VertexTransferBuffer = fd->IndexTransferBuffer = nullptr;
  513. fd->VertexBufferSize = fd->IndexBufferSize = 0;
  514. }
  515. void ImGui_ImplSDLGPU3_DestroyDeviceObjects()
  516. {
  517. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  518. ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo;
  519. ImGui_ImplSDLGPU3_DestroyFrameData();
  520. // Destroy all textures
  521. for (ImTextureData* tex : ImGui::GetPlatformIO().Textures)
  522. if (tex->RefCount == 1)
  523. ImGui_ImplSDLGPU3_DestroyTexture(tex);
  524. if (bd->TexTransferBuffer) { SDL_ReleaseGPUTransferBuffer(v->Device, bd->TexTransferBuffer); bd->TexTransferBuffer = nullptr; }
  525. if (bd->VertexShader) { SDL_ReleaseGPUShader(v->Device, bd->VertexShader); bd->VertexShader = nullptr; }
  526. if (bd->FragmentShader) { SDL_ReleaseGPUShader(v->Device, bd->FragmentShader); bd->FragmentShader = nullptr; }
  527. if (bd->TexSampler) { SDL_ReleaseGPUSampler(v->Device, bd->TexSampler); bd->TexSampler = nullptr; }
  528. if (bd->Pipeline) { SDL_ReleaseGPUGraphicsPipeline(v->Device, bd->Pipeline); bd->Pipeline = nullptr; }
  529. }
  530. static void ImGui_ImplSDLGPU3_InitMultiViewportSupport();
  531. static void ImGui_ImplSDLGPU3_ShutdownMultiViewportSupport();
  532. bool ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info)
  533. {
  534. ImGuiIO& io = ImGui::GetIO();
  535. IMGUI_CHECKVERSION();
  536. IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!");
  537. // Setup backend capabilities flags
  538. ImGui_ImplSDLGPU3_Data* bd = IM_NEW(ImGui_ImplSDLGPU3_Data)();
  539. io.BackendRendererUserData = (void*)bd;
  540. io.BackendRendererName = "imgui_impl_sdlgpu3";
  541. io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes.
  542. io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; // We can honor ImGuiPlatformIO::Textures[] requests during render.
  543. io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; // We can create multi-viewports on the Renderer side (optional)
  544. IM_ASSERT(info->Device != nullptr);
  545. IM_ASSERT(info->ColorTargetFormat != SDL_GPU_TEXTUREFORMAT_INVALID);
  546. bd->InitInfo = *info;
  547. ImGui_ImplSDLGPU3_InitMultiViewportSupport();
  548. return true;
  549. }
  550. void ImGui_ImplSDLGPU3_Shutdown()
  551. {
  552. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  553. IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?");
  554. ImGuiIO& io = ImGui::GetIO();
  555. ImGui_ImplSDLGPU3_ShutdownMultiViewportSupport();
  556. ImGui_ImplSDLGPU3_DestroyDeviceObjects();
  557. io.BackendRendererName = nullptr;
  558. io.BackendRendererUserData = nullptr;
  559. io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports);
  560. IM_DELETE(bd);
  561. }
  562. void ImGui_ImplSDLGPU3_NewFrame()
  563. {
  564. ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
  565. IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDLGPU3_Init()?");
  566. if (!bd->TexSampler)
  567. ImGui_ImplSDLGPU3_CreateDeviceObjects();
  568. }
  569. //--------------------------------------------------------------------------------------------------------
  570. // MULTI-VIEWPORT / PLATFORM INTERFACE SUPPORT
  571. // This is an _advanced_ and _optional_ feature, allowing the backend to create and handle multiple viewports simultaneously.
  572. // If you are new to dear imgui or creating a new binding for dear imgui, it is recommended that you completely ignore this section first..
  573. //--------------------------------------------------------------------------------------------------------
  574. static void ImGui_ImplSDLGPU3_CreateWindow(ImGuiViewport* viewport)
  575. {
  576. ImGui_ImplSDLGPU3_Data* data = ImGui_ImplSDLGPU3_GetBackendData();
  577. SDL_Window* window = SDL_GetWindowFromID((SDL_WindowID)(intptr_t)viewport->PlatformHandle);
  578. SDL_ClaimWindowForGPUDevice(data->InitInfo.Device, window);
  579. viewport->RendererUserData = (void*)1;
  580. }
  581. static void ImGui_ImplSDLGPU3_RenderWindow(ImGuiViewport* viewport, void*)
  582. {
  583. ImGui_ImplSDLGPU3_Data* data = ImGui_ImplSDLGPU3_GetBackendData();
  584. SDL_Window* window = SDL_GetWindowFromID((SDL_WindowID)(intptr_t)viewport->PlatformHandle);
  585. ImDrawData* draw_data = viewport->DrawData;
  586. SDL_GPUCommandBuffer* command_buffer = SDL_AcquireGPUCommandBuffer(data->InitInfo.Device);
  587. SDL_GPUTexture* swapchain_texture;
  588. SDL_AcquireGPUSwapchainTexture(command_buffer, window, &swapchain_texture, nullptr, nullptr);
  589. if (swapchain_texture != nullptr)
  590. {
  591. ImGui_ImplSDLGPU3_PrepareDrawData(draw_data, command_buffer); // FIXME-OPT: Not optimal, may this be done earlier?
  592. SDL_GPUColorTargetInfo target_info = {};
  593. target_info.texture = swapchain_texture;
  594. target_info.clear_color = SDL_FColor{ 0.0f,0.0f,0.0f,1.0f };
  595. target_info.load_op = SDL_GPU_LOADOP_CLEAR;
  596. target_info.store_op = SDL_GPU_STOREOP_STORE;
  597. target_info.mip_level = 0;
  598. target_info.layer_or_depth_plane = 0;
  599. target_info.cycle = false;
  600. SDL_GPURenderPass* render_pass = SDL_BeginGPURenderPass(command_buffer, &target_info, 1, nullptr);
  601. ImGui_ImplSDLGPU3_RenderDrawData(draw_data, command_buffer, render_pass);
  602. SDL_EndGPURenderPass(render_pass);
  603. }
  604. SDL_SubmitGPUCommandBuffer(command_buffer);
  605. }
  606. static void ImGui_ImplSDLGPU3_DestroyWindow(ImGuiViewport* viewport)
  607. {
  608. ImGui_ImplSDLGPU3_Data* data = ImGui_ImplSDLGPU3_GetBackendData();
  609. if (viewport->RendererUserData)
  610. {
  611. SDL_Window* window = SDL_GetWindowFromID((SDL_WindowID)(intptr_t)viewport->PlatformHandle);
  612. SDL_ReleaseWindowFromGPUDevice(data->InitInfo.Device, window);
  613. }
  614. viewport->RendererUserData = nullptr;
  615. }
  616. static void ImGui_ImplSDLGPU3_InitMultiViewportSupport()
  617. {
  618. ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
  619. platform_io.Renderer_RenderWindow = ImGui_ImplSDLGPU3_RenderWindow;
  620. platform_io.Renderer_CreateWindow = ImGui_ImplSDLGPU3_CreateWindow;
  621. platform_io.Renderer_DestroyWindow = ImGui_ImplSDLGPU3_DestroyWindow;
  622. }
  623. static void ImGui_ImplSDLGPU3_ShutdownMultiViewportSupport()
  624. {
  625. ImGui::DestroyPlatformWindows();
  626. }
  627. //-----------------------------------------------------------------------------
  628. #endif // #ifndef IMGUI_DISABLE