Skip to content

Commit 5fcc83d

Browse files
Wohlstandslouken
authored andcommitted
Vita Render: Limit the scope of cliprect to viewport
Don't allow cliprect be larger than viewport's scope (cherry picked from commit 6701f93) # Conflicts: # src/render/vitagxm/SDL_render_vita_gxm.c
1 parent 1bd5110 commit 5fcc83d

File tree

1 file changed

+35
-2
lines changed

1 file changed

+35
-2
lines changed

src/render/vitagxm/SDL_render_vita_gxm.c

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,35 @@ static SceGxmTextureAddrMode TranslateAddressMode(SDL_TextureAddressMode mode)
820820
}
821821
}
822822

823+
static void ClampCliprectToViewport(SDL_Rect *clip, const SDL_Rect *viewport)
824+
{
825+
int max_x_v, max_y_v, max_x_c, max_y_c;
826+
827+
if (clip->x < 0) {
828+
clip->w += clip->x;
829+
clip->x = 0;
830+
}
831+
832+
if (clip->y < 0) {
833+
clip->h += clip->y;
834+
clip->y = 0;
835+
}
836+
837+
max_x_c = clip->x + clip->w;
838+
max_y_c = clip->y + clip->h;
839+
840+
max_x_v = viewport->x + viewport->w;
841+
max_y_v = viewport->y + viewport->h;
842+
843+
if (max_x_c > max_x_v) {
844+
clip->w -= (max_x_v - max_x_c);
845+
}
846+
847+
if (max_y_c > max_y_v) {
848+
clip->h -= (max_y_v - max_y_c);
849+
}
850+
}
851+
823852
static bool SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd)
824853
{
825854
SDL_Texture *texture = cmd->data.draw.texture;
@@ -863,8 +892,12 @@ static bool SetDrawState(VITA_GXM_RenderData *data, const SDL_RenderCommand *cmd
863892
}
864893

865894
if ((data->drawstate.cliprect_enabled || data->drawstate.viewport_is_set) && data->drawstate.cliprect_dirty) {
866-
const SDL_Rect *rect = &data->drawstate.cliprect;
867-
set_clip_rectangle(data, rect->x, rect->y, rect->x + rect->w, rect->y + rect->h);
895+
SDL_Rect rect;
896+
SDL_copyp(&rect, &data->drawstate.cliprect);
897+
if (data->drawstate.viewport_is_set) {
898+
ClampCliprectToViewport(&rect, &data->drawstate.viewport);
899+
}
900+
set_clip_rectangle(data, rect.x, rect.y, rect.x + rect.w, rect.y + rect.h);
868901
data->drawstate.cliprect_dirty = false;
869902
}
870903

0 commit comments

Comments
 (0)