bring back clipping to v_video functions (#1518)

* add clipping to V_FillRect

* add clipping to V_CopyRect
This commit is contained in:
Roman Fomin 2024-02-21 17:43:35 +07:00 committed by GitHub
parent 81ebfeffaa
commit 4b0f729d52
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -632,6 +632,35 @@ int V_ScaleY(int y)
return y1lookup[y];
}
static void V_ClipRect(vrect_t *rect)
{
// clip to left and top edges
rect->cx1 = rect->x >= 0 ? rect->x : 0;
rect->cy1 = rect->y >= 0 ? rect->y : 0;
// determine right and bottom edges
rect->cx2 = rect->x + rect->w - 1;
rect->cy2 = rect->y + rect->h - 1;
// clip right and bottom edges
if (rect->cx2 >= video.unscaledw)
rect->cx2 = video.unscaledw - 1;
if (rect->cy2 >= SCREENHEIGHT)
rect->cy2 = SCREENHEIGHT - 1;
// determine clipped width and height
rect->cw = rect->cx2 - rect->cx1 + 1;
rect->ch = rect->cy2 - rect->cy1 + 1;
}
static void V_ScaleClippedRect(vrect_t *rect)
{
rect->sx = x1lookup[rect->cx1];
rect->sy = y1lookup[rect->cy1];
rect->sw = x2lookup[rect->cx2] - rect->sx + 1;
rect->sh = y2lookup[rect->cy2] - rect->sy + 1;
}
void V_FillRect(int x, int y, int width, int height, byte color)
{
vrect_t dstrect;
@ -641,7 +670,13 @@ void V_FillRect(int x, int y, int width, int height, byte color)
dstrect.w = width;
dstrect.h = height;
V_ScaleRect(&dstrect);
V_ClipRect(&dstrect);
// clipped away completely?
if (dstrect.cw <= 0 || dstrect.ch <= 0)
return;
V_ScaleClippedRect(&dstrect);
byte* dest = V_ADDRESS(dest_screen, dstrect.sx, dstrect.sy);
@ -683,13 +718,26 @@ void V_CopyRect(int srcx, int srcy, pixel_t *source,
srcrect.w = width;
srcrect.h = height;
V_ClipRect(&srcrect);
// clipped away completely?
if (srcrect.cw <= 0 || srcrect.ch <= 0)
return;
V_ScaleClippedRect(&srcrect);
dstrect.x = destx;
dstrect.y = desty;
dstrect.w = width;
dstrect.h = height;
V_ScaleRect(&srcrect);
V_ScaleRect(&dstrect);
V_ClipRect(&dstrect);
// clipped away completely?
if (dstrect.cw <= 0 || dstrect.ch <= 0)
return;
V_ScaleClippedRect(&dstrect);
// use the smaller of the two scaled rect widths / heights
usew = (srcrect.sw < dstrect.sw ? srcrect.sw : dstrect.sw);
@ -706,35 +754,6 @@ void V_CopyRect(int srcx, int srcy, pixel_t *source,
}
}
static void V_ClipRect(vrect_t *rect)
{
// clip to left and top edges
rect->cx1 = rect->x >= 0 ? rect->x : 0;
rect->cy1 = rect->y >= 0 ? rect->y : 0;
// determine right and bottom edges
rect->cx2 = rect->x + rect->w - 1;
rect->cy2 = rect->y + rect->h - 1;
// clip right and bottom edges
if (rect->cx2 >= video.unscaledw)
rect->cx2 = video.unscaledw - 1;
if (rect->cy2 >= SCREENHEIGHT)
rect->cy2 = SCREENHEIGHT - 1;
// determine clipped width and height
rect->cw = rect->cx2 - rect->cx1 + 1;
rect->ch = rect->cy2 - rect->cy1 + 1;
}
static void V_ScaleClippedRect(vrect_t *rect)
{
rect->sx = x1lookup[rect->cx1];
rect->sy = y1lookup[rect->cy1];
rect->sw = x2lookup[rect->cx2] - rect->sx + 1;
rect->sh = y2lookup[rect->cy2] - rect->sy + 1;
}
//
// V_DrawBlock
//