render: an empty clip rect should clip all drawing

Added a test to validate this and fixed the Metal renderer

Fixes https://github.com/libsdl-org/SDL/issues/15434
This commit is contained in:
Sam Lantinga 2026-05-29 13:44:46 -07:00
parent ed2c8036a7
commit e04bfb4c6e
2 changed files with 22 additions and 8 deletions

View file

@ -1553,14 +1553,14 @@ static bool SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, c
METAL_GetOutputSize(renderer, &output.w, &output.h); METAL_GetOutputSize(renderer, &output.w, &output.h);
} }
if (SDL_GetRectIntersection(&output, &clip, &clip)) { SDL_GetRectIntersection(&output, &clip, &clip);
MTLScissorRect mtlrect;
mtlrect.x = clip.x; MTLScissorRect mtlrect;
mtlrect.y = clip.y; mtlrect.x = clip.x;
mtlrect.width = clip.w; mtlrect.y = clip.y;
mtlrect.height = clip.h; mtlrect.width = clip.w;
[data.mtlcmdencoder setScissorRect:mtlrect]; mtlrect.height = clip.h;
} [data.mtlcmdencoder setScissorRect:mtlrect];
statecache->cliprect_dirty = false; statecache->cliprect_dirty = false;
} }

View file

@ -1361,6 +1361,20 @@ static int SDLCALL render_testClipRect(void *arg)
/* Check to see if final image matches. */ /* Check to see if final image matches. */
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE); compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
/*
* Verify that empty cliprect clips all drawing
*/
/* Set the cliprect and do a fill operation */
cliprect.h = 0;
CHECK_FUNC(SDL_SetRenderClipRect, (renderer, &cliprect))
CHECK_FUNC(SDL_SetRenderDrawColor, (renderer, 255, 0, 0, SDL_ALPHA_OPAQUE))
CHECK_FUNC(SDL_RenderFillRect, (renderer, NULL))
CHECK_FUNC(SDL_SetRenderClipRect, (renderer, NULL))
/* Check to see if final image matches. */
compare(referenceSurface, ALLOWABLE_ERROR_OPAQUE);
/* /*
* Verify that clear ignores the cliprect * Verify that clear ignores the cliprect
*/ */