diff options
Diffstat (limited to 'src/refresh/sw/draw.c')
-rw-r--r-- | src/refresh/sw/draw.c | 165 |
1 files changed, 63 insertions, 102 deletions
diff --git a/src/refresh/sw/draw.c b/src/refresh/sw/draw.c index 706c21e..9bd9b51 100644 --- a/src/refresh/sw/draw.c +++ b/src/refresh/sw/draw.c @@ -88,9 +88,8 @@ with this program; if not, write to the Free Software Foundation, Inc., } while (count) typedef struct { - color_t colors[2]; - clipRect_t clipRect; - int flags; + color_t colors[2]; + clipRect_t clip; } drawStatic_t; static drawStatic_t draw; @@ -107,6 +106,10 @@ void R_InitDraw(void) memset(&draw, 0, sizeof(draw)); draw.colors[0].u32 = U32_WHITE; draw.colors[1].u32 = U32_WHITE; + draw.clip.left = 0; + draw.clip.top = 0; + draw.clip.right = r_config.width; + draw.clip.bottom = r_config.height; } void R_ClearColor(void) @@ -127,15 +130,31 @@ void R_SetColor(uint32_t color) draw.colors[1].u8[3] = draw.colors[0].u8[3]; } -void R_SetClipRect(int flags, const clipRect_t *clip) +void R_SetClipRect(const clipRect_t *clip) { - draw.flags &= ~DRAW_CLIP_MASK; - - if (flags == DRAW_CLIP_DISABLED) { + if (!clip) { +clear: + draw.clip.left = 0; + draw.clip.top = 0; + draw.clip.right = r_config.width; + draw.clip.bottom = r_config.height; return; } - draw.flags |= flags; - draw.clipRect = *clip; + + draw.clip = *clip; + + if (draw.clip.left < 0) + draw.clip.left = 0; + if (draw.clip.top < 0) + draw.clip.top = 0; + if (draw.clip.right > r_config.width) + draw.clip.right = r_config.width; + if (draw.clip.bottom > r_config.height) + draw.clip.bottom = r_config.height; + if (draw.clip.right < draw.clip.left) + goto clear; + if (draw.clip.bottom < draw.clip.top) + goto clear; } /* @@ -149,60 +168,30 @@ static void R_DrawStretchData(int x, int y, int w, int h, int xx, int yy, byte *srcpixels, *dstpixels, *dst, *src; int v, u; int ustep, vstep; - int skipv, skipu; - int width, height; + int skipv = 0, skipu = 0; + int width = w, height = h; int count; byte *_src; int tmp[4]; - skipv = skipu = 0; - width = w; - height = h; - - if (draw.flags & DRAW_CLIP_MASK) { - clipRect_t *clip = &draw.clipRect; - - if (draw.flags & DRAW_CLIP_LEFT) { - if (x < clip->left) { - skipu = clip->left - x; - if (w <= skipu) { - return; - } - w -= skipu; - x = clip->left; - } - } - - if (draw.flags & DRAW_CLIP_RIGHT) { - if (x >= clip->right) { - return; - } - if (x + w > clip->right) { - w = clip->right - x; - } - } - - if (draw.flags & DRAW_CLIP_TOP) { - if (y < clip->top) { - skipv = clip->top - y; - if (h <= skipv) { - return; - } - h -= skipv; - y = clip->top; - } - } - - if (draw.flags & DRAW_CLIP_BOTTOM) { - if (y >= clip->bottom) { - return; - } - if (y + h > clip->bottom) { - h = clip->bottom - y; - } - } + if (x < draw.clip.left) { + skipu = draw.clip.left - x; + w -= skipu; + x = draw.clip.left; + } + if (y < draw.clip.top) { + skipv = draw.clip.top - y; + h -= skipv; + y = draw.clip.top; } + if (x + w > draw.clip.right) + w = draw.clip.right - x; + if (y + h > draw.clip.bottom) + h = draw.clip.bottom - y; + if (w <= 0 || h <= 0) + return; + srcpixels = data + yy * pitch + xx * TEX_BYTES; dstpixels = vid.buffer + y * vid.rowbytes + x * VID_BYTES; @@ -302,55 +291,27 @@ static void R_DrawFixedData(int x, int y, int w, int h, { byte *srcpixels, *dstpixels; byte *dst, *src; - int skipv, skipu; + int skipv = 0, skipu = 0; int count; int tmp[4]; - skipv = skipu = 0; - - if (draw.flags & DRAW_CLIP_MASK) { - clipRect_t *clip = &draw.clipRect; - - if (draw.flags & DRAW_CLIP_LEFT) { - if (x < clip->left) { - skipu = clip->left - x; - if (w <= skipu) { - return; - } - w -= skipu; - x = clip->left; - } - } - - if (draw.flags & DRAW_CLIP_RIGHT) { - if (x >= clip->right) { - return; - } - if (x + w > clip->right) { - w = clip->right - x; - } - } - - if (draw.flags & DRAW_CLIP_TOP) { - if (y < clip->top) { - skipv = clip->top - y; - if (h <= skipv) { - return; - } - h -= skipv; - y = clip->top; - } - } - - if (draw.flags & DRAW_CLIP_BOTTOM) { - if (y >= clip->bottom) { - return; - } - if (y + h > clip->bottom) { - h = clip->bottom - y; - } - } + if (x < draw.clip.left) { + skipu = draw.clip.left - x; + w -= skipu; + x = draw.clip.left; } + if (y < draw.clip.top) { + skipv = draw.clip.top - y; + h -= skipv; + y = draw.clip.top; + } + + if (x + w > draw.clip.right) + w = draw.clip.right - x; + if (y + h > draw.clip.bottom) + h = draw.clip.bottom - y; + if (w <= 0 || h <= 0) + return; srcpixels = data + skipv * pitch + skipu * TEX_BYTES; dstpixels = vid.buffer + y * vid.rowbytes + x * VID_BYTES; |