mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Backends: Metal: Fixed a crash when clipping rect larger than framebuffer is submitted. (#4464)
Backends: Normalize clipping rect handling across backends. + Squashed amends.
This commit is contained in:
@ -511,31 +511,27 @@ void ImGui_ImplVulkan_RenderDrawData(ImDrawData* draw_data, VkCommandBuffer comm
|
||||
else
|
||||
{
|
||||
// Project scissor/clipping rectangles into framebuffer space
|
||||
ImVec4 clip_rect;
|
||||
clip_rect.x = (pcmd->ClipRect.x - clip_off.x) * clip_scale.x;
|
||||
clip_rect.y = (pcmd->ClipRect.y - clip_off.y) * clip_scale.y;
|
||||
clip_rect.z = (pcmd->ClipRect.z - clip_off.x) * clip_scale.x;
|
||||
clip_rect.w = (pcmd->ClipRect.w - clip_off.y) * clip_scale.y;
|
||||
ImVec2 clip_min((pcmd->ClipRect.x - clip_off.x) * clip_scale.x, (pcmd->ClipRect.y - clip_off.y) * clip_scale.y);
|
||||
ImVec2 clip_max((pcmd->ClipRect.z - clip_off.x) * clip_scale.x, (pcmd->ClipRect.w - clip_off.y) * clip_scale.y);
|
||||
|
||||
if (clip_rect.x < fb_width && clip_rect.y < fb_height && clip_rect.z >= 0.0f && clip_rect.w >= 0.0f)
|
||||
{
|
||||
// Negative offsets are illegal for vkCmdSetScissor
|
||||
if (clip_rect.x < 0.0f)
|
||||
clip_rect.x = 0.0f;
|
||||
if (clip_rect.y < 0.0f)
|
||||
clip_rect.y = 0.0f;
|
||||
// Clamp to viewport as vkCmdSetScissor() won't accept values that are off bounds
|
||||
if (clip_min.x < 0.0f) { clip_min.x = 0.0f; }
|
||||
if (clip_min.y < 0.0f) { clip_min.y = 0.0f; }
|
||||
if (clip_max.x > fb_width) { clip_max.x = (float)fb_width; }
|
||||
if (clip_max.y > fb_height) { clip_max.y = (float)fb_height; }
|
||||
if (clip_max.x < clip_min.x || clip_max.y < clip_min.y)
|
||||
continue;
|
||||
|
||||
// Apply scissor/clipping rectangle
|
||||
VkRect2D scissor;
|
||||
scissor.offset.x = (int32_t)(clip_rect.x);
|
||||
scissor.offset.y = (int32_t)(clip_rect.y);
|
||||
scissor.extent.width = (uint32_t)(clip_rect.z - clip_rect.x);
|
||||
scissor.extent.height = (uint32_t)(clip_rect.w - clip_rect.y);
|
||||
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
||||
// Apply scissor/clipping rectangle
|
||||
VkRect2D scissor;
|
||||
scissor.offset.x = (int32_t)(clip_min.x);
|
||||
scissor.offset.y = (int32_t)(clip_min.y);
|
||||
scissor.extent.width = (uint32_t)(clip_max.x - clip_min.x);
|
||||
scissor.extent.height = (uint32_t)(clip_max.y - clip_min.y);
|
||||
vkCmdSetScissor(command_buffer, 0, 1, &scissor);
|
||||
|
||||
// Draw
|
||||
vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
|
||||
}
|
||||
// Draw
|
||||
vkCmdDrawIndexed(command_buffer, pcmd->ElemCount, 1, pcmd->IdxOffset + global_idx_offset, pcmd->VtxOffset + global_vtx_offset, 0);
|
||||
}
|
||||
}
|
||||
global_idx_offset += cmd_list->IdxBuffer.Size;
|
||||
|
Reference in New Issue
Block a user