Skip to content

Commit

Permalink
METAL: clip rect w/h must be <= render pass
Browse files Browse the repository at this point in the history
  • Loading branch information
1bsyl committed Mar 15, 2022
1 parent 7c421fe commit 3bebdac
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions src/render/metal/SDL_render_metal.m
Original file line number Diff line number Diff line change
Expand Up @@ -1255,22 +1255,29 @@ - (void)dealloc
}

if (statecache->cliprect_dirty) {
MTLScissorRect mtlrect;
SDL_Rect output;
SDL_Rect clip;
if (statecache->cliprect_enabled) {
const SDL_Rect *rect = &statecache->cliprect;
mtlrect.x = statecache->viewport.x + rect->x;
mtlrect.y = statecache->viewport.y + rect->y;
mtlrect.width = rect->w;
mtlrect.height = rect->h;
clip = statecache->cliprect;
clip.x += statecache->viewport.x;
clip.y += statecache->viewport.y;
} else {
mtlrect.x = statecache->viewport.x;
mtlrect.y = statecache->viewport.y;
mtlrect.width = statecache->viewport.w;
mtlrect.height = statecache->viewport.h;
clip = statecache->viewport;
}
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];
}

statecache->cliprect_dirty = SDL_FALSE;
}

Expand Down

1 comment on commit 3bebdac

@1bsyl
Copy link
Contributor Author

@1bsyl 1bsyl commented on 3bebdac Sep 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.