METAL: clip rect w/h must be <= render pass

This commit is contained in:
Sylvain Becker 2022-03-15 10:37:17 +01:00
parent 7c421fec16
commit 3bebdaccb7
1 changed files with 18 additions and 11 deletions

View File

@ -1255,22 +1255,29 @@ SetDrawState(SDL_Renderer *renderer, const SDL_RenderCommand *cmd, const SDL_Met
} }
if (statecache->cliprect_dirty) { if (statecache->cliprect_dirty) {
MTLScissorRect mtlrect; SDL_Rect output;
SDL_Rect clip;
if (statecache->cliprect_enabled) { if (statecache->cliprect_enabled) {
const SDL_Rect *rect = &statecache->cliprect; clip = statecache->cliprect;
mtlrect.x = statecache->viewport.x + rect->x; clip.x += statecache->viewport.x;
mtlrect.y = statecache->viewport.y + rect->y; clip.y += statecache->viewport.y;
mtlrect.width = rect->w;
mtlrect.height = rect->h;
} else { } else {
mtlrect.x = statecache->viewport.x; clip = statecache->viewport;
mtlrect.y = statecache->viewport.y;
mtlrect.width = statecache->viewport.w;
mtlrect.height = statecache->viewport.h;
} }
if (mtlrect.width > 0 && mtlrect.height > 0) {
/* Set Scissor Rect Validation: w/h must be <= render pass */
SDL_zero(output);
METAL_GetOutputSize(renderer, &output.w, &output.h);
if (SDL_IntersectRect(&output, &clip, &clip)) {
MTLScissorRect mtlrect;
mtlrect.x = clip.x;
mtlrect.y = clip.y;
mtlrect.width = clip.w;
mtlrect.height = clip.h;
[data.mtlcmdencoder setScissorRect:mtlrect]; [data.mtlcmdencoder setScissorRect:mtlrect];
} }
statecache->cliprect_dirty = SDL_FALSE; statecache->cliprect_dirty = SDL_FALSE;
} }