|
@@ -2,7 +2,7 @@
|
|
|
// This needs to be used along with the SDL3 Platform Backend
|
|
|
|
|
|
// Implemented features:
|
|
|
-// [X] Renderer: User texture binding. Use simply cast a reference to your SDL_GPUTextureSamplerBinding to ImTextureID.
|
|
|
+// [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.
|
|
|
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
|
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
|
|
|
|
@@ -22,6 +22,8 @@
|
|
|
// 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.
|
|
|
|
|
|
// CHANGELOG
|
|
|
+// 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)
|
|
|
+// 2025-08-08: Expose SamplerDefault and SamplerCurrent in ImGui_ImplSDLGPU3_RenderState. Allow callback to change sampler.
|
|
|
// 2025-06-25: Mapping transfer buffer for texture update use cycle=true. Fixes artifacts e.g. on Metal backend.
|
|
|
// 2025-06-11: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas. Removed ImGui_ImplSDLGPU3_CreateFontsTexture() and ImGui_ImplSDLGPU3_DestroyFontsTexture().
|
|
|
// 2025-04-28: Added support for special ImDrawCallback_ResetRenderState callback to reset render state.
|
|
@@ -39,7 +41,6 @@
|
|
|
struct ImGui_ImplSDLGPU3_Texture
|
|
|
{
|
|
|
SDL_GPUTexture* Texture = nullptr;
|
|
|
- SDL_GPUTextureSamplerBinding TextureSamplerBinding = { nullptr, nullptr };
|
|
|
};
|
|
|
|
|
|
// Reusable buffers used for rendering 1 current in-flight frame, for ImGui_ImplSDLGPU3_RenderDrawData()
|
|
@@ -84,12 +85,13 @@ static ImGui_ImplSDLGPU3_Data* ImGui_ImplSDLGPU3_GetBackendData()
|
|
|
return ImGui::GetCurrentContext() ? (ImGui_ImplSDLGPU3_Data*)ImGui::GetIO().BackendRendererUserData : nullptr;
|
|
|
}
|
|
|
|
|
|
-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)
|
|
|
+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)
|
|
|
{
|
|
|
- //ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
|
|
+ ImGui_ImplSDLGPU3_Data* bd = ImGui_ImplSDLGPU3_GetBackendData();
|
|
|
+ render_state->SamplerCurrent = render_state->SamplerCurrent = bd->TexSampler;
|
|
|
|
|
|
// Bind graphics pipeline
|
|
|
- SDL_BindGPUGraphicsPipeline(render_pass,pipeline);
|
|
|
+ SDL_BindGPUGraphicsPipeline(render_pass, pipeline);
|
|
|
|
|
|
// Bind Vertex And Index Buffers
|
|
|
if (draw_data->TotalVtxCount > 0)
|
|
@@ -227,12 +229,19 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|
|
if (pipeline == nullptr)
|
|
|
pipeline = bd->Pipeline;
|
|
|
|
|
|
- ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
|
|
-
|
|
|
// Will project scissor/clipping rectangles into framebuffer space
|
|
|
ImVec2 clip_off = draw_data->DisplayPos; // (0,0) unless using multi-viewports
|
|
|
ImVec2 clip_scale = draw_data->FramebufferScale; // (1,1) unless using retina display which are often (2,2)
|
|
|
|
|
|
+ // Setup render state structure (for callbacks and custom texture bindings)
|
|
|
+ ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
|
|
+ ImGui_ImplSDLGPU3_RenderState render_state;
|
|
|
+ render_state.Device = bd->InitInfo.Device;
|
|
|
+ render_state.SamplerDefault = render_state.SamplerCurrent = bd->TexSampler;
|
|
|
+ platform_io.Renderer_RenderState = &render_state;
|
|
|
+
|
|
|
+ ImGui_ImplSDLGPU3_SetupRenderState(draw_data, &render_state, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
|
|
+
|
|
|
// Render command lists
|
|
|
// (Because we merged all buffers into a single one, we maintain our own offset into them)
|
|
|
int global_vtx_offset = 0;
|
|
@@ -247,7 +256,7 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|
|
// User callback, registered via ImDrawList::AddCallback()
|
|
|
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
|
|
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
|
- ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
|
|
+ ImGui_ImplSDLGPU3_SetupRenderState(draw_data, &render_state, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
|
|
else
|
|
|
pcmd->UserCallback(draw_list, pcmd);
|
|
|
}
|
|
@@ -274,9 +283,14 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|
|
SDL_SetGPUScissor(render_pass,&scissor_rect);
|
|
|
|
|
|
// Bind DescriptorSet with font or user texture
|
|
|
- SDL_BindGPUFragmentSamplers(render_pass, 0, (SDL_GPUTextureSamplerBinding*)pcmd->GetTexID(), 1);
|
|
|
+ SDL_GPUTextureSamplerBinding texture_sampler_binding;
|
|
|
+ texture_sampler_binding.texture = (SDL_GPUTexture*)(intptr_t)pcmd->GetTexID();
|
|
|
+ texture_sampler_binding.sampler = render_state.SamplerCurrent;
|
|
|
+ SDL_BindGPUFragmentSamplers(render_pass, 0, &texture_sampler_binding, 1);
|
|
|
|
|
|
// Draw
|
|
|
+ // **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'.
|
|
|
+ // Any code loading custom texture using this backend needs to be updated.
|
|
|
SDL_DrawGPUIndexedPrimitives(render_pass, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
|
|
|
}
|
|
|
}
|
|
@@ -334,12 +348,10 @@ void ImGui_ImplSDLGPU3_UpdateTexture(ImTextureData* tex)
|
|
|
texture_info.sample_count = SDL_GPU_SAMPLECOUNT_1;
|
|
|
|
|
|
backend_tex->Texture = SDL_CreateGPUTexture(v->Device, &texture_info);
|
|
|
- backend_tex->TextureSamplerBinding.texture = backend_tex->Texture;
|
|
|
- backend_tex->TextureSamplerBinding.sampler = bd->TexSampler;
|
|
|
IM_ASSERT(backend_tex->Texture && "Failed to create font texture, call SDL_GetError() for more info");
|
|
|
|
|
|
// Store identifiers
|
|
|
- tex->SetTexID((ImTextureID)(intptr_t)&backend_tex->TextureSamplerBinding);
|
|
|
+ tex->SetTexID((ImTextureID)(intptr_t)backend_tex->Texture);
|
|
|
tex->BackendUserData = backend_tex;
|
|
|
}
|
|
|
|