mirror of
https://github.com/ocornut/imgui.git
synced 2026-05-09 07:12:23 +00:00
ImDrawList: made AddCallback() user data default to NULL + minor amends/comments.
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
// CHANGELOG
|
// CHANGELOG
|
||||||
// (minor and older changes stripped away, please see git history for details)
|
// (minor and older changes stripped away, please see git history for details)
|
||||||
// 2026-01-19: DirectX11: Added 'SamplerNearest' in ImGui_ImplDX11_RenderState. Renamed 'SamplerDefault' to 'SamplerLinear'.
|
// 2026-01-19: DirectX10: Added 'SamplerNearest' in ImGui_ImplDX10_RenderState. Renamed 'SamplerDefault' to 'SamplerLinear'.
|
||||||
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
// 2025-09-18: Call platform_io.ClearRendererHandlers() on shutdown.
|
||||||
// 2025-06-11: DirectX10: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
// 2025-06-11: DirectX10: Added support for ImGuiBackendFlags_RendererHasTextures, for dynamic font atlas.
|
||||||
// 2025-05-07: DirectX10: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
|
// 2025-05-07: DirectX10: Honor draw_data->FramebufferScale to allow for custom backends and experiment using it (consistently with other renderer backends, even though in normal condition it is not set under Windows).
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
// Learn about Dear ImGui:
|
// Learn about Dear ImGui:
|
||||||
// - FAQ https://dearimgui.com/faq
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
// Learn about Dear ImGui:
|
// Learn about Dear ImGui:
|
||||||
// - FAQ https://dearimgui.com/faq
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
|
|
||||||
// You can copy and use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
// You can use unmodified imgui_impl_* files in your project. See examples/ folder for examples of using this.
|
||||||
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
// Prefer including the entire imgui/ repository into your project (either as a copy or as a submodule), and only build the backends you need.
|
||||||
// Learn about Dear ImGui:
|
// Learn about Dear ImGui:
|
||||||
// - FAQ https://dearimgui.com/faq
|
// - FAQ https://dearimgui.com/faq
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [!] Renderer: User texture binding. Use 'VkDescriptorSet' as texture identifier. Call ImGui_ImplVulkan_AddTexture() to register one. Read the FAQ about ImTextureID/ImTextureRef + https://github.com/ocornut/imgui/pull/914 for discussions.
|
// [!] Renderer: User texture binding. Use a VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE 'VkDescriptorSet' as texture identifier. Call ImGui_ImplVulkan_AddTexture() to register one. Read the FAQ about ImTextureID/ImTextureRef + https://github.com/ocornut/imgui/pull/914 for discussions.
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
// [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).
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
// This needs to be used along with a Platform Backend (e.g. GLFW, SDL, Win32, custom..)
|
||||||
|
|
||||||
// Implemented features:
|
// Implemented features:
|
||||||
// [!] Renderer: User texture binding. Use 'VkDescriptorSet' as texture identifier. Call ImGui_ImplVulkan_AddTexture() to register one. Read the FAQ about ImTextureID/ImTextureRef + https://github.com/ocornut/imgui/pull/914 for discussions.
|
// [!] Renderer: User texture binding. Use a VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE 'VkDescriptorSet' as texture identifier. Call ImGui_ImplVulkan_AddTexture() to register one. Read the FAQ about ImTextureID/ImTextureRef + https://github.com/ocornut/imgui/pull/914 for discussions.
|
||||||
// [X] Renderer: Large meshes support (64k+ vertices) even with 16-bit indices (ImGuiBackendFlags_RendererHasVtxOffset).
|
// [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).
|
// [X] Renderer: Texture updates support for dynamic font atlas (ImGuiBackendFlags_RendererHasTextures).
|
||||||
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
// [X] Renderer: Expose selected render state for draw callbacks to use. Access in '(ImGui_ImplXXXX_RenderState*)GetPlatformIO().Renderer_RenderState'.
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ struct ImGui_ImplWGPU_Texture
|
|||||||
|
|
||||||
struct RenderResources
|
struct RenderResources
|
||||||
{
|
{
|
||||||
WGPUSampler Sampler = nullptr; // Sampler for textures
|
WGPUSampler SamplerLinear = nullptr; // Sampler for textures
|
||||||
WGPUBuffer Uniforms = nullptr; // Shader uniforms
|
WGPUBuffer Uniforms = nullptr; // Shader uniforms
|
||||||
WGPUBindGroup CommonBindGroup = nullptr; // Resources bind-group to bind the common resources to pipeline
|
WGPUBindGroup CommonBindGroup = nullptr; // Resources bind-group to bind the common resources to pipeline
|
||||||
ImGuiStorage ImageBindGroups; // Resources bind-group to bind the font/image resources to pipeline (this is a key->value map)
|
ImGuiStorage ImageBindGroups; // Resources bind-group to bind the font/image resources to pipeline (this is a key->value map)
|
||||||
@@ -296,7 +296,7 @@ static void SafeRelease(WGPUShaderModule& res)
|
|||||||
}
|
}
|
||||||
static void SafeRelease(RenderResources& res)
|
static void SafeRelease(RenderResources& res)
|
||||||
{
|
{
|
||||||
SafeRelease(res.Sampler);
|
SafeRelease(res.SamplerLinear);
|
||||||
SafeRelease(res.Uniforms);
|
SafeRelease(res.Uniforms);
|
||||||
SafeRelease(res.CommonBindGroup);
|
SafeRelease(res.CommonBindGroup);
|
||||||
SafeRelease(res.ImageBindGroupLayout);
|
SafeRelease(res.ImageBindGroupLayout);
|
||||||
@@ -538,6 +538,7 @@ void ImGui_ImplWGPU_RenderDrawData(ImDrawData* draw_data, WGPURenderPassEncoder
|
|||||||
{
|
{
|
||||||
// User callback, registered via ImDrawList::AddCallback()
|
// 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.)
|
// (ImDrawCallback_ResetRenderState is a special callback value used by the user to request the renderer to reset render state.)
|
||||||
|
IM_ASSERT(pcmd->UserCallback != ImDrawCallback_SetSamplerLinear && pcmd->UserCallback != ImDrawCallback_SetSamplerNearest); // Unsupported.
|
||||||
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
if (pcmd->UserCallback == ImDrawCallback_ResetRenderState)
|
||||||
ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr);
|
ImGui_ImplWGPU_SetupRenderState(draw_data, pass_encoder, fr);
|
||||||
else
|
else
|
||||||
@@ -824,13 +825,13 @@ bool ImGui_ImplWGPU_CreateDeviceObjects()
|
|||||||
sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
|
sampler_desc.addressModeV = WGPUAddressMode_ClampToEdge;
|
||||||
sampler_desc.addressModeW = WGPUAddressMode_ClampToEdge;
|
sampler_desc.addressModeW = WGPUAddressMode_ClampToEdge;
|
||||||
sampler_desc.maxAnisotropy = 1;
|
sampler_desc.maxAnisotropy = 1;
|
||||||
bd->renderResources.Sampler = wgpuDeviceCreateSampler(bd->wgpuDevice, &sampler_desc);
|
bd->renderResources.SamplerLinear = wgpuDeviceCreateSampler(bd->wgpuDevice, &sampler_desc);
|
||||||
|
|
||||||
// Create resource bind group
|
// Create resource bind group
|
||||||
WGPUBindGroupEntry common_bg_entries[] =
|
WGPUBindGroupEntry common_bg_entries[] =
|
||||||
{
|
{
|
||||||
{ nullptr, 0, bd->renderResources.Uniforms, 0, MEMALIGN(sizeof(Uniforms), 16), 0, 0 },
|
{ nullptr, 0, bd->renderResources.Uniforms, 0, MEMALIGN(sizeof(Uniforms), 16), 0, 0 },
|
||||||
{ nullptr, 1, 0, 0, 0, bd->renderResources.Sampler, 0 },
|
{ nullptr, 1, 0, 0, 0, bd->renderResources.SamplerLinear, 0 },
|
||||||
};
|
};
|
||||||
WGPUBindGroupDescriptor common_bg_descriptor = {};
|
WGPUBindGroupDescriptor common_bg_descriptor = {};
|
||||||
common_bg_descriptor.layout = bg_layouts[0];
|
common_bg_descriptor.layout = bg_layouts[0];
|
||||||
@@ -896,7 +897,7 @@ bool ImGui_ImplWGPU_Init(ImGui_ImplWGPU_InitInfo* init_info)
|
|||||||
bd->numFramesInFlight = init_info->NumFramesInFlight;
|
bd->numFramesInFlight = init_info->NumFramesInFlight;
|
||||||
bd->frameIndex = UINT_MAX;
|
bd->frameIndex = UINT_MAX;
|
||||||
|
|
||||||
bd->renderResources.Sampler = nullptr;
|
bd->renderResources.SamplerLinear = nullptr;
|
||||||
bd->renderResources.Uniforms = nullptr;
|
bd->renderResources.Uniforms = nullptr;
|
||||||
bd->renderResources.CommonBindGroup = nullptr;
|
bd->renderResources.CommonBindGroup = nullptr;
|
||||||
bd->renderResources.ImageBindGroups.Data.reserve(100);
|
bd->renderResources.ImageBindGroups.Data.reserve(100);
|
||||||
|
|||||||
@@ -113,6 +113,8 @@ Other Changes:
|
|||||||
reporting the common clipper error over a table sanity check assert). (#9350)
|
reporting the common clipper error over a table sanity check assert). (#9350)
|
||||||
- Tweaked assert triggering when first item height measurement fails, and made it
|
- Tweaked assert triggering when first item height measurement fails, and made it
|
||||||
a better recoverable error. (#9350)
|
a better recoverable error. (#9350)
|
||||||
|
- DrawList:
|
||||||
|
- Made AddCallback() user data default parameter.
|
||||||
- Misc:
|
- Misc:
|
||||||
- Minor optimization: reduce redudant label scanning in common widgets.
|
- Minor optimization: reduce redudant label scanning in common widgets.
|
||||||
- Added missing Test Engine hooks for PlotXXX(), VSliderXXX(), TableHeader().
|
- Added missing Test Engine hooks for PlotXXX(), VSliderXXX(), TableHeader().
|
||||||
|
|||||||
2
imgui.h
2
imgui.h
@@ -3385,7 +3385,7 @@ struct ImDrawList
|
|||||||
// - If userdata_size == 0: we copy/store the 'userdata' argument as-is. It will be available unmodified in ImDrawCmd::UserCallbackData during render.
|
// - If userdata_size == 0: we copy/store the 'userdata' argument as-is. It will be available unmodified in ImDrawCmd::UserCallbackData during render.
|
||||||
// - If userdata_size > 0, we copy/store 'userdata_size' bytes pointed to by 'userdata'. We store them in a buffer stored inside the drawlist. ImDrawCmd::UserCallbackData will point inside that buffer so you have to retrieve data from there. Your callback may need to use ImDrawCmd::UserCallbackDataSize if you expect dynamically-sized data.
|
// - If userdata_size > 0, we copy/store 'userdata_size' bytes pointed to by 'userdata'. We store them in a buffer stored inside the drawlist. ImDrawCmd::UserCallbackData will point inside that buffer so you have to retrieve data from there. Your callback may need to use ImDrawCmd::UserCallbackDataSize if you expect dynamically-sized data.
|
||||||
// - Support for userdata_size > 0 was added in v1.91.4, October 2024. So earlier code always only allowed to copy/store a simple void*.
|
// - Support for userdata_size > 0 was added in v1.91.4, October 2024. So earlier code always only allowed to copy/store a simple void*.
|
||||||
IMGUI_API void AddCallback(ImDrawCallback callback, void* userdata, size_t userdata_size = 0);
|
IMGUI_API void AddCallback(ImDrawCallback callback, void* userdata = NULL, size_t userdata_size = 0);
|
||||||
|
|
||||||
// Advanced: Miscellaneous
|
// Advanced: Miscellaneous
|
||||||
IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible
|
IMGUI_API void AddDrawCmd(); // This is useful if you need to forcefully create a new draw call (to allow for dependent rendering / blending). Otherwise primitives are merged into the same draw-call as much as possible
|
||||||
|
|||||||
Reference in New Issue
Block a user