| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | #include "imgui.h" |
| 44 | #ifndef IMGUI_DISABLE |
| 45 | #include "imgui_impl_sdlgpu3.h" |
| 46 | #include "imgui_impl_sdlgpu3_shaders.h" |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | struct ImGui_ImplSDLGPU3_FrameData |
| 52 | { |
| 53 | SDL_GPUBuffer* VertexBuffer = nullptr; |
| 54 | SDL_GPUTransferBuffer* VertexTransferBuffer = nullptr; |
| 55 | uint32_t VertexBufferSize = 0; |
| 56 | SDL_GPUBuffer* IndexBuffer = nullptr; |
| 57 | SDL_GPUTransferBuffer* IndexTransferBuffer = nullptr; |
| 58 | uint32_t IndexBufferSize = 0; |
| 59 | }; |
| 60 | |
| 61 | struct ImGui_ImplSDLGPU3_Data |
| 62 | { |
| 63 | ImGui_ImplSDLGPU3_InitInfo InitInfo; |
| 64 | |
| 65 | |
| 66 | ImGui_ImplSDLGPU3_RenderState* RenderState = nullptr; |
| 67 | SDL_GPUSampler* CurrentSampler = nullptr; |
| 68 | |
| 69 | |
| 70 | SDL_GPUShader* VertexShader = nullptr; |
| 71 | SDL_GPUShader* FragmentShader = nullptr; |
| 72 | SDL_GPUGraphicsPipeline* Pipeline = nullptr; |
| 73 | SDL_GPUSampler* TexSamplerLinear = nullptr; |
| 74 | SDL_GPUSampler* TexSamplerNearest = nullptr; |
| 75 | SDL_GPUTransferBuffer* TexTransferBuffer = nullptr; |
| 76 | uint32_t TexTransferBufferSize = 0; |
| 77 | |
| 78 | |
| 79 | ImGui_ImplSDLGPU3_FrameData MainWindowFrameData; |
| 80 | }; |
| 81 | |
| 82 | |
| 83 | static void ImGui_ImplSDLGPU3_DestroyFrameData(); |
| 84 | |
| 85 | |
| 86 | |
| 87 | |
| 88 | |
| 89 | |
| 90 | |
| 91 | |
| 92 | static ImGui_ImplSDLGPU3_Data* ImGui_ImplSDLGPU3_GetBackendData() |
| 93 | { |
| 94 | return ImGui::GetCurrentContext() ? (ImGui_ImplSDLGPU3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr; |
| 95 | } |
| 96 | |
| 97 | static void ImGui_ImplSDLGPU3_SetupRenderState(ImDrawData* draw_data, SDL_GPUGraphicsPipeline* pipeline, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, ImGui_ImplSDLGPU3_FrameData* fd, uint32_t fb_width, uint32_t fb_height) |
| 98 | { |
| 99 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 100 | bd->CurrentSampler = bd->TexSamplerLinear; |
| 101 | |
| 102 | |
| 103 | SDL_BindGPUGraphicsPipeline(render_pass, pipeline); |
| 104 | |
| 105 | |
| 106 | if (draw_data->TotalVtxCount > 0) |
| 107 | { |
| 108 | SDL_GPUBufferBinding vertex_buffer_binding = {}; |
| 109 | vertex_buffer_binding.buffer = fd->VertexBuffer; |
| 110 | vertex_buffer_binding.offset = 0; |
| 111 | SDL_GPUBufferBinding index_buffer_binding = {}; |
| 112 | index_buffer_binding.buffer = fd->IndexBuffer; |
| 113 | index_buffer_binding.offset = 0; |
| 114 | SDL_BindGPUVertexBuffers(render_pass,0, &vertex_buffer_binding, 1); |
| 115 | SDL_BindGPUIndexBuffer(render_pass, &index_buffer_binding, sizeof(ImDrawIdx) == 2 ? SDL_GPU_INDEXELEMENTSIZE_16BIT : SDL_GPU_INDEXELEMENTSIZE_32BIT); |
| 116 | } |
| 117 | |
| 118 | |
| 119 | SDL_GPUViewport viewport = {}; |
| 120 | viewport.x = 0; |
| 121 | viewport.y = 0; |
| 122 | viewport.w = (float)fb_width; |
| 123 | viewport.h = (float)fb_height; |
| 124 | viewport.min_depth = 0.0f; |
| 125 | viewport.max_depth = 1.0f; |
| 126 | SDL_SetGPUViewport(render_pass, &viewport); |
| 127 | |
| 128 | |
| 129 | |
| 130 | struct UBO { float scale[2]; float translation[2]; } ubo; |
| 131 | ubo.scale[0] = 2.0f / draw_data->DisplaySize.x; |
| 132 | ubo.scale[1] = 2.0f / draw_data->DisplaySize.y; |
| 133 | ubo.translation[0] = -1.0f - draw_data->DisplayPos.x * ubo.scale[0]; |
| 134 | ubo.translation[1] = -1.0f - draw_data->DisplayPos.y * ubo.scale[1]; |
| 135 | SDL_PushGPUVertexUniformData(command_buffer, 0, &ubo, sizeof(UBO)); |
| 136 | } |
| 137 | |
| 138 | static void CreateOrResizeBuffers(SDL_GPUBuffer** buffer, SDL_GPUTransferBuffer** transferbuffer, uint32_t* old_size, uint32_t new_size, SDL_GPUBufferUsageFlags usage) |
| 139 | { |
| 140 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 141 | ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; |
| 142 | |
| 143 | |
| 144 | SDL_ReleaseGPUBuffer(v->Device, *buffer); |
| 145 | SDL_ReleaseGPUTransferBuffer(v->Device, *transferbuffer); |
| 146 | |
| 147 | SDL_GPUBufferCreateInfo buffer_info = {}; |
| 148 | buffer_info.usage = usage; |
| 149 | buffer_info.size = new_size; |
| 150 | buffer_info.props = 0; |
| 151 | *buffer = SDL_CreateGPUBuffer(v->Device, &buffer_info); |
| 152 | *old_size = new_size; |
| 153 | IM_ASSERT(*buffer != nullptr && "Failed to create GPU Buffer, call SDL_GetError() for more information"); |
| 154 | |
| 155 | SDL_GPUTransferBufferCreateInfo transferbuffer_info = {}; |
| 156 | transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD; |
| 157 | transferbuffer_info.size = new_size; |
| 158 | *transferbuffer = SDL_CreateGPUTransferBuffer(v->Device, &transferbuffer_info); |
| 159 | IM_ASSERT(*transferbuffer != nullptr && "Failed to create GPU Transfer Buffer, call SDL_GetError() for more information"); |
| 160 | } |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | void ImGui_ImplSDLGPU3_PrepareDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer) |
| 166 | { |
| 167 | |
| 168 | int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x); |
| 169 | int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y); |
| 170 | if (fb_width <= 0 || fb_height <= 0 || draw_data->TotalVtxCount <= 0) |
| 171 | return; |
| 172 | |
| 173 | |
| 174 | |
| 175 | if (draw_data->Textures != nullptr) |
| 176 | for (ImTextureData* tex : *draw_data->Textures) |
| 177 | if (tex->Status != ImTextureStatus_OK) |
| 178 | ImGui_ImplSDLGPU3_UpdateTexture(tex); |
| 179 | |
| 180 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 181 | ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; |
| 182 | ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData; |
| 183 | |
| 184 | uint32_t vertex_size = (uint32_t)draw_data->TotalVtxCount * sizeof(ImDrawVert); |
| 185 | uint32_t index_size = (uint32_t)draw_data->TotalIdxCount * sizeof(ImDrawIdx); |
| 186 | if (fd->VertexBuffer == nullptr || fd->VertexBufferSize < vertex_size) |
| 187 | CreateOrResizeBuffers(&fd->VertexBuffer, &fd->VertexTransferBuffer, &fd->VertexBufferSize, vertex_size, SDL_GPU_BUFFERUSAGE_VERTEX); |
| 188 | if (fd->IndexBuffer == nullptr || fd->IndexBufferSize < index_size) |
| 189 | CreateOrResizeBuffers(&fd->IndexBuffer, &fd->IndexTransferBuffer, &fd->IndexBufferSize, index_size, SDL_GPU_BUFFERUSAGE_INDEX); |
| 190 | |
| 191 | ImDrawVert* vtx_dst = (ImDrawVert*)SDL_MapGPUTransferBuffer(v->Device, fd->VertexTransferBuffer, true); |
| 192 | ImDrawIdx* idx_dst = (ImDrawIdx*)SDL_MapGPUTransferBuffer(v->Device, fd->IndexTransferBuffer, true); |
| 193 | for (const ImDrawList* draw_list : draw_data->CmdLists) |
| 194 | { |
| 195 | memcpy(vtx_dst, draw_list->VtxBuffer.Data, draw_list->VtxBuffer.Size * sizeof(ImDrawVert)); |
| 196 | memcpy(idx_dst, draw_list->IdxBuffer.Data, draw_list->IdxBuffer.Size * sizeof(ImDrawIdx)); |
| 197 | vtx_dst += draw_list->VtxBuffer.Size; |
| 198 | idx_dst += draw_list->IdxBuffer.Size; |
| 199 | } |
| 200 | SDL_UnmapGPUTransferBuffer(v->Device, fd->VertexTransferBuffer); |
| 201 | SDL_UnmapGPUTransferBuffer(v->Device, fd->IndexTransferBuffer); |
| 202 | |
| 203 | SDL_GPUTransferBufferLocation vertex_buffer_location = {}; |
| 204 | vertex_buffer_location.offset = 0; |
| 205 | vertex_buffer_location.transfer_buffer = fd->VertexTransferBuffer; |
| 206 | SDL_GPUTransferBufferLocation index_buffer_location = {}; |
| 207 | index_buffer_location.offset = 0; |
| 208 | index_buffer_location.transfer_buffer = fd->IndexTransferBuffer; |
| 209 | |
| 210 | SDL_GPUBufferRegion vertex_buffer_region = {}; |
| 211 | vertex_buffer_region.buffer = fd->VertexBuffer; |
| 212 | vertex_buffer_region.offset = 0; |
| 213 | vertex_buffer_region.size = vertex_size; |
| 214 | |
| 215 | SDL_GPUBufferRegion index_buffer_region = {}; |
| 216 | index_buffer_region.buffer = fd->IndexBuffer; |
| 217 | index_buffer_region.offset = 0; |
| 218 | index_buffer_region.size = index_size; |
| 219 | |
| 220 | SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(command_buffer); |
| 221 | SDL_UploadToGPUBuffer(copy_pass, &vertex_buffer_location, &vertex_buffer_region, true); |
| 222 | SDL_UploadToGPUBuffer(copy_pass, &index_buffer_location, &index_buffer_region, true); |
| 223 | SDL_EndGPUCopyPass(copy_pass); |
| 224 | } |
| 225 | |
| 226 | |
| 227 | static void ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState(const ImDrawList*, const ImDrawCmd*) {} |
| 228 | static void ImGui_ImplSDLGPU3_DrawCallback_SetSamplerLinear(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); bd->CurrentSampler = bd->TexSamplerLinear; } |
| 229 | static void ImGui_ImplSDLGPU3_DrawCallback_SetSamplerNearest(const ImDrawList*, const ImDrawCmd*) { ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); bd->CurrentSampler = bd->TexSamplerNearest; } |
| 230 | |
| 231 | void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffer* command_buffer, SDL_GPURenderPass* render_pass, SDL_GPUGraphicsPipeline* pipeline) |
| 232 | { |
| 233 | |
| 234 | int fb_width = (int)(draw_data->DisplaySize.x * draw_data->FramebufferScale.x); |
| 235 | int fb_height = (int)(draw_data->DisplaySize.y * draw_data->FramebufferScale.y); |
| 236 | if (fb_width <= 0 || fb_height <= 0) |
| 237 | return; |
| 238 | |
| 239 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 240 | ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData; |
| 241 | |
| 242 | if (pipeline == nullptr) |
| 243 | pipeline = bd->Pipeline; |
| 244 | |
| 245 | |
| 246 | ImVec2 clip_off = draw_data->DisplayPos; |
| 247 | ImVec2 clip_scale = draw_data->FramebufferScale; |
| 248 | |
| 249 | |
| 250 | ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); |
| 251 | ImGui_ImplSDLGPU3_RenderState render_state; |
| 252 | render_state.Device = bd->InitInfo.Device; |
| 253 | platform_io.Renderer_RenderState = bd->RenderState = &render_state; |
| 254 | |
| 255 | ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height); |
| 256 | |
| 257 | |
| 258 | |
| 259 | int global_vtx_offset = 0; |
| 260 | int global_idx_offset = 0; |
| 261 | for (const ImDrawList* draw_list : draw_data->CmdLists) |
| 262 | { |
| 263 | for (int cmd_i = 0; cmd_i < draw_list->CmdBuffer.Size; cmd_i++) |
| 264 | { |
| 265 | const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i]; |
| 266 | if (pcmd->UserCallback != nullptr) |
| 267 | { |
| 268 | |
| 269 | if (pcmd->UserCallback == ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState) |
| 270 | ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height); |
| 271 | else |
| 272 | pcmd->UserCallback(draw_list, pcmd); |
| 273 | } |
| 274 | else |
| 275 | { |
| 276 | |
| 277 | ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y); |
| 278 | ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y); |
| 279 | |
| 280 | |
| 281 | if (clip_min.x < 0.0f) { clip_min.x = 0.0f; } |
| 282 | if (clip_min.y < 0.0f) { clip_min.y = 0.0f; } |
| 283 | if (clip_max.x > (float)fb_width) { clip_max.x = (float)fb_width; } |
| 284 | if (clip_max.y > (float)fb_height) { clip_max.y = (float)fb_height; } |
| 285 | if (clip_max.x <= clip_min.x || clip_max.y <= clip_min.y) |
| 286 | continue; |
| 287 | |
| 288 | |
| 289 | SDL_Rect scissor_rect = {}; |
| 290 | scissor_rect.x = (int)clip_min.x; |
| 291 | scissor_rect.y = (int)clip_min.y; |
| 292 | scissor_rect.w = (int)(clip_max.x - clip_min.x); |
| 293 | scissor_rect.h = (int)(clip_max.y - clip_min.y); |
| 294 | SDL_SetGPUScissor(render_pass,&scissor_rect); |
| 295 | |
| 296 | |
| 297 | SDL_GPUTextureSamplerBinding texture_sampler_binding; |
| 298 | texture_sampler_binding.texture = (SDL_GPUTexture*)(intptr_t)pcmd->GetTexID(); |
| 299 | texture_sampler_binding.sampler = bd->CurrentSampler; |
| 300 | SDL_BindGPUFragmentSamplers(render_pass, 0, &texture_sampler_binding, 1); |
| 301 | |
| 302 | |
| 303 | |
| 304 | |
| 305 | SDL_DrawGPUIndexedPrimitives(render_pass, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0); |
| 306 | } |
| 307 | } |
| 308 | global_idx_offset += draw_list->IdxBuffer.Size; |
| 309 | global_vtx_offset += draw_list->VtxBuffer.Size; |
| 310 | } |
| 311 | |
| 312 | |
| 313 | |
| 314 | |
| 315 | |
| 316 | SDL_Rect scissor_rect { 0, 0, fb_width, fb_height }; |
| 317 | SDL_SetGPUScissor(render_pass, &scissor_rect); |
| 318 | |
| 319 | platform_io.Renderer_RenderState = bd->RenderState = nullptr; |
| 320 | } |
| 321 | |
| 322 | static void ImGui_ImplSDLGPU3_DestroyTexture(ImTextureData* tex) |
| 323 | { |
| 324 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 325 | if (tex->GetTexID() != ImTextureID_Invalid) |
| 326 | if (SDL_GPUTexture* raw_tex = (SDL_GPUTexture*)(intptr_t)tex->GetTexID()) |
| 327 | SDL_ReleaseGPUTexture(bd->InitInfo.Device, raw_tex); |
| 328 | |
| 329 | |
| 330 | tex->SetTexID(ImTextureID_Invalid); |
| 331 | tex->SetStatus(ImTextureStatus_Destroyed); |
| 332 | } |
| 333 | |
| 334 | void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex) |
| 335 | { |
| 336 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 337 | ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; |
| 338 | |
| 339 | if (tex->Status == ImTextureStatus_WantCreate) |
| 340 | { |
| 341 | |
| 342 | |
| 343 | IM_ASSERT(tex->TexID == ImTextureID_Invalid && tex->BackendUserData == nullptr); |
| 344 | IM_ASSERT(tex->Format == ImTextureFormat_RGBA32); |
| 345 | |
| 346 | |
| 347 | SDL_GPUTextureCreateInfo texture_info = {}; |
| 348 | texture_info.type = SDL_GPU_TEXTURETYPE_2D; |
| 349 | texture_info.format = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM; |
| 350 | texture_info.usage = SDL_GPU_TEXTUREUSAGE_SAMPLER; |
| 351 | texture_info.width = tex->Width; |
| 352 | texture_info.height = tex->Height; |
| 353 | texture_info.layer_count_or_depth = 1; |
| 354 | texture_info.num_levels = 1; |
| 355 | texture_info.sample_count = SDL_GPU_SAMPLECOUNT_1; |
| 356 | |
| 357 | SDL_GPUTexture* raw_tex = SDL_CreateGPUTexture(v->Device, &texture_info); |
| 358 | IM_ASSERT(raw_tex != nullptr && "Failed to create texture, call SDL_GetError() for more info"); |
| 359 | |
| 360 | |
| 361 | tex->SetTexID((ImTextureID)(intptr_t)raw_tex); |
| 362 | } |
| 363 | |
| 364 | if (tex->Status == ImTextureStatus_WantCreate || tex->Status == ImTextureStatus_WantUpdates) |
| 365 | { |
| 366 | SDL_GPUTexture* raw_tex = (SDL_GPUTexture*)(intptr_t)tex->GetTexID(); |
| 367 | IM_ASSERT(tex->Format == ImTextureFormat_RGBA32); |
| 368 | |
| 369 | |
| 370 | |
| 371 | |
| 372 | const int upload_x = (tex->Status == ImTextureStatus_WantCreate) ? 0 : tex->UpdateRect.x; |
| 373 | const int upload_y = (tex->Status == ImTextureStatus_WantCreate) ? 0 : tex->UpdateRect.y; |
| 374 | const int upload_w = (tex->Status == ImTextureStatus_WantCreate) ? tex->Width : tex->UpdateRect.w; |
| 375 | const int upload_h = (tex->Status == ImTextureStatus_WantCreate) ? tex->Height : tex->UpdateRect.h; |
| 376 | uint32_t upload_pitch = upload_w * tex->BytesPerPixel; |
| 377 | uint32_t upload_size = upload_w * upload_h * tex->BytesPerPixel; |
| 378 | |
| 379 | |
| 380 | if (bd->TexTransferBufferSize < upload_size) |
| 381 | { |
| 382 | SDL_ReleaseGPUTransferBuffer(v->Device, bd->TexTransferBuffer); |
| 383 | SDL_GPUTransferBufferCreateInfo transferbuffer_info = {}; |
| 384 | transferbuffer_info.usage = SDL_GPU_TRANSFERBUFFERUSAGE_UPLOAD; |
| 385 | transferbuffer_info.size = upload_size + 1024; |
| 386 | bd->TexTransferBufferSize = upload_size + 1024; |
| 387 | bd->TexTransferBuffer = SDL_CreateGPUTransferBuffer(v->Device, &transferbuffer_info); |
| 388 | IM_ASSERT(bd->TexTransferBuffer != nullptr && "Failed to create transfer buffer, call SDL_GetError() for more information"); |
| 389 | } |
| 390 | |
| 391 | |
| 392 | { |
| 393 | void* texture_ptr = SDL_MapGPUTransferBuffer(v->Device, bd->TexTransferBuffer, true); |
| 394 | for (int y = 0; y < upload_h; y++) |
| 395 | memcpy((void*)((uintptr_t)texture_ptr + y * upload_pitch), tex->GetPixelsAt(upload_x, upload_y + y), upload_pitch); |
| 396 | SDL_UnmapGPUTransferBuffer(v->Device, bd->TexTransferBuffer); |
| 397 | } |
| 398 | |
| 399 | SDL_GPUTextureTransferInfo transfer_info = {}; |
| 400 | transfer_info.offset = 0; |
| 401 | transfer_info.transfer_buffer = bd->TexTransferBuffer; |
| 402 | |
| 403 | SDL_GPUTextureRegion texture_region = {}; |
| 404 | texture_region.texture = raw_tex; |
| 405 | texture_region.x = (Uint32)upload_x; |
| 406 | texture_region.y = (Uint32)upload_y; |
| 407 | texture_region.w = (Uint32)upload_w; |
| 408 | texture_region.h = (Uint32)upload_h; |
| 409 | texture_region.d = 1; |
| 410 | |
| 411 | |
| 412 | { |
| 413 | SDL_GPUCommandBuffer* cmd = SDL_AcquireGPUCommandBuffer(v->Device); |
| 414 | SDL_GPUCopyPass* copy_pass = SDL_BeginGPUCopyPass(cmd); |
| 415 | SDL_UploadToGPUTexture(copy_pass, &transfer_info, &texture_region, false); |
| 416 | SDL_EndGPUCopyPass(copy_pass); |
| 417 | SDL_SubmitGPUCommandBuffer(cmd); |
| 418 | } |
| 419 | |
| 420 | tex->SetStatus(ImTextureStatus_OK); |
| 421 | } |
| 422 | if (tex->Status == ImTextureStatus_WantDestroy && tex->UnusedFrames > 0) |
| 423 | ImGui_ImplSDLGPU3_DestroyTexture(tex); |
| 424 | } |
| 425 | |
| 426 | static void ImGui_ImplSDLGPU3_CreateShaders() |
| 427 | { |
| 428 | |
| 429 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 430 | ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; |
| 431 | |
| 432 | const char* driver = SDL_GetGPUDeviceDriver(v->Device); |
| 433 | |
| 434 | SDL_GPUShaderCreateInfo vertex_shader_info = {}; |
| 435 | vertex_shader_info.entrypoint = "main"; |
| 436 | vertex_shader_info.stage = SDL_GPU_SHADERSTAGE_VERTEX; |
| 437 | vertex_shader_info.num_uniform_buffers = 1; |
| 438 | vertex_shader_info.num_storage_buffers = 0; |
| 439 | vertex_shader_info.num_storage_textures = 0; |
| 440 | vertex_shader_info.num_samplers = 0; |
| 441 | |
| 442 | SDL_GPUShaderCreateInfo fragment_shader_info = {}; |
| 443 | fragment_shader_info.entrypoint = "main"; |
| 444 | fragment_shader_info.stage = SDL_GPU_SHADERSTAGE_FRAGMENT; |
| 445 | fragment_shader_info.num_samplers = 1; |
| 446 | fragment_shader_info.num_storage_buffers = 0; |
| 447 | fragment_shader_info.num_storage_textures = 0; |
| 448 | fragment_shader_info.num_uniform_buffers = 0; |
| 449 | |
| 450 | if (strcmp(driver, "vulkan") == 0) |
| 451 | { |
| 452 | vertex_shader_info.format = SDL_GPU_SHADERFORMAT_SPIRV; |
| 453 | vertex_shader_info.code = spirv_vertex; |
| 454 | vertex_shader_info.code_size = sizeof(spirv_vertex); |
| 455 | fragment_shader_info.format = SDL_GPU_SHADERFORMAT_SPIRV; |
| 456 | fragment_shader_info.code = spirv_fragment; |
| 457 | fragment_shader_info.code_size = sizeof(spirv_fragment); |
| 458 | } |
| 459 | else if (strcmp(driver, "direct3d12") == 0) |
| 460 | { |
| 461 | vertex_shader_info.format = SDL_GPU_SHADERFORMAT_DXBC; |
| 462 | vertex_shader_info.code = dxbc_vertex; |
| 463 | vertex_shader_info.code_size = sizeof(dxbc_vertex); |
| 464 | fragment_shader_info.format = SDL_GPU_SHADERFORMAT_DXBC; |
| 465 | fragment_shader_info.code = dxbc_fragment; |
| 466 | fragment_shader_info.code_size = sizeof(dxbc_fragment); |
| 467 | } |
| 468 | #ifdef __APPLE__ |
| 469 | else |
| 470 | { |
| 471 | SDL_GPUShaderFormat supported_formats = SDL_GetGPUShaderFormats(v->Device); |
| 472 | if (supported_formats & SDL_GPU_SHADERFORMAT_METALLIB) |
| 473 | { |
| 474 | |
| 475 | vertex_shader_info.entrypoint = "main0"; |
| 476 | vertex_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB; |
| 477 | vertex_shader_info.code = metallib_vertex; |
| 478 | vertex_shader_info.code_size = sizeof(metallib_vertex); |
| 479 | fragment_shader_info.entrypoint = "main0"; |
| 480 | fragment_shader_info.format = SDL_GPU_SHADERFORMAT_METALLIB; |
| 481 | fragment_shader_info.code = metallib_fragment; |
| 482 | fragment_shader_info.code_size = sizeof(metallib_fragment); |
| 483 | } |
| 484 | else if (supported_formats & SDL_GPU_SHADERFORMAT_MSL) |
| 485 | { |
| 486 | |
| 487 | vertex_shader_info.entrypoint = "main0"; |
| 488 | vertex_shader_info.format = SDL_GPU_SHADERFORMAT_MSL; |
| 489 | vertex_shader_info.code = msl_vertex; |
| 490 | vertex_shader_info.code_size = sizeof(msl_vertex); |
| 491 | fragment_shader_info.entrypoint = "main0"; |
| 492 | fragment_shader_info.format = SDL_GPU_SHADERFORMAT_MSL; |
| 493 | fragment_shader_info.code = msl_fragment; |
| 494 | fragment_shader_info.code_size = sizeof(msl_fragment); |
| 495 | } |
| 496 | } |
| 497 | #endif |
| 498 | bd->VertexShader = SDL_CreateGPUShader(v->Device, &vertex_shader_info); |
| 499 | bd->FragmentShader = SDL_CreateGPUShader(v->Device, &fragment_shader_info); |
| 500 | IM_ASSERT(bd->VertexShader != nullptr && "Failed to create vertex shader, call SDL_GetError() for more information"); |
| 501 | IM_ASSERT(bd->FragmentShader != nullptr && "Failed to create fragment shader, call SDL_GetError() for more information"); |
| 502 | } |
| 503 | |
| 504 | static void ImGui_ImplSDLGPU3_CreateGraphicsPipeline() |
| 505 | { |
| 506 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 507 | ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; |
| 508 | ImGui_ImplSDLGPU3_CreateShaders(); |
| 509 | |
| 510 | SDL_GPUVertexBufferDescription vertex_buffer_desc[1]; |
| 511 | vertex_buffer_desc[0].slot = 0; |
| 512 | vertex_buffer_desc[0].input_rate = SDL_GPU_VERTEXINPUTRATE_VERTEX; |
| 513 | vertex_buffer_desc[0].instance_step_rate = 0; |
| 514 | vertex_buffer_desc[0].pitch = sizeof(ImDrawVert); |
| 515 | |
| 516 | SDL_GPUVertexAttribute vertex_attributes[3]; |
| 517 | vertex_attributes[0].buffer_slot = 0; |
| 518 | vertex_attributes[0].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2; |
| 519 | vertex_attributes[0].location = 0; |
| 520 | vertex_attributes[0].offset = offsetof(ImDrawVert,pos); |
| 521 | |
| 522 | vertex_attributes[1].buffer_slot = 0; |
| 523 | vertex_attributes[1].format = SDL_GPU_VERTEXELEMENTFORMAT_FLOAT2; |
| 524 | vertex_attributes[1].location = 1; |
| 525 | vertex_attributes[1].offset = offsetof(ImDrawVert, uv); |
| 526 | |
| 527 | vertex_attributes[2].buffer_slot = 0; |
| 528 | vertex_attributes[2].format = SDL_GPU_VERTEXELEMENTFORMAT_UBYTE4_NORM; |
| 529 | vertex_attributes[2].location = 2; |
| 530 | vertex_attributes[2].offset = offsetof(ImDrawVert, col); |
| 531 | |
| 532 | SDL_GPUVertexInputState vertex_input_state = {}; |
| 533 | vertex_input_state.num_vertex_attributes = 3; |
| 534 | vertex_input_state.vertex_attributes = vertex_attributes; |
| 535 | vertex_input_state.num_vertex_buffers = 1; |
| 536 | vertex_input_state.vertex_buffer_descriptions = vertex_buffer_desc; |
| 537 | |
| 538 | SDL_GPURasterizerState rasterizer_state = {}; |
| 539 | rasterizer_state.fill_mode = SDL_GPU_FILLMODE_FILL; |
| 540 | rasterizer_state.cull_mode = SDL_GPU_CULLMODE_NONE; |
| 541 | rasterizer_state.front_face = SDL_GPU_FRONTFACE_COUNTER_CLOCKWISE; |
| 542 | rasterizer_state.enable_depth_bias = false; |
| 543 | rasterizer_state.enable_depth_clip = false; |
| 544 | |
| 545 | SDL_GPUMultisampleState multisample_state = {}; |
| 546 | multisample_state.sample_count = v->MSAASamples; |
| 547 | multisample_state.enable_mask = false; |
| 548 | |
| 549 | SDL_GPUDepthStencilState depth_stencil_state = {}; |
| 550 | depth_stencil_state.enable_depth_test = false; |
| 551 | depth_stencil_state.enable_depth_write = false; |
| 552 | depth_stencil_state.enable_stencil_test = false; |
| 553 | |
| 554 | SDL_GPUColorTargetBlendState blend_state = {}; |
| 555 | blend_state.enable_blend = true; |
| 556 | blend_state.src_color_blendfactor = SDL_GPU_BLENDFACTOR_SRC_ALPHA; |
| 557 | blend_state.dst_color_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; |
| 558 | blend_state.color_blend_op = SDL_GPU_BLENDOP_ADD; |
| 559 | blend_state.src_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE; |
| 560 | blend_state.dst_alpha_blendfactor = SDL_GPU_BLENDFACTOR_ONE_MINUS_SRC_ALPHA; |
| 561 | blend_state.alpha_blend_op = SDL_GPU_BLENDOP_ADD; |
| 562 | blend_state.color_write_mask = SDL_GPU_COLORCOMPONENT_R | SDL_GPU_COLORCOMPONENT_G | SDL_GPU_COLORCOMPONENT_B | SDL_GPU_COLORCOMPONENT_A; |
| 563 | |
| 564 | SDL_GPUColorTargetDescription color_target_desc[1]; |
| 565 | color_target_desc[0].format = v->ColorTargetFormat; |
| 566 | color_target_desc[0].blend_state = blend_state; |
| 567 | |
| 568 | SDL_GPUGraphicsPipelineTargetInfo target_info = {}; |
| 569 | target_info.num_color_targets = 1; |
| 570 | target_info.color_target_descriptions = color_target_desc; |
| 571 | target_info.has_depth_stencil_target = false; |
| 572 | |
| 573 | SDL_GPUGraphicsPipelineCreateInfo pipeline_info = {}; |
| 574 | pipeline_info.vertex_shader = bd->VertexShader; |
| 575 | pipeline_info.fragment_shader = bd->FragmentShader; |
| 576 | pipeline_info.vertex_input_state = vertex_input_state; |
| 577 | pipeline_info.primitive_type = SDL_GPU_PRIMITIVETYPE_TRIANGLELIST; |
| 578 | pipeline_info.rasterizer_state = rasterizer_state; |
| 579 | pipeline_info.multisample_state = multisample_state; |
| 580 | pipeline_info.depth_stencil_state = depth_stencil_state; |
| 581 | pipeline_info.target_info = target_info; |
| 582 | |
| 583 | bd->Pipeline = SDL_CreateGPUGraphicsPipeline(v->Device, &pipeline_info); |
| 584 | IM_ASSERT(bd->Pipeline != nullptr && "Failed to create graphics pipeline, call SDL_GetError() for more information"); |
| 585 | } |
| 586 | |
| 587 | void ImGui_ImplSDLGPU3_CreateDeviceObjects() |
| 588 | { |
| 589 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 590 | ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; |
| 591 | |
| 592 | ImGui_ImplSDLGPU3_DestroyDeviceObjects(); |
| 593 | |
| 594 | if (bd->TexSamplerLinear == nullptr) |
| 595 | { |
| 596 | |
| 597 | SDL_GPUSamplerCreateInfo sampler_info = {}; |
| 598 | sampler_info.min_filter = SDL_GPU_FILTER_LINEAR; |
| 599 | sampler_info.mag_filter = SDL_GPU_FILTER_LINEAR; |
| 600 | sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_LINEAR; |
| 601 | sampler_info.address_mode_u = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE; |
| 602 | sampler_info.address_mode_v = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE; |
| 603 | sampler_info.address_mode_w = SDL_GPU_SAMPLERADDRESSMODE_CLAMP_TO_EDGE; |
| 604 | sampler_info.mip_lod_bias = 0.0f; |
| 605 | sampler_info.min_lod = -1000.0f; |
| 606 | sampler_info.max_lod = 1000.0f; |
| 607 | sampler_info.enable_anisotropy = false; |
| 608 | sampler_info.max_anisotropy = 1.0f; |
| 609 | sampler_info.enable_compare = false; |
| 610 | bd->TexSamplerLinear = SDL_CreateGPUSampler(v->Device, &sampler_info); |
| 611 | IM_ASSERT(bd->TexSamplerLinear != nullptr && "Failed to create sampler, call SDL_GetError() for more information"); |
| 612 | |
| 613 | sampler_info.min_filter = SDL_GPU_FILTER_NEAREST; |
| 614 | sampler_info.mag_filter = SDL_GPU_FILTER_NEAREST; |
| 615 | sampler_info.mipmap_mode = SDL_GPU_SAMPLERMIPMAPMODE_NEAREST; |
| 616 | bd->TexSamplerNearest = SDL_CreateGPUSampler(v->Device, &sampler_info); |
| 617 | IM_ASSERT(bd->TexSamplerNearest != nullptr && "Failed to create sampler, call SDL_GetError() for more information"); |
| 618 | } |
| 619 | |
| 620 | ImGui_ImplSDLGPU3_CreateGraphicsPipeline(); |
| 621 | } |
| 622 | |
| 623 | void ImGui_ImplSDLGPU3_DestroyFrameData() |
| 624 | { |
| 625 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 626 | ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; |
| 627 | |
| 628 | ImGui_ImplSDLGPU3_FrameData* fd = &bd->MainWindowFrameData; |
| 629 | SDL_ReleaseGPUBuffer(v->Device, fd->VertexBuffer); |
| 630 | SDL_ReleaseGPUBuffer(v->Device, fd->IndexBuffer); |
| 631 | SDL_ReleaseGPUTransferBuffer(v->Device, fd->VertexTransferBuffer); |
| 632 | SDL_ReleaseGPUTransferBuffer(v->Device, fd->IndexTransferBuffer); |
| 633 | fd->VertexBuffer = fd->IndexBuffer = nullptr; |
| 634 | fd->VertexTransferBuffer = fd->IndexTransferBuffer = nullptr; |
| 635 | fd->VertexBufferSize = fd->IndexBufferSize = 0; |
| 636 | } |
| 637 | |
| 638 | void ImGui_ImplSDLGPU3_DestroyDeviceObjects() |
| 639 | { |
| 640 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 641 | ImGui_ImplSDLGPU3_InitInfo* v = &bd->InitInfo; |
| 642 | |
| 643 | ImGui_ImplSDLGPU3_DestroyFrameData(); |
| 644 | |
| 645 | |
| 646 | for (ImTextureData* tex : ImGui::GetPlatformIO().Textures) |
| 647 | if (tex->RefCount == 1) |
| 648 | ImGui_ImplSDLGPU3_DestroyTexture(tex); |
| 649 | if (bd->TexTransferBuffer) { SDL_ReleaseGPUTransferBuffer(v->Device, bd->TexTransferBuffer); bd->TexTransferBuffer = nullptr; } |
| 650 | if (bd->VertexShader) { SDL_ReleaseGPUShader(v->Device, bd->VertexShader); bd->VertexShader = nullptr; } |
| 651 | if (bd->FragmentShader) { SDL_ReleaseGPUShader(v->Device, bd->FragmentShader); bd->FragmentShader = nullptr; } |
| 652 | if (bd->TexSamplerLinear) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerLinear); bd->TexSamplerLinear = nullptr; } |
| 653 | if (bd->TexSamplerNearest) { SDL_ReleaseGPUSampler(v->Device, bd->TexSamplerNearest); bd->TexSamplerNearest = nullptr; } |
| 654 | if (bd->Pipeline) { SDL_ReleaseGPUGraphicsPipeline(v->Device, bd->Pipeline); bd->Pipeline = nullptr; } |
| 655 | } |
| 656 | |
| 657 | static void ImGui_ImplSDLGPU3_InitMultiViewportSupport(); |
| 658 | static void ImGui_ImplSDLGPU3_ShutdownMultiViewportSupport(); |
| 659 | |
| 660 | bool ImGui_ImplSDLGPU3_Init(ImGui_ImplSDLGPU3_InitInfo* info) |
| 661 | { |
| 662 | ImGuiIO& io = ImGui::GetIO(); |
| 663 | IMGUI_CHECKVERSION(); |
| 664 | IM_ASSERT(io.BackendRendererUserData == nullptr && "Already initialized a renderer backend!"); |
| 665 | |
| 666 | |
| 667 | ImGui_ImplSDLGPU3_Data* bd = IM_NEW(ImGui_ImplSDLGPU3_Data)(); |
| 668 | io.BackendRendererUserData = (void*)bd; |
| 669 | io.BackendRendererName = "imgui_impl_sdlgpu3"; |
| 670 | io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; |
| 671 | io.BackendFlags |= ImGuiBackendFlags_RendererHasTextures; |
| 672 | io.BackendFlags |= ImGuiBackendFlags_RendererHasViewports; |
| 673 | |
| 674 | ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); |
| 675 | platform_io.DrawCallback_ResetRenderState = ImGui_ImplSDLGPU3_DrawCallback_ResetRenderState; |
| 676 | platform_io.DrawCallback_SetSamplerLinear = ImGui_ImplSDLGPU3_DrawCallback_SetSamplerLinear; |
| 677 | platform_io.DrawCallback_SetSamplerNearest = ImGui_ImplSDLGPU3_DrawCallback_SetSamplerNearest; |
| 678 | |
| 679 | IM_ASSERT(info->Device != nullptr); |
| 680 | IM_ASSERT(info->ColorTargetFormat != SDL_GPU_TEXTUREFORMAT_INVALID); |
| 681 | |
| 682 | bd->InitInfo = *info; |
| 683 | |
| 684 | ImGui_ImplSDLGPU3_InitMultiViewportSupport(); |
| 685 | |
| 686 | return true; |
| 687 | } |
| 688 | |
| 689 | void ImGui_ImplSDLGPU3_Shutdown() |
| 690 | { |
| 691 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 692 | IM_ASSERT(bd != nullptr && "No renderer backend to shutdown, or already shutdown?"); |
| 693 | ImGuiIO& io = ImGui::GetIO(); |
| 694 | ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); |
| 695 | |
| 696 | ImGui_ImplSDLGPU3_ShutdownMultiViewportSupport(); |
| 697 | ImGui_ImplSDLGPU3_DestroyDeviceObjects(); |
| 698 | |
| 699 | io.BackendRendererName = nullptr; |
| 700 | io.BackendRendererUserData = nullptr; |
| 701 | io.BackendFlags &= ~(ImGuiBackendFlags_RendererHasVtxOffset | ImGuiBackendFlags_RendererHasTextures | ImGuiBackendFlags_RendererHasViewports); |
| 702 | platform_io.ClearRendererHandlers(); |
| 703 | IM_DELETE(bd); |
| 704 | } |
| 705 | |
| 706 | void ImGui_ImplSDLGPU3_NewFrame() |
| 707 | { |
| 708 | ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData(); |
| 709 | IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplSDLGPU3_Init()?"); |
| 710 | |
| 711 | if (!bd->TexSamplerLinear) |
| 712 | ImGui_ImplSDLGPU3_CreateDeviceObjects(); |
| 713 | } |
| 714 | |
| 715 | |
| 716 | |
| 717 | |
| 718 | |
| 719 | |
| 720 | |
| 721 | static void ImGui_ImplSDLGPU3_CreateWindow(ImGuiViewport* viewport) |
| 722 | { |
| 723 | ImGui_ImplSDLGPU3_Data* data = ImGui_ImplSDLGPU3_GetBackendData(); |
| 724 | SDL_Window* window = SDL_GetWindowFromID((SDL_WindowID)(intptr_t)viewport->PlatformHandle); |
| 725 | SDL_ClaimWindowForGPUDevice(data->InitInfo.Device, window); |
| 726 | SDL_SetGPUSwapchainParameters(data->InitInfo.Device, window, data->InitInfo.SwapchainComposition, data->InitInfo.PresentMode); |
| 727 | viewport->RendererUserData = (void*)1; |
| 728 | } |
| 729 | |
| 730 | static void ImGui_ImplSDLGPU3_RenderWindow(ImGuiViewport* viewport, void*) |
| 731 | { |
| 732 | ImGui_ImplSDLGPU3_Data* data = ImGui_ImplSDLGPU3_GetBackendData(); |
| 733 | SDL_Window* window = SDL_GetWindowFromID((SDL_WindowID)(intptr_t)viewport->PlatformHandle); |
| 734 | |
| 735 | ImDrawData* draw_data = viewport->DrawData; |
| 736 | |
| 737 | SDL_GPUCommandBuffer* command_buffer = SDL_AcquireGPUCommandBuffer(data->InitInfo.Device); |
| 738 | |
| 739 | SDL_GPUTexture* swapchain_texture; |
| 740 | SDL_AcquireGPUSwapchainTexture(command_buffer, window, &swapchain_texture, nullptr, nullptr); |
| 741 | |
| 742 | if (swapchain_texture != nullptr) |
| 743 | { |
| 744 | ImGui_ImplSDLGPU3_PrepareDrawData(draw_data, command_buffer); |
| 745 | SDL_GPUColorTargetInfo target_info = {}; |
| 746 | target_info.texture = swapchain_texture; |
| 747 | target_info.clear_color = SDL_FColor{ 0.0f,0.0f,0.0f,1.0f }; |
| 748 | target_info.load_op = SDL_GPU_LOADOP_CLEAR; |
| 749 | target_info.store_op = SDL_GPU_STOREOP_STORE; |
| 750 | target_info.mip_level = 0; |
| 751 | target_info.layer_or_depth_plane = 0; |
| 752 | target_info.cycle = false; |
| 753 | SDL_GPURenderPass* render_pass = SDL_BeginGPURenderPass(command_buffer, &target_info, 1, nullptr); |
| 754 | ImGui_ImplSDLGPU3_RenderDrawData(draw_data, command_buffer, render_pass); |
| 755 | SDL_EndGPURenderPass(render_pass); |
| 756 | } |
| 757 | |
| 758 | SDL_SubmitGPUCommandBuffer(command_buffer); |
| 759 | } |
| 760 | |
| 761 | static void ImGui_ImplSDLGPU3_DestroyWindow(ImGuiViewport* viewport) |
| 762 | { |
| 763 | ImGui_ImplSDLGPU3_Data* data = ImGui_ImplSDLGPU3_GetBackendData(); |
| 764 | if (viewport->RendererUserData) |
| 765 | { |
| 766 | SDL_Window* window = SDL_GetWindowFromID((SDL_WindowID)(intptr_t)viewport->PlatformHandle); |
| 767 | SDL_ReleaseWindowFromGPUDevice(data->InitInfo.Device, window); |
| 768 | } |
| 769 | viewport->RendererUserData = nullptr; |
| 770 | } |
| 771 | |
| 772 | static void ImGui_ImplSDLGPU3_InitMultiViewportSupport() |
| 773 | { |
| 774 | ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO(); |
| 775 | platform_io.Renderer_RenderWindow = ImGui_ImplSDLGPU3_RenderWindow; |
| 776 | platform_io.Renderer_CreateWindow = ImGui_ImplSDLGPU3_CreateWindow; |
| 777 | platform_io.Renderer_DestroyWindow = ImGui_ImplSDLGPU3_DestroyWindow; |
| 778 | } |
| 779 | |
| 780 | static void ImGui_ImplSDLGPU3_ShutdownMultiViewportSupport() |
| 781 | { |
| 782 | ImGui::DestroyPlatformWindows(); |
| 783 | } |
| 784 | |
| 785 | |
| 786 | |
| 787 | #endif |