61 lines
2.9 KiB
Diff
61 lines
2.9 KiB
Diff
From 3c421b0502a4fed7fcc72cce6e99e40986cdb9a7 Mon Sep 17 00:00:00 2001
|
|
From: Sven Balzer <4653051+Kyuusokuna@users.noreply.github.com>
|
|
Date: Thu, 20 Mar 2025 12:10:23 +0100
|
|
Subject: [PATCH] add callback support for imgui sdlgpu3 backend
|
|
---
|
|
libs/imgui/backends/imgui_impl_sdlgpu3.cpp | 12 +++++++++++-
|
|
libs/imgui/backends/imgui_impl_sdlgpu3.h | 9 +++++++++
|
|
2 files changed, 20 insertions(+), 1 deletion(-)
|
|
|
|
diff --git a/libs/imgui/backends/imgui_impl_sdlgpu3.cpp b/libs/imgui/backends/imgui_impl_sdlgpu3.cpp
|
|
index 74b9662..e399974 100644
|
|
--- a/libs/imgui/backends/imgui_impl_sdlgpu3.cpp
|
|
+++ b/libs/imgui/backends/imgui_impl_sdlgpu3.cpp
|
|
@@ -220,6 +220,13 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|
|
|
ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
|
|
|
+ // Setup render state structure (for callbacks and custom texture bindings)
|
|
+ ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
|
+ ImGui_ImplSDLGPU3_RenderState render_state;
|
|
+ render_state.command_buffer = command_buffer;
|
|
+ render_state.render_pass = render_pass;
|
|
+ platform_io.Renderer_RenderState = &render_state;
|
|
+
|
|
// 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)
|
|
@@ -236,7 +243,10 @@ void ImGui_ImplSDLGPU3_RenderDrawData(ImDrawData* draw_data, SDL_GPUCommandBuffe
|
|
const ImDrawCmd* pcmd = &draw_list->CmdBuffer[cmd_i];
|
|
if (pcmd->UserCallback != nullptr)
|
|
{
|
|
- pcmd->UserCallback(draw_list, pcmd);
|
|
+ if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
|
+ ImGui_ImplSDLGPU3_SetupRenderState(draw_data, pipeline, command_buffer, render_pass, fd, fb_width, fb_height);
|
|
+ else
|
|
+ pcmd->UserCallback(draw_list, pcmd);
|
|
}
|
|
else
|
|
{
|
|
diff --git a/libs/imgui/backends/imgui_impl_sdlgpu3.h b/libs/imgui/backends/imgui_impl_sdlgpu3.h
|
|
index 865139e..2cc032d 100644
|
|
--- a/libs/imgui/backends/imgui_impl_sdlgpu3.h
|
|
+++ b/libs/imgui/backends/imgui_impl_sdlgpu3.h
|
|
@@ -46,4 +46,13 @@ IMGUI_IMPL_API void ImGui_ImplSDLGPU3_DestroyDeviceObjects();
|
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_CreateFontsTexture();
|
|
IMGUI_IMPL_API void ImGui_ImplSDLGPU3_DestroyFontsTexture();
|
|
|
|
+// [BETA] Selected render state data shared with callbacks.
|
|
+// This is temporarily stored in GetPlatformIO().Renderer_RenderState during the ImGui_ImplSDLGPU3_RenderDrawData() call.
|
|
+// (Please open an issue if you feel you need access to more data)
|
|
+struct ImGui_ImplSDLGPU3_RenderState
|
|
+{
|
|
+ SDL_GPUCommandBuffer* command_buffer;
|
|
+ SDL_GPURenderPass* render_pass;
|
|
+};
|
|
+
|
|
#endif // #ifndef IMGUI_DISABLE
|
|
--
|
|
2.49.0
|
|
|