From b48296c02e231accc203b5881b2d76694315dcc4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 9 Dec 2009 15:56:56 +0000 Subject: [PATCH] Added interfaces for batch drawing of points, lines and rects: SDL_DrawPoints() SDL_BlendPoints() SDL_BlendLines() SDL_DrawLines() SDL_FillRects() SDL_BlendRects() SDL_RenderPoints() SDL_RenderLines() SDL_RenderRects() Renamed SDL_RenderFill() to SDL_RenderRect() --- include/SDL_compat.h | 2 + include/SDL_rect.h | 22 +++ include/SDL_surface.h | 39 +++-- include/SDL_video.h | 34 ++++- src/video/SDL_blendline.c | 99 +++++++++++-- src/video/SDL_blendpoint.c | 108 ++++++++++++-- src/video/SDL_blendrect.c | 151 +++++++++++++++----- src/video/SDL_draw.h | 6 +- src/video/SDL_drawline.c | 59 +++++++- src/video/SDL_drawpoint.c | 58 +++++++- src/video/SDL_fillrect.c | 67 +++++---- src/video/SDL_rect.c | 78 ++++++++++ src/video/SDL_renderer_gl.c | 104 +++++++++----- src/video/SDL_renderer_gles.c | 84 +++++------ src/video/SDL_renderer_sw.c | 235 ++++++++++++++++++------------- src/video/SDL_sysvideo.h | 10 +- src/video/SDL_video.c | 100 ++++++++----- src/video/dummy/SDL_nullrender.c | 79 +++++------ src/video/win32/SDL_d3drender.c | 186 ++++++++++++------------ src/video/win32/SDL_gdirender.c | 130 ++++++++++------- test/automated/render/render.c | 24 ++-- test/testdraw2.c | 8 +- test/testintersections.c | 10 +- test/testnative.c | 6 +- test/testsprite2.c | 14 +- test/testspriteminimal.c | 2 +- 26 files changed, 1192 insertions(+), 523 deletions(-) diff --git a/include/SDL_compat.h b/include/SDL_compat.h index a6d28a003..530714b2a 100644 --- a/include/SDL_compat.h +++ b/include/SDL_compat.h @@ -350,6 +350,8 @@ extern DECLSPEC int SDLCALL SDL_EnableKeyRepeat(int delay, int interval); extern DECLSPEC void SDLCALL SDL_GetKeyRepeat(int *delay, int *interval); extern DECLSPEC int SDLCALL SDL_EnableUNICODE(int enable); +#define SDL_RenderFill SDL_RenderRect + /*@}*//*Compatibility*/ /* Ends C function definitions when using C++ */ diff --git a/include/SDL_rect.h b/include/SDL_rect.h index d6cb7942c..f32dbf090 100644 --- a/include/SDL_rect.h +++ b/include/SDL_rect.h @@ -42,6 +42,17 @@ extern "C" { /* *INDENT-ON* */ #endif +/** + * \brief The structure that defines a point + * + * \sa SDL_EnclosePoints + */ +typedef struct +{ + int x; + int y; +} SDL_Point; + /** * \brief A rectangle, with the origin at the upper left. * @@ -50,6 +61,7 @@ extern "C" { * \sa SDL_HasIntersection * \sa SDL_IntersectRect * \sa SDL_UnionRect + * \sa SDL_EnclosePoints */ typedef struct SDL_Rect { @@ -92,6 +104,16 @@ extern DECLSPEC void SDLCALL SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result); +/** + * \brief Calculate a minimal rectangle enclosing a set of points + * + * \return SDL_TRUE if any points were within the clipping rect + */ +extern DECLSPEC SDL_bool SDLCALL SDL_EnclosePoints(const SDL_Point * points, + int count, + const SDL_Rect * clip, + SDL_Rect * result); + /** * \brief Calculate the intersection of a rectangle and line segment. * diff --git a/include/SDL_surface.h b/include/SDL_surface.h index 5c556ee3f..4c21a0be2 100644 --- a/include/SDL_surface.h +++ b/include/SDL_surface.h @@ -405,6 +405,8 @@ extern DECLSPEC int SDLCALL SDL_ConvertPixels(int width, int height, */ extern DECLSPEC int SDLCALL SDL_DrawPoint (SDL_Surface * dst, int x, int y, Uint32 color); +extern DECLSPEC int SDLCALL SDL_DrawPoints + (SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); /** * Blends a point with an RGBA value. @@ -415,8 +417,11 @@ extern DECLSPEC int SDLCALL SDL_DrawPoint * \return 0 on success, or -1 on error. */ extern DECLSPEC int SDLCALL SDL_BlendPoint - (SDL_Surface * dst, int x, int y, int blendMode, - Uint8 r, Uint8 g, Uint8 b, Uint8 a); + (SDL_Surface * dst, int x, int y, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern DECLSPEC int SDLCALL SDL_BlendPoints + (SDL_Surface * dst, const SDL_Point * points, int count, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /** * Draws a line with \c color. @@ -428,6 +433,8 @@ extern DECLSPEC int SDLCALL SDL_BlendPoint */ extern DECLSPEC int SDLCALL SDL_DrawLine (SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color); +extern DECLSPEC int SDLCALL SDL_DrawLines + (SDL_Surface * dst, const SDL_Point * points, int count, Uint32 color); /** * Blends an RGBA value along a line. @@ -435,16 +442,16 @@ extern DECLSPEC int SDLCALL SDL_DrawLine * \return 0 on success, or -1 on error. */ extern DECLSPEC int SDLCALL SDL_BlendLine - (SDL_Surface * dst, int x1, int y1, int x2, int y2, int blendMode, - Uint8 r, Uint8 g, Uint8 b, Uint8 a); + (SDL_Surface * dst, int x1, int y1, int x2, int y2, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern DECLSPEC int SDLCALL SDL_BlendLines + (SDL_Surface * dst, const SDL_Point * points, int count, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /** * Performs a fast fill of the given rectangle with \c color. * - * The given rectangle is clipped to the destination surface clip area - * and the final fill rectangle is saved in the passed in pointer. - * - * If \c dstrect is NULL, the whole surface will be filled with \c color. + * If \c rect is NULL, the whole surface will be filled with \c color. * * The color should be a pixel of the format used by the surface, and * can be generated by the SDL_MapRGB() function. @@ -452,21 +459,23 @@ extern DECLSPEC int SDLCALL SDL_BlendLine * \return 0 on success, or -1 on error. */ extern DECLSPEC int SDLCALL SDL_FillRect - (SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color); + (SDL_Surface * dst, const SDL_Rect * rect, Uint32 color); +extern DECLSPEC int SDLCALL SDL_FillRects + (SDL_Surface * dst, const SDL_Rect ** rects, int count, Uint32 color); /** * Blends an RGBA value into the given rectangle. * - * The given rectangle is clipped to the destination surface clip area - * and the final fill rectangle is saved in the passed in pointer. - * - * If \c dstrect is NULL, the whole surface will be filled with \c color. + * If \c rect is NULL, the whole surface will be filled with \c color. * * \return This function returns 0 on success, or -1 on error. */ extern DECLSPEC int SDLCALL SDL_BlendRect - (SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, Uint8 g, - Uint8 b, Uint8 a); + (SDL_Surface * dst, const SDL_Rect * rect, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); +extern DECLSPEC int SDLCALL SDL_BlendRects + (SDL_Surface * dst, const SDL_Rect ** rects, int count, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a); /** * Performs a fast blit from the source surface to the destination surface. diff --git a/include/SDL_video.h b/include/SDL_video.h index 6ae110d07..63b18ca0f 100644 --- a/include/SDL_video.h +++ b/include/SDL_video.h @@ -1147,6 +1147,17 @@ extern DECLSPEC int SDLCALL SDL_GetRenderDrawBlendMode(int *blendMode); */ extern DECLSPEC int SDLCALL SDL_RenderPoint(int x, int y); +/** + * \brief Draw some number of points on the current rendering target. + * + * \param points The points to draw + * \param count The number of points to draw + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderPoints(const SDL_Point * points, + int count); + /** * \brief Draw a line on the current rendering target. * @@ -1159,6 +1170,17 @@ extern DECLSPEC int SDLCALL SDL_RenderPoint(int x, int y); */ extern DECLSPEC int SDLCALL SDL_RenderLine(int x1, int y1, int x2, int y2); +/** + * \brief Draw a series of connected lines on the current rendering target. + * + * \param points The points along the lines + * \param count The number of points, drawing count-1 lines + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderLines(const SDL_Point * points, + int count); + /** * \brief Fill the current rendering target with the drawing color. * @@ -1167,7 +1189,17 @@ extern DECLSPEC int SDLCALL SDL_RenderLine(int x1, int y1, int x2, int y2); * * \return 0 on success, or -1 if there is no rendering context current. */ -extern DECLSPEC int SDLCALL SDL_RenderFill(const SDL_Rect * rect); +extern DECLSPEC int SDLCALL SDL_RenderRect(const SDL_Rect * rect); + +/** + * \brief Fill some number of rectangles in the current rendering target with the drawing color. + * + * \param rects A pointer to an array of destination rectangles. + * \param count The number of rectangles. + * + * \return 0 on success, or -1 if there is no rendering context current. + */ +extern DECLSPEC int SDLCALL SDL_RenderRects(const SDL_Rect ** rect, int count); /** * \brief Copy a portion of the texture to the current rendering target. diff --git a/src/video/SDL_blendline.c b/src/video/SDL_blendline.c index 5838819cd..89ee45993 100644 --- a/src/video/SDL_blendline.c +++ b/src/video/SDL_blendline.c @@ -195,8 +195,6 @@ int SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { - SDL_PixelFormat *fmt = dst->format; - /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { SDL_SetError("SDL_BlendLine(): Unsupported surface format"); @@ -209,32 +207,31 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, } - if ((blendMode == SDL_BLENDMODE_BLEND) - || (blendMode == SDL_BLENDMODE_ADD)) { + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } - switch (fmt->BitsPerPixel) { + switch (dst->format->BitsPerPixel) { case 15: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0x7C00: return SDL_BlendLine_RGB555(dst, x1, y1, x2, y2, blendMode, r, g, b, a); } break; case 16: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0xF800: return SDL_BlendLine_RGB565(dst, x1, y1, x2, y2, blendMode, r, g, b, a); } break; case 32: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0x00FF0000: - if (!fmt->Amask) { + if (!dst->format->Amask) { return SDL_BlendLine_RGB888(dst, x1, y1, x2, y2, blendMode, r, g, b, a); } else { @@ -243,15 +240,97 @@ SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, } break; } + break; default: break; } - if (!fmt->Amask) { + if (!dst->format->Amask) { return SDL_BlendLine_RGB(dst, x1, y1, x2, y2, blendMode, r, g, b, a); } else { return SDL_BlendLine_RGBA(dst, x1, y1, x2, y2, blendMode, r, g, b, a); } } +int +SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int i; + int x1, y1; + int x2, y2; + int (*func)(SDL_Surface * dst, int x1, int y1, int x2, int y2, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; + int status = 0; + + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + + /* This function doesn't work on surfaces < 8 bpp */ + if (dst->format->BitsPerPixel < 8) { + SDL_SetError("SDL_BlendLines(): Unsupported surface format"); + return -1; + } + + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { + r = DRAW_MUL(r, a); + g = DRAW_MUL(g, a); + b = DRAW_MUL(b, a); + } + + /* FIXME: Does this function pointer slow things down significantly? */ + switch (dst->format->BitsPerPixel) { + case 15: + switch (dst->format->Rmask) { + case 0x7C00: + func = SDL_BlendLine_RGB555; + } + break; + case 16: + switch (dst->format->Rmask) { + case 0xF800: + func = SDL_BlendLine_RGB565; + } + break; + case 32: + switch (dst->format->Rmask) { + case 0x00FF0000: + if (!dst->format->Amask) { + func = SDL_BlendLine_RGB888; + } else { + func = SDL_BlendLine_ARGB8888; + } + break; + } + default: + break; + } + + if (!func) { + if (!dst->format->Amask) { + func = SDL_BlendLine_RGB; + } else { + func = SDL_BlendLine_RGBA; + } + } + + for (i = 1; i < count; ++i) { + x1 = points[i-1].x; + y1 = points[i-1].y; + x2 = points[i].x; + y2 = points[i].y; + + /* Perform clipping */ + /* FIXME: We don't actually want to clip, as it may change line slope */ + if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { + continue; + } + + status = func(dst, x1, y1, x2, y2, blendMode, r, g, b, a); + } + return status; +} + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blendpoint.c b/src/video/SDL_blendpoint.c index deabd0cd0..4b5c84e0f 100644 --- a/src/video/SDL_blendpoint.c +++ b/src/video/SDL_blendpoint.c @@ -195,12 +195,15 @@ int SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { - SDL_PixelFormat *fmt = dst->format; + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { SDL_SetError("SDL_BlendPoint(): Unsupported surface format"); - return (-1); + return -1; } /* Perform clipping */ @@ -210,30 +213,29 @@ SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r, return 0; } - if ((blendMode == SDL_BLENDMODE_BLEND) - || (blendMode == SDL_BLENDMODE_ADD)) { + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } - switch (fmt->BitsPerPixel) { + switch (dst->format->BitsPerPixel) { case 15: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0x7C00: return SDL_BlendPoint_RGB555(dst, x, y, blendMode, r, g, b, a); } break; case 16: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0xF800: return SDL_BlendPoint_RGB565(dst, x, y, blendMode, r, g, b, a); } break; case 32: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0x00FF0000: - if (!fmt->Amask) { + if (!dst->format->Amask) { return SDL_BlendPoint_RGB888(dst, x, y, blendMode, r, g, b, a); } else { @@ -242,15 +244,101 @@ SDL_BlendPoint(SDL_Surface * dst, int x, int y, int blendMode, Uint8 r, } break; } + break; default: break; } - if (!fmt->Amask) { + if (!dst->format->Amask) { return SDL_BlendPoint_RGB(dst, x, y, blendMode, r, g, b, a); } else { return SDL_BlendPoint_RGBA(dst, x, y, blendMode, r, g, b, a); } } +int +SDL_BlendPoints(SDL_Surface * dst, const SDL_Point * points, int count, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + int minx, miny; + int maxx, maxy; + int i; + int x, y; + int (*func)(SDL_Surface * dst, int x, int y, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; + int status = 0; + + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + + /* This function doesn't work on surfaces < 8 bpp */ + if (dst->format->BitsPerPixel < 8) { + SDL_SetError("SDL_BlendPoints(): Unsupported surface format"); + return (-1); + } + + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { + r = DRAW_MUL(r, a); + g = DRAW_MUL(g, a); + b = DRAW_MUL(b, a); + } + + /* FIXME: Does this function pointer slow things down significantly? */ + switch (dst->format->BitsPerPixel) { + case 15: + switch (dst->format->Rmask) { + case 0x7C00: + func = SDL_BlendPoint_RGB555; + break; + } + break; + case 16: + switch (dst->format->Rmask) { + case 0xF800: + func = SDL_BlendPoint_RGB565; + break; + } + break; + case 32: + switch (dst->format->Rmask) { + case 0x00FF0000: + if (!dst->format->Amask) { + func = SDL_BlendPoint_RGB888; + } else { + func = SDL_BlendPoint_ARGB8888; + } + break; + } + break; + default: + break; + } + + if (!func) { + if (!dst->format->Amask) { + func = SDL_BlendPoint_RGB; + } else { + func = SDL_BlendPoint_RGBA; + } + } + + minx = dst->clip_rect.x; + maxx = dst->clip_rect.x + dst->clip_rect.w - 1; + miny = dst->clip_rect.y; + maxy = dst->clip_rect.y + dst->clip_rect.h - 1; + + for (i = 0; i < count; ++i) { + x = points[i].x; + y = points[i].y; + + if (x < minx || x > maxx || y < miny || y > maxy) { + continue; + } + status = func(dst, x, y, blendMode, r, g, b, a); + } + return status; +} + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_blendrect.c b/src/video/SDL_blendrect.c index 6a5ad9d50..40a78ba23 100644 --- a/src/video/SDL_blendrect.c +++ b/src/video/SDL_blendrect.c @@ -25,7 +25,7 @@ #include "SDL_draw.h" static int -SDL_BlendRect_RGB555(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGB555(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -48,7 +48,7 @@ SDL_BlendRect_RGB555(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, } static int -SDL_BlendRect_RGB565(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGB565(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -71,7 +71,7 @@ SDL_BlendRect_RGB565(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, } static int -SDL_BlendRect_RGB888(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGB888(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -94,7 +94,7 @@ SDL_BlendRect_RGB888(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, } static int -SDL_BlendRect_ARGB8888(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_ARGB8888(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { unsigned inva = 0xff - a; @@ -117,7 +117,7 @@ SDL_BlendRect_ARGB8888(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, } static int -SDL_BlendRect_RGB(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGB(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; @@ -163,7 +163,7 @@ SDL_BlendRect_RGB(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, } static int -SDL_BlendRect_RGBA(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, +SDL_BlendRect_RGBA(SDL_Surface * dst, const SDL_Rect * rect, int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { SDL_PixelFormat *fmt = dst->format; @@ -193,68 +193,155 @@ SDL_BlendRect_RGBA(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, } int -SDL_BlendRect(SDL_Surface * dst, SDL_Rect * dstrect, int blendMode, Uint8 r, - Uint8 g, Uint8 b, Uint8 a) +SDL_BlendRect(SDL_Surface * dst, const SDL_Rect * rect, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) { - SDL_PixelFormat *fmt = dst->format; + SDL_Rect clipped; + + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } /* This function doesn't work on surfaces < 8 bpp */ - if (fmt->BitsPerPixel < 8) { + if (dst->format->BitsPerPixel < 8) { SDL_SetError("SDL_BlendRect(): Unsupported surface format"); - return (-1); + return -1; } - /* If 'dstrect' == NULL, then fill the whole surface */ - if (dstrect) { + /* If 'rect' == NULL, then fill the whole surface */ + if (rect) { /* Perform clipping */ - if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) { - return (0); + if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { + return 0; } + rect = &clipped; } else { - dstrect = &dst->clip_rect; + rect = &dst->clip_rect; } - if ((blendMode == SDL_BLENDMODE_BLEND) - || (blendMode == SDL_BLENDMODE_ADD)) { + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { r = DRAW_MUL(r, a); g = DRAW_MUL(g, a); b = DRAW_MUL(b, a); } - switch (fmt->BitsPerPixel) { + switch (dst->format->BitsPerPixel) { case 15: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0x7C00: - return SDL_BlendRect_RGB555(dst, dstrect, blendMode, r, g, b, a); + return SDL_BlendRect_RGB555(dst, rect, blendMode, r, g, b, a); } break; case 16: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0xF800: - return SDL_BlendRect_RGB565(dst, dstrect, blendMode, r, g, b, a); + return SDL_BlendRect_RGB565(dst, rect, blendMode, r, g, b, a); } break; case 32: - switch (fmt->Rmask) { + switch (dst->format->Rmask) { case 0x00FF0000: - if (!fmt->Amask) { - return SDL_BlendRect_RGB888(dst, dstrect, blendMode, r, g, b, - a); + if (!dst->format->Amask) { + return SDL_BlendRect_RGB888(dst, rect, blendMode, r, g, b, a); } else { - return SDL_BlendRect_ARGB8888(dst, dstrect, blendMode, r, g, - b, a); + return SDL_BlendRect_ARGB8888(dst, rect, blendMode, r, g, b, a); } break; } + break; default: break; } - if (!fmt->Amask) { - return SDL_BlendRect_RGB(dst, dstrect, blendMode, r, g, b, a); + if (!dst->format->Amask) { + return SDL_BlendRect_RGB(dst, rect, blendMode, r, g, b, a); } else { - return SDL_BlendRect_RGBA(dst, dstrect, blendMode, r, g, b, a); + return SDL_BlendRect_RGBA(dst, rect, blendMode, r, g, b, a); + } +} + +int +SDL_BlendRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) +{ + SDL_Rect clipped; + int i; + int (*func)(SDL_Surface * dst, const SDL_Rect * rect, + int blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a) = NULL; + int status = 0; + + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + + /* This function doesn't work on surfaces < 8 bpp */ + if (dst->format->BitsPerPixel < 8) { + SDL_SetError("SDL_BlendRects(): Unsupported surface format"); + return -1; + } + + if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) { + r = DRAW_MUL(r, a); + g = DRAW_MUL(g, a); + b = DRAW_MUL(b, a); + } + + /* FIXME: Does this function pointer slow things down significantly? */ + switch (dst->format->BitsPerPixel) { + case 15: + switch (dst->format->Rmask) { + case 0x7C00: + func = SDL_BlendRect_RGB555; + } + break; + case 16: + switch (dst->format->Rmask) { + case 0xF800: + func = SDL_BlendRect_RGB565; + } + break; + case 32: + switch (dst->format->Rmask) { + case 0x00FF0000: + if (!dst->format->Amask) { + func = SDL_BlendRect_RGB888; + } else { + func = SDL_BlendRect_ARGB8888; + } + break; + } + break; + default: + break; + } + + if (!func) { + if (!dst->format->Amask) { + func = SDL_BlendRect_RGB; + } else { + func = SDL_BlendRect_RGBA; + } + } + + for (i = 0; i < count; ++i) { + const SDL_Rect * rect = rects[i]; + + /* If 'rect' == NULL, then fill the whole surface */ + if (rect) { + /* Perform clipping */ + if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { + continue; + } + rect = &clipped; + } else { + rect = &dst->clip_rect; + } + + status = func(dst, rect, blendMode, r, g, b, a); } + return status; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_draw.h b/src/video/SDL_draw.h index 27165c663..b2e1e4b1f 100644 --- a/src/video/SDL_draw.h +++ b/src/video/SDL_draw.h @@ -346,11 +346,11 @@ do { \ #define FILLRECT(type, op) \ do { \ - int width = dstrect->w; \ - int height = dstrect->h; \ + int width = rect->w; \ + int height = rect->h; \ int pitch = (dst->pitch / dst->format->BytesPerPixel); \ int skip = pitch - width; \ - type *pixel = (type *)dst->pixels + dstrect->y * pitch + dstrect->x; \ + type *pixel = (type *)dst->pixels + rect->y * pitch + rect->x; \ while (height--) { \ { int n = (width+3)/4; \ switch (width & 3) { \ diff --git a/src/video/SDL_drawline.c b/src/video/SDL_drawline.c index 96f206623..f606a8a14 100644 --- a/src/video/SDL_drawline.c +++ b/src/video/SDL_drawline.c @@ -27,13 +27,19 @@ int SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) { + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { SDL_SetError("SDL_DrawLine(): Unsupported surface format"); - return (-1); + return -1; } /* Perform clipping */ + /* FIXME: We don't actually want to clip, as it may change line slope */ if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { return (0); } @@ -55,4 +61,55 @@ SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color) return 0; } +int +SDL_DrawLines(SDL_Surface * dst, const SDL_Point * points, int count, + Uint32 color) +{ + int i; + + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + + /* This function doesn't work on surfaces < 8 bpp */ + if (dst->format->BitsPerPixel < 8) { + SDL_SetError("SDL_DrawLine(): Unsupported surface format"); + return -1; + } + + if (count < 2) { + return 0; + } + + for (i = 1; i < count; ++i) { + int x1 = points[i-1].x; + int y1 = points[i-1].y; + int x2 = points[i].x; + int y2 = points[i].y; + + /* Perform clipping */ + /* FIXME: We don't actually want to clip, as it may change line slope */ + if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) { + continue; + } + + switch (dst->format->BytesPerPixel) { + case 1: + DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1); + break; + case 2: + DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2); + break; + case 3: + SDL_Unsupported(); + return -1; + case 4: + DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4); + break; + } + } + return 0; +} + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_drawpoint.c b/src/video/SDL_drawpoint.c index 033951e3b..74f9ff739 100644 --- a/src/video/SDL_drawpoint.c +++ b/src/video/SDL_drawpoint.c @@ -27,10 +27,15 @@ int SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) { + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); - return (-1); + return -1; } /* Perform clipping */ @@ -57,4 +62,55 @@ SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color) return 0; } +int +SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count, + Uint32 color) +{ + int minx, miny; + int maxx, maxy; + int i; + int x, y; + + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + + /* This function doesn't work on surfaces < 8 bpp */ + if (dst->format->BitsPerPixel < 8) { + SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); + return -1; + } + + minx = dst->clip_rect.x; + maxx = dst->clip_rect.x + dst->clip_rect.w - 1; + miny = dst->clip_rect.y; + maxy = dst->clip_rect.y + dst->clip_rect.h - 1; + + for (i = 0; i < count; ++i) { + x = points[i].x; + y = points[i].y; + + if (x < minx || x > maxx || y < miny || y > maxy) { + continue; + } + + switch (dst->format->BytesPerPixel) { + case 1: + DRAW_FASTSETPIXEL1(x, y); + break; + case 2: + DRAW_FASTSETPIXEL2(x, y); + break; + case 3: + SDL_Unsupported(); + return -1; + case 4: + DRAW_FASTSETPIXEL4(x, y); + break; + } + } + return 0; +} + /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_fillrect.c b/src/video/SDL_fillrect.c index f86e675f1..f389f1a07 100644 --- a/src/video/SDL_fillrect.c +++ b/src/video/SDL_fillrect.c @@ -310,24 +310,31 @@ SDL_FillRect4(Uint8 * pixels, int pitch, Uint32 color, int w, int h) * This function performs a fast fill of the given rectangle with 'color' */ int -SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) +SDL_FillRect(SDL_Surface * dst, const SDL_Rect * rect, Uint32 color) { + SDL_Rect clipped; Uint8 *pixels; + if (!dst) { + SDL_SetError("Passed NULL destination surface"); + return -1; + } + /* This function doesn't work on surfaces < 8 bpp */ if (dst->format->BitsPerPixel < 8) { SDL_SetError("SDL_FillRect(): Unsupported surface format"); - return (-1); + return -1; } - /* If 'dstrect' == NULL, then fill the whole surface */ - if (dstrect) { + /* If 'rect' == NULL, then fill the whole surface */ + if (rect) { /* Perform clipping */ - if (!SDL_IntersectRect(dstrect, &dst->clip_rect, dstrect)) { - return (0); + if (!SDL_IntersectRect(rect, &dst->clip_rect, &clipped)) { + return 0; } + rect = &clipped; } else { - dstrect = &dst->clip_rect; + rect = &dst->clip_rect; } /* Perform software fill */ @@ -336,9 +343,8 @@ SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) return (-1); } - pixels = - (Uint8 *) dst->pixels + dstrect->y * dst->pitch + - dstrect->x * dst->format->BytesPerPixel; + pixels = (Uint8 *) dst->pixels + rect->y * dst->pitch + + rect->x * dst->format->BytesPerPixel; switch (dst->format->BytesPerPixel) { case 1: @@ -347,19 +353,17 @@ SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) color |= (color << 16); #ifdef __SSE__ if (SDL_HasSSE()) { - SDL_FillRect1SSE(pixels, dst->pitch, color, dstrect->w, - dstrect->h); + SDL_FillRect1SSE(pixels, dst->pitch, color, rect->w, rect->h); break; } #endif #ifdef __MMX__ if (SDL_HasMMX()) { - SDL_FillRect1MMX(pixels, dst->pitch, color, dstrect->w, - dstrect->h); + SDL_FillRect1MMX(pixels, dst->pitch, color, rect->w, rect->h); break; } #endif - SDL_FillRect1(pixels, dst->pitch, color, dstrect->w, dstrect->h); + SDL_FillRect1(pixels, dst->pitch, color, rect->w, rect->h); break; } @@ -368,26 +372,24 @@ SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) color |= (color << 16); #ifdef __SSE__ if (SDL_HasSSE()) { - SDL_FillRect2SSE(pixels, dst->pitch, color, dstrect->w, - dstrect->h); + SDL_FillRect2SSE(pixels, dst->pitch, color, rect->w, rect->h); break; } #endif #ifdef __MMX__ if (SDL_HasMMX()) { - SDL_FillRect2MMX(pixels, dst->pitch, color, dstrect->w, - dstrect->h); + SDL_FillRect2MMX(pixels, dst->pitch, color, rect->w, rect->h); break; } #endif - SDL_FillRect2(pixels, dst->pitch, color, dstrect->w, dstrect->h); + SDL_FillRect2(pixels, dst->pitch, color, rect->w, rect->h); break; } case 3: /* 24-bit RGB is a slow path, at least for now. */ { - SDL_FillRect3(pixels, dst->pitch, color, dstrect->w, dstrect->h); + SDL_FillRect3(pixels, dst->pitch, color, rect->w, rect->h); break; } @@ -395,25 +397,36 @@ SDL_FillRect(SDL_Surface * dst, SDL_Rect * dstrect, Uint32 color) { #ifdef __SSE__ if (SDL_HasSSE()) { - SDL_FillRect4SSE(pixels, dst->pitch, color, dstrect->w, - dstrect->h); + SDL_FillRect4SSE(pixels, dst->pitch, color, rect->w, rect->h); break; } #endif #ifdef __MMX__ if (SDL_HasMMX()) { - SDL_FillRect4MMX(pixels, dst->pitch, color, dstrect->w, - dstrect->h); + SDL_FillRect4MMX(pixels, dst->pitch, color, rect->w, rect->h); break; } #endif - SDL_FillRect4(pixels, dst->pitch, color, dstrect->w, dstrect->h); + SDL_FillRect4(pixels, dst->pitch, color, rect->w, rect->h); break; } } /* We're done! */ - return (0); + return 0; +} + +int +SDL_FillRects(SDL_Surface * dst, const SDL_Rect ** rects, int count, + Uint32 color) +{ + int i; + int status = 0; + + for (i = 0; i < count; ++i) { + status = SDL_FillRect(dst, rects[i], color); + } + return status; } /* vi: set ts=4 sw=4 expandtab: */ diff --git a/src/video/SDL_rect.c b/src/video/SDL_rect.c index 4142a8799..80a71b3da 100644 --- a/src/video/SDL_rect.c +++ b/src/video/SDL_rect.c @@ -118,6 +118,84 @@ SDL_UnionRect(const SDL_Rect * A, const SDL_Rect * B, SDL_Rect * result) result->h = Amax - Amin; } +SDL_bool +SDL_EnclosePoints(const SDL_Point * points, int count, const SDL_Rect * clip, + SDL_Rect * result) +{ + int minx, miny; + int maxx, maxy; + int x, y, i; + + if (count < 1) { + return SDL_FALSE; + } + + if (clip) { + SDL_bool added = SDL_FALSE; + int clip_minx = clip->x; + int clip_miny = clip->y; + int clip_maxx = clip->x+clip->w-1; + int clip_maxy = clip->y+clip->h-1; + + for (i = 0; i < count; ++i) { + x = points[i].x; + y = points[i].y; + + if (x < clip_minx || x > clip_maxx || + y < clip_miny || y > clip_maxy) { + continue; + } + if (!added) { + minx = maxx = x; + miny = maxy = y; + added = SDL_TRUE; + continue; + } + if (x < minx) { + minx = x; + } else if (x > maxx) { + maxx = x; + } + if (y < miny) { + miny = y; + } else if (y > maxy) { + maxy = y; + } + } + if (!added) { + return SDL_FALSE; + } + } else { + /* No clipping, always add the first point */ + minx = maxx = points[0].x; + miny = maxy = points[0].y; + + for (i = 1; i < count; ++i) { + x = points[i].x; + y = points[i].y; + + if (x < minx) { + minx = x; + } else if (x > maxx) { + maxx = x; + } + if (y < miny) { + miny = y; + } else if (y > maxy) { + maxy = y; + } + } + } + + if (result) { + result->x = minx; + result->y = miny; + result->w = (maxx-minx)+1; + result->h = (maxy-miny)+1; + } + return SDL_TRUE; +} + SDL_bool SDL_IntersectRectAndLine(const SDL_Rect * rect, int *X1, int *Y1, int *X2, int *Y2) diff --git a/src/video/SDL_renderer_gl.c b/src/video/SDL_renderer_gl.c index 176954755..79d1b12e0 100644 --- a/src/video/SDL_renderer_gl.c +++ b/src/video/SDL_renderer_gl.c @@ -96,10 +96,12 @@ static int GL_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, static void GL_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void GL_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects, const SDL_Rect * rects); -static int GL_RenderPoint(SDL_Renderer * renderer, int x, int y); -static int GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, - int y2); -static int GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); +static int GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int GL_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); static int GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, @@ -304,9 +306,9 @@ GL_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->LockTexture = GL_LockTexture; renderer->UnlockTexture = GL_UnlockTexture; renderer->DirtyTexture = GL_DirtyTexture; - renderer->RenderPoint = GL_RenderPoint; - renderer->RenderLine = GL_RenderLine; - renderer->RenderFill = GL_RenderFill; + renderer->RenderPoints = GL_RenderPoints; + renderer->RenderLines = GL_RenderLines; + renderer->RenderRects = GL_RenderRects; renderer->RenderCopy = GL_RenderCopy; renderer->RenderReadPixels = GL_RenderReadPixels; renderer->RenderWritePixels = GL_RenderWritePixels; @@ -1112,9 +1114,10 @@ GL_SetBlendMode(GL_RenderData * data, int blendMode, int isprimitive) } static int -GL_RenderPoint(SDL_Renderer * renderer, int x, int y) +GL_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) { GL_RenderData *data = (GL_RenderData *) renderer->driverdata; + int i; GL_SetBlendMode(data, renderer->blendMode, 1); @@ -1124,16 +1127,19 @@ GL_RenderPoint(SDL_Renderer * renderer, int x, int y) (GLfloat) renderer->a * inv255f); data->glBegin(GL_POINTS); - data->glVertex2f(0.5f + x, 0.5f + y); + for (i = 0; i < count; ++i) { + data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); + } data->glEnd(); return 0; } static int -GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) +GL_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) { GL_RenderData *data = (GL_RenderData *) renderer->driverdata; + int i; GL_SetBlendMode(data, renderer->blendMode, 1); @@ -1142,43 +1148,61 @@ GL_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) (GLfloat) renderer->b * inv255f, (GLfloat) renderer->a * inv255f); - data->glBegin(GL_LINES); - data->glVertex2f(0.5f + x1, 0.5f + y1); - data->glVertex2f(0.5f + x2, 0.5f + y2); - data->glEnd(); - - /* The line is half open, so we need one more point to complete the line. - * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html - * If we have to, we can use vertical line and horizontal line textures - * for vertical and horizontal lines, and then create custom textures - * for diagonal lines and software render those. It's terrible, but at - * least it would be pixel perfect. - */ - data->glBegin(GL_POINTS); + if (count > 2 && + points[0].x == points[count-1].x && points[0].y == points[count-1].y) { + data->glBegin(GL_LINE_LOOP); + /* GL_LINE_LOOP takes care of the final segment */ + --count; + for (i = 0; i < count; ++i) { + data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); + } + data->glEnd(); + } else { + data->glBegin(GL_LINE_STRIP); + for (i = 0; i < count; ++i) { + data->glVertex2f(0.5f + points[i].x, 0.5f + points[i].y); + } + data->glEnd(); + + /* The line is half open, so we need one more point to complete it. + * http://www.opengl.org/documentation/specs/version1.1/glspec1.1/node47.html + * If we have to, we can use vertical line and horizontal line textures + * for vertical and horizontal lines, and then create custom textures + * for diagonal lines and software render those. It's terrible, but at + * least it would be pixel perfect. + */ + data->glBegin(GL_POINTS); #if defined(__APPLE__) || defined(__WIN32__) - /* Mac OS X and Windows seem to always leave the second point open */ - data->glVertex2f(0.5f + x2, 0.5f + y2); + /* Mac OS X and Windows seem to always leave the second point open */ + data->glVertex2f(0.5f + points[count-1].x, 0.5f + points[count-1].y); #else - /* Linux seems to leave the right-most or bottom-most point open */ - if (x1 > x2) { - data->glVertex2f(0.5f + x1, 0.5f + y1); - } else if (x2 > x1) { - data->glVertex2f(0.5f + x2, 0.5f + y2); - } else if (y1 > y2) { - data->glVertex2f(0.5f + x1, 0.5f + y1); - } else if (y2 > y1) { - data->glVertex2f(0.5f + x2, 0.5f + y2); - } + /* Linux seems to leave the right-most or bottom-most point open */ + int x1 = points[0].x; + int y1 = points[0].y; + int x2 = points[count-1].x; + int y2 = points[count-1].y; + + if (x1 > x2) { + data->glVertex2f(0.5f + x1, 0.5f + y1); + } else if (x2 > x1) { + data->glVertex2f(0.5f + x2, 0.5f + y2); + } else if (y1 > y2) { + data->glVertex2f(0.5f + x1, 0.5f + y1); + } else if (y2 > y1) { + data->glVertex2f(0.5f + x2, 0.5f + y2); + } #endif - data->glEnd(); + data->glEnd(); + } return 0; } static int -GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) +GL_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) { GL_RenderData *data = (GL_RenderData *) renderer->driverdata; + int i; GL_SetBlendMode(data, renderer->blendMode, 1); @@ -1187,7 +1211,11 @@ GL_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) (GLfloat) renderer->b * inv255f, (GLfloat) renderer->a * inv255f); - data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); + for (i = 0; i < count; ++i) { + const SDL_Rect *rect = rects[i]; + + data->glRecti(rect->x, rect->y, rect->x + rect->w, rect->y + rect->h); + } return 0; } diff --git a/src/video/SDL_renderer_gles.c b/src/video/SDL_renderer_gles.c index ec9cf6762..0eb4323c2 100644 --- a/src/video/SDL_renderer_gles.c +++ b/src/video/SDL_renderer_gles.c @@ -85,10 +85,12 @@ static void GLES_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void GLES_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects, const SDL_Rect * rects); -static int GLES_RenderPoint(SDL_Renderer * renderer, int x, int y); -static int GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, - int y2); -static int GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); +static int GLES_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int GLES_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int GLES_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); @@ -242,9 +244,9 @@ GLES_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->LockTexture = GLES_LockTexture; renderer->UnlockTexture = GLES_UnlockTexture; renderer->DirtyTexture = GLES_DirtyTexture; - renderer->RenderPoint = GLES_RenderPoint; - renderer->RenderLine = GLES_RenderLine; - renderer->RenderFill = GLES_RenderFill; + renderer->RenderPoints = GLES_RenderPoints; + renderer->RenderLines = GLES_RenderLines; + renderer->RenderRects = GLES_RenderRects; renderer->RenderCopy = GLES_RenderCopy; renderer->RenderPresent = GLES_RenderPresent; renderer->DestroyTexture = GLES_DestroyTexture; @@ -641,7 +643,7 @@ GLES_SetBlendMode(GLES_RenderData * data, int blendMode, int isprimitive) } static int -GLES_RenderPoint(SDL_Renderer * renderer, int x, int y) +GLES_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) { GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; @@ -652,20 +654,16 @@ GLES_RenderPoint(SDL_Renderer * renderer, int x, int y) (GLfloat) renderer->b * inv255f, (GLfloat) renderer->a * inv255f); - GLshort vertices[2]; - vertices[0] = x; - vertices[1] = y; - - data->glVertexPointer(2, GL_SHORT, 0, vertices); + data->glVertexPointer(2, GL_INT, 0, points); data->glEnableClientState(GL_VERTEX_ARRAY); - data->glDrawArrays(GL_POINTS, 0, 1); + data->glDrawArrays(GL_POINTS, 0, count); data->glDisableClientState(GL_VERTEX_ARRAY); return 0; } static int -GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) +GLES_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) { GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; @@ -676,24 +674,26 @@ GLES_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) (GLfloat) renderer->b * inv255f, (GLfloat) renderer->a * inv255f); - GLshort vertices[4]; - vertices[0] = x1; - vertices[1] = y1; - vertices[2] = x2; - vertices[3] = y2; - - data->glVertexPointer(2, GL_SHORT, 0, vertices); + data->glVertexPointer(2, GL_INT, 0, points); data->glEnableClientState(GL_VERTEX_ARRAY); - data->glDrawArrays(GL_LINES, 0, 2); + if (count > 2 && + points[0].x == points[count-1].x && points[0].y == points[count-1].y) { + /* GL_LINE_LOOP takes care of the final segment */ + --count; + data->glDrawArrays(GL_LINE_LOOP, 0, count); + } else { + data->glDrawArrays(GL_LINE_STRIP, 0, count); + } data->glDisableClientState(GL_VERTEX_ARRAY); return 0; } static int -GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) +GLES_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) { GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; + int i; GLES_SetBlendMode(data, renderer->blendMode, 1); @@ -702,24 +702,26 @@ GLES_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) (GLfloat) renderer->b * inv255f, (GLfloat) renderer->a * inv255f); - GLshort minx = rect->x; - GLshort maxx = rect->x + rect->w; - GLshort miny = rect->y; - GLshort maxy = rect->y + rect->h; - - GLshort vertices[8]; - vertices[0] = minx; - vertices[1] = miny; - vertices[2] = maxx; - vertices[3] = miny; - vertices[4] = minx; - vertices[5] = maxy; - vertices[6] = maxx; - vertices[7] = maxy; - - data->glVertexPointer(2, GL_SHORT, 0, vertices); data->glEnableClientState(GL_VERTEX_ARRAY); - data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + for (i = 0; i < count; ++i) { + const SDL_Rect *rect = rects[i]; + GLshort minx = rect->x; + GLshort maxx = rect->x + rect->w; + GLshort miny = rect->y; + GLshort maxy = rect->y + rect->h; + GLshort vertices[8]; + vertices[0] = minx; + vertices[1] = miny; + vertices[2] = maxx; + vertices[3] = miny; + vertices[4] = minx; + vertices[5] = maxy; + vertices[6] = maxx; + vertices[7] = maxy; + + data->glVertexPointer(2, GL_SHORT, 0, vertices); + data->glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); + } data->glDisableClientState(GL_VERTEX_ARRAY); return 0; diff --git a/src/video/SDL_renderer_sw.c b/src/video/SDL_renderer_sw.c index e85e8f972..5aa018d3e 100644 --- a/src/video/SDL_renderer_sw.c +++ b/src/video/SDL_renderer_sw.c @@ -59,10 +59,12 @@ static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * rect, int markDirty, void **pixels, int *pitch); static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int SW_RenderPoint(SDL_Renderer * renderer, int x, int y); -static int SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, - int y2); -static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); +static int SW_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int SW_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, @@ -228,9 +230,9 @@ SW_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->ActivateRenderer = SW_ActivateRenderer; renderer->DisplayModeChanged = SW_DisplayModeChanged; - renderer->RenderPoint = SW_RenderPoint; - renderer->RenderLine = SW_RenderLine; - renderer->RenderFill = SW_RenderFill; + renderer->RenderPoints = SW_RenderPoints; + renderer->RenderLines = SW_RenderLines; + renderer->RenderRects = SW_RenderRects; renderer->RenderCopy = SW_RenderCopy; renderer->RenderReadPixels = SW_RenderReadPixels; renderer->RenderWritePixels = SW_RenderWritePixels; @@ -537,156 +539,189 @@ SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture) } static int -SW_RenderPoint(SDL_Renderer * renderer, int x, int y) +SW_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; + SDL_Texture *texture = data->texture[data->current_texture]; SDL_Rect rect; - int status; - - rect.x = x; - rect.y = y; - rect.w = 1; - rect.h = 1; + int i; + int x, y; + int status = 0; + + /* Get the smallest rectangle that contains everything */ + rect.x = 0; + rect.y = 0; + rect.w = texture->w; + rect.h = texture->h; + if (!SDL_EnclosePoints(points, count, &rect, &rect)) { + /* Nothing to draw */ + return 0; + } if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { SDL_AddDirtyRect(&data->dirty, &rect); } - if (data->renderer->LockTexture(data->renderer, - data->texture[data->current_texture], - &rect, 1, + if (data->renderer->LockTexture(data->renderer, texture, &rect, 1, &data->surface.pixels, &data->surface.pitch) < 0) { return -1; } - data->surface.w = 1; - data->surface.h = 1; - data->surface.clip_rect.w = 1; - data->surface.clip_rect.h = 1; + data->surface.clip_rect.w = data->surface.w = rect.w; + data->surface.clip_rect.h = data->surface.h = rect.h; + /* Draw the points! */ if (renderer->blendMode == SDL_BLENDMODE_NONE || renderer->blendMode == SDL_BLENDMODE_MASK) { - Uint32 color = - SDL_MapRGBA(data->surface.format, renderer->r, renderer->g, - renderer->b, renderer->a); + Uint32 color = SDL_MapRGBA(data->surface.format, + renderer->r, renderer->g, renderer->b, + renderer->a); - status = SDL_DrawPoint(&data->surface, 0, 0, color); + for (i = 0; i < count; ++i) { + x = points[i].x - rect.x; + y = points[i].y - rect.y; + + status = SDL_DrawPoint(&data->surface, x, y, color); + } } else { - status = - SDL_BlendPoint(&data->surface, 0, 0, renderer->blendMode, - renderer->r, renderer->g, renderer->b, - renderer->a); + for (i = 0; i < count; ++i) { + x = points[i].x - rect.x; + y = points[i].y - rect.y; + + status = SDL_BlendPoint(&data->surface, x, y, + renderer->blendMode, + renderer->r, renderer->g, renderer->b, + renderer->a); + } } - data->renderer->UnlockTexture(data->renderer, - data->texture[data->current_texture]); + data->renderer->UnlockTexture(data->renderer, texture); + return status; } static int -SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) +SW_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - SDL_Rect rect; - int status; - - if (x1 < x2) { - rect.x = x1; - rect.w = (x2 - x1) + 1; - x2 -= x1; - x1 = 0; - } else { - rect.x = x2; - rect.w = (x1 - x2) + 1; - x1 -= x2; - x2 = 0; - } - if (y1 < y2) { - rect.y = y1; - rect.h = (y2 - y1) + 1; - y2 -= y1; - y1 = 0; - } else { - rect.y = y2; - rect.h = (y1 - y2) + 1; - y1 -= y2; - y2 = 0; + SDL_Texture *texture = data->texture[data->current_texture]; + SDL_Rect clip, rect; + int i; + int x1, y1, x2, y2; + int status = 0; + + /* Get the smallest rectangle that contains everything */ + clip.x = 0; + clip.y = 0; + clip.w = texture->w; + clip.h = texture->h; + SDL_EnclosePoints(points, count, NULL, &rect); + if (!SDL_IntersectRect(&rect, &clip, &rect)) { + /* Nothing to draw */ + return 0; } if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { SDL_AddDirtyRect(&data->dirty, &rect); } - if (data->renderer->LockTexture(data->renderer, - data->texture[data->current_texture], - &rect, 1, + if (data->renderer->LockTexture(data->renderer, texture, &rect, 1, &data->surface.pixels, &data->surface.pitch) < 0) { return -1; } - data->surface.w = rect.w; - data->surface.h = rect.h; - data->surface.clip_rect.w = rect.w; - data->surface.clip_rect.h = rect.h; + data->surface.clip_rect.w = data->surface.w = rect.w; + data->surface.clip_rect.h = data->surface.h = rect.h; + /* Draw the points! */ if (renderer->blendMode == SDL_BLENDMODE_NONE || renderer->blendMode == SDL_BLENDMODE_MASK) { - Uint32 color = - SDL_MapRGBA(data->surface.format, renderer->r, renderer->g, - renderer->b, renderer->a); + Uint32 color = SDL_MapRGBA(data->surface.format, + renderer->r, renderer->g, renderer->b, + renderer->a); - status = SDL_DrawLine(&data->surface, x1, y1, x2, y2, color); + for (i = 1; i < count; ++i) { + x1 = points[i-1].x - rect.x; + y1 = points[i-1].y - rect.y; + x2 = points[i].x - rect.x; + y2 = points[i].y - rect.y; + + status = SDL_DrawLine(&data->surface, x1, y1, x2, y2, color); + } } else { - status = - SDL_BlendLine(&data->surface, x1, y1, x2, y2, renderer->blendMode, - renderer->r, renderer->g, renderer->b, renderer->a); + for (i = 1; i < count; ++i) { + x1 = points[i-1].x - rect.x; + y1 = points[i-1].y - rect.y; + x2 = points[i].x - rect.x; + y2 = points[i].y - rect.y; + + status = SDL_BlendLine(&data->surface, x1, y1, x2, y2, + renderer->blendMode, + renderer->r, renderer->g, renderer->b, + renderer->a); + } } - data->renderer->UnlockTexture(data->renderer, - data->texture[data->current_texture]); + data->renderer->UnlockTexture(data->renderer, texture); + return status; } static int -SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) +SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) { SW_RenderData *data = (SW_RenderData *) renderer->driverdata; - SDL_Rect real_rect; - int status; + SDL_Texture *texture = data->texture[data->current_texture]; + SDL_Rect clip, rect; + Uint32 color = 0; + int i; + int status = 0; - if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { - SDL_AddDirtyRect(&data->dirty, rect); - } + clip.x = 0; + clip.y = 0; + clip.w = texture->w; + clip.h = texture->h; - if (data->renderer->LockTexture(data->renderer, - data->texture[data->current_texture], - rect, 1, &data->surface.pixels, - &data->surface.pitch) < 0) { - return -1; + if (renderer->blendMode == SDL_BLENDMODE_NONE || + renderer->blendMode == SDL_BLENDMODE_MASK) { + color = SDL_MapRGBA(data->surface.format, + renderer->r, renderer->g, renderer->b, + renderer->a); } - data->surface.w = rect->w; - data->surface.h = rect->h; - data->surface.clip_rect.w = rect->w; - data->surface.clip_rect.h = rect->h; - real_rect = data->surface.clip_rect; + for (i = 0; i < count; ++i) { + if (!SDL_IntersectRect(rects[i], &clip, &rect)) { + /* Nothing to draw */ + continue; + } - if (renderer->blendMode == SDL_BLENDMODE_NONE) { - Uint32 color = - SDL_MapRGBA(data->surface.format, renderer->r, renderer->g, - renderer->b, renderer->a); + if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { + SDL_AddDirtyRect(&data->dirty, &rect); + } - status = SDL_FillRect(&data->surface, &real_rect, color); - } else { - status = - SDL_BlendRect(&data->surface, &real_rect, renderer->blendMode, - renderer->r, renderer->g, renderer->b, renderer->a); - } + if (data->renderer->LockTexture(data->renderer, texture, &rect, 1, + &data->surface.pixels, + &data->surface.pitch) < 0) { + return -1; + } - data->renderer->UnlockTexture(data->renderer, - data->texture[data->current_texture]); + data->surface.clip_rect.w = data->surface.w = rect.w; + data->surface.clip_rect.h = data->surface.h = rect.h; + + if (renderer->blendMode == SDL_BLENDMODE_NONE || + renderer->blendMode == SDL_BLENDMODE_MASK) { + status = SDL_FillRect(&data->surface, NULL, color); + } else { + status = SDL_BlendRect(&data->surface, NULL, + renderer->blendMode, + renderer->r, renderer->g, renderer->b, + renderer->a); + } + + data->renderer->UnlockTexture(data->renderer, texture); + } return status; } diff --git a/src/video/SDL_sysvideo.h b/src/video/SDL_sysvideo.h index 2cfac4948..b0bfbde4c 100644 --- a/src/video/SDL_sysvideo.h +++ b/src/video/SDL_sysvideo.h @@ -90,10 +90,12 @@ struct SDL_Renderer int numrects, const SDL_Rect * rects); int (*SetDrawColor) (SDL_Renderer * renderer); int (*SetDrawBlendMode) (SDL_Renderer * renderer); - int (*RenderPoint) (SDL_Renderer * renderer, int x, int y); - int (*RenderLine) (SDL_Renderer * renderer, int x1, int y1, int x2, - int y2); - int (*RenderFill) (SDL_Renderer * renderer, const SDL_Rect * rect); + int (*RenderPoints) (SDL_Renderer * renderer, const SDL_Point * points, + int count); + int (*RenderLines) (SDL_Renderer * renderer, const SDL_Point * points, + int count); + int (*RenderRects) (SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); int (*RenderReadPixels) (SDL_Renderer * renderer, const SDL_Rect * rect, diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index 0e4e9140e..51ffbb2bc 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2484,83 +2484,119 @@ SDL_GetRenderDrawBlendMode(int *blendMode) int SDL_RenderPoint(int x, int y) +{ + SDL_Point point; + + point.x = x; + point.y = y; + return SDL_RenderPoints(&point, 1); +} + +int +SDL_RenderPoints(const SDL_Point * points, int count) { SDL_Renderer *renderer; - SDL_Window *window; + + if (!points) { + SDL_SetError("SDL_RenderPoints(): Passed NULL points"); + return -1; + } renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } - if (!renderer->RenderPoint) { + if (!renderer->RenderPoints) { SDL_Unsupported(); return -1; } - window = SDL_GetWindowFromID(renderer->window); - if (x < 0 || y < 0 || x >= window->w || y >= window->h) { + if (count < 1) { return 0; } - return renderer->RenderPoint(renderer, x, y); + return renderer->RenderPoints(renderer, points, count); } int SDL_RenderLine(int x1, int y1, int x2, int y2) +{ + SDL_Point points[2]; + + points[0].x = x1; + points[0].y = y1; + points[1].x = x2; + points[1].y = y2; + return SDL_RenderLines(points, 2); +} + +int +SDL_RenderLines(const SDL_Point * points, int count) { SDL_Renderer *renderer; - SDL_Window *window; - SDL_Rect real_rect; - if (x1 == x2 && y1 == y2) { - return SDL_RenderPoint(x1, y1); + if (!points) { + SDL_SetError("SDL_RenderLines(): Passed NULL points"); + return -1; } renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } - if (!renderer->RenderLine) { + if (!renderer->RenderLines) { SDL_Unsupported(); return -1; } - window = SDL_GetWindowFromID(renderer->window); - - real_rect.x = 0; - real_rect.y = 0; - real_rect.w = window->w; - real_rect.h = window->h; - if (!SDL_IntersectRectAndLine(&real_rect, &x1, &y1, &x2, &y2)) { - return (0); + if (count < 2) { + return 0; } - return renderer->RenderLine(renderer, x1, y1, x2, y2); + return renderer->RenderLines(renderer, points, count); +} + +int +SDL_RenderRect(const SDL_Rect * rect) +{ + return SDL_RenderRects(&rect, 1); } int -SDL_RenderFill(const SDL_Rect * rect) +SDL_RenderRects(const SDL_Rect ** rects, int count) { SDL_Renderer *renderer; - SDL_Window *window; - SDL_Rect real_rect; + int i; + + if (!rects) { + SDL_SetError("SDL_RenderRects(): Passed NULL rects"); + return -1; + } renderer = SDL_GetCurrentRenderer(SDL_TRUE); if (!renderer) { return -1; } - if (!renderer->RenderFill) { + if (!renderer->RenderRects) { SDL_Unsupported(); return -1; } - window = SDL_GetWindowFromID(renderer->window); + if (count < 1) { + return 0; + } + /* Check for NULL rect, which means fill entire window */ + for (i = 0; i < count; ++i) { + if (rects[i] == NULL) { + SDL_Window *window; + SDL_Rect full_rect; + SDL_Rect *rect; - real_rect.x = 0; - real_rect.y = 0; - real_rect.w = window->w; - real_rect.h = window->h; - if (rect) { - if (!SDL_IntersectRect(rect, &real_rect, &real_rect)) { - return 0; + window = SDL_GetWindowFromID(renderer->window); + full_rect.x = 0; + full_rect.y = 0; + full_rect.w = window->w; + full_rect.h = window->h; + rect = &full_rect; + return renderer->RenderRects(renderer, &rect, 1); } } - return renderer->RenderFill(renderer, &real_rect); + return renderer->RenderRects(renderer, rects, count); } int diff --git a/src/video/dummy/SDL_nullrender.c b/src/video/dummy/SDL_nullrender.c index 2234530d4..5887ad267 100644 --- a/src/video/dummy/SDL_nullrender.c +++ b/src/video/dummy/SDL_nullrender.c @@ -31,11 +31,12 @@ static SDL_Renderer *SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags); -static int SDL_DUMMY_RenderPoint(SDL_Renderer * renderer, int x, int y); -static int SDL_DUMMY_RenderLine(SDL_Renderer * renderer, int x1, int y1, - int x2, int y2); -static int SDL_DUMMY_RenderFill(SDL_Renderer * renderer, - const SDL_Rect * rect); +static int SDL_DUMMY_RenderPoints(SDL_Renderer * renderer, + const SDL_Point * points, int count); +static int SDL_DUMMY_RenderLines(SDL_Renderer * renderer, + const SDL_Point * points, int count); +static int SDL_DUMMY_RenderRects(SDL_Renderer * renderer, + const SDL_Rect ** rects, int count); static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, @@ -99,9 +100,9 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags) } SDL_zerop(data); - renderer->RenderPoint = SDL_DUMMY_RenderPoint; - renderer->RenderLine = SDL_DUMMY_RenderLine; - renderer->RenderFill = SDL_DUMMY_RenderFill; + renderer->RenderPoints = SDL_DUMMY_RenderPoints; + renderer->RenderLines = SDL_DUMMY_RenderLines; + renderer->RenderRects = SDL_DUMMY_RenderRects; renderer->RenderCopy = SDL_DUMMY_RenderCopy; renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels; renderer->RenderWritePixels = SDL_DUMMY_RenderWritePixels; @@ -139,72 +140,70 @@ SDL_DUMMY_CreateRenderer(SDL_Window * window, Uint32 flags) } static int -SDL_DUMMY_RenderPoint(SDL_Renderer * renderer, int x, int y) +SDL_DUMMY_RenderPoints(SDL_Renderer * renderer, + const SDL_Point * points, int count) { SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; SDL_Surface *target = data->screens[data->current_screen]; - int status; if (renderer->blendMode == SDL_BLENDMODE_NONE || renderer->blendMode == SDL_BLENDMODE_MASK) { - Uint32 color = - SDL_MapRGBA(target->format, renderer->r, renderer->g, renderer->b, - renderer->a); + Uint32 color = SDL_MapRGBA(target->format, + renderer->r, renderer->g, renderer->b, + renderer->a); - status = SDL_DrawPoint(target, x, y, color); + return SDL_DrawPoints(target, points, count, color); } else { - status = - SDL_BlendPoint(target, x, y, renderer->blendMode, renderer->r, - renderer->g, renderer->b, renderer->a); + return SDL_BlendPoints(target, points, count, renderer->blendMode, + renderer->r, renderer->g, renderer->b, + renderer->a); } - return status; } static int -SDL_DUMMY_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) +SDL_DUMMY_RenderLines(SDL_Renderer * renderer, + const SDL_Point * points, int count) { SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; SDL_Surface *target = data->screens[data->current_screen]; - int status; if (renderer->blendMode == SDL_BLENDMODE_NONE || renderer->blendMode == SDL_BLENDMODE_MASK) { - Uint32 color = - SDL_MapRGBA(target->format, renderer->r, renderer->g, renderer->b, - renderer->a); + Uint32 color = SDL_MapRGBA(target->format, + renderer->r, renderer->g, renderer->b, + renderer->a); - status = SDL_DrawLine(target, x1, y1, x2, y2, color); + return SDL_DrawLines(target, points, count, color); } else { - status = - SDL_BlendLine(target, x1, y1, x2, y2, renderer->blendMode, - renderer->r, renderer->g, renderer->b, renderer->a); + return SDL_BlendLines(target, points, count, renderer->blendMode, + renderer->r, renderer->g, renderer->b, + renderer->a); } - return status; } static int -SDL_DUMMY_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) +SDL_DUMMY_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count) { SDL_DUMMY_RenderData *data = (SDL_DUMMY_RenderData *) renderer->driverdata; SDL_Surface *target = data->screens[data->current_screen]; - SDL_Rect real_rect = *rect; - int status; - if (renderer->blendMode == SDL_BLENDMODE_NONE) { - Uint32 color = - SDL_MapRGBA(target->format, renderer->r, renderer->g, renderer->b, - renderer->a); + if (renderer->blendMode == SDL_BLENDMODE_NONE || + renderer->blendMode == SDL_BLENDMODE_MASK) { + Uint32 color = SDL_MapRGBA(target->format, + renderer->r, renderer->g, renderer->b, + renderer->a); - status = SDL_FillRect(target, &real_rect, color); + return SDL_FillRects(target, rects, count, color); } else { - status = - SDL_BlendRect(target, &real_rect, renderer->blendMode, - renderer->r, renderer->g, renderer->b, renderer->a); + return SDL_BlendRects(target, rects, count, + renderer->blendMode, + renderer->r, renderer->g, renderer->b, + renderer->a); } - return status; } static int diff --git a/src/video/win32/SDL_d3drender.c b/src/video/win32/SDL_d3drender.c index d00fb9d41..3c6a4e756 100644 --- a/src/video/win32/SDL_d3drender.c +++ b/src/video/win32/SDL_d3drender.c @@ -66,10 +66,12 @@ static int D3D_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, static void D3D_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static void D3D_DirtyTexture(SDL_Renderer * renderer, SDL_Texture * texture, int numrects, const SDL_Rect * rects); -static int D3D_RenderPoint(SDL_Renderer * renderer, int x, int y); -static int D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, - int y2); -static int D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); +static int D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int D3D_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); static int D3D_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, @@ -407,9 +409,9 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->LockTexture = D3D_LockTexture; renderer->UnlockTexture = D3D_UnlockTexture; renderer->DirtyTexture = D3D_DirtyTexture; - renderer->RenderPoint = D3D_RenderPoint; - renderer->RenderLine = D3D_RenderLine; - renderer->RenderFill = D3D_RenderFill; + renderer->RenderPoints = D3D_RenderPoints; + renderer->RenderLines = D3D_RenderLines; + renderer->RenderRects = D3D_RenderRects; renderer->RenderCopy = D3D_RenderCopy; renderer->RenderReadPixels = D3D_RenderReadPixels; renderer->RenderWritePixels = D3D_RenderWritePixels; @@ -927,11 +929,12 @@ D3D_SetBlendMode(D3D_RenderData * data, int blendMode) } static int -D3D_RenderPoint(SDL_Renderer * renderer, int x, int y) +D3D_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) { D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; DWORD color; - Vertex vertices[1]; + Vertex *vertices; + int i; HRESULT result; if (data->beginScene) { @@ -939,16 +942,6 @@ D3D_RenderPoint(SDL_Renderer * renderer, int x, int y) data->beginScene = SDL_FALSE; } - color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); - - vertices[0].x = (float) x; - vertices[0].y = (float) y; - vertices[0].z = 0.0f; - vertices[0].rhw = 1.0f; - vertices[0].color = color; - vertices[0].u = 0.0f; - vertices[0].v = 0.0f; - D3D_SetBlendMode(data, renderer->blendMode); result = @@ -958,9 +951,23 @@ D3D_RenderPoint(SDL_Renderer * renderer, int x, int y) D3D_SetError("SetTexture()", result); return -1; } + + color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); + + vertices = SDL_stack_alloc(Vertex, count); + for (i = 0; i < count; ++i) { + vertices[i].x = (float) points[i].x; + vertices[i].y = (float) points[i].y; + vertices[i].z = 0.0f; + vertices[i].rhw = 1.0f; + vertices[i].color = color; + vertices[i].u = 0.0f; + vertices[i].v = 0.0f; + } result = - IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, 1, + IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_POINTLIST, count, vertices, sizeof(*vertices)); + SDL_stack_free(vertices); if (FAILED(result)) { D3D_SetError("DrawPrimitiveUP()", result); return -1; @@ -969,11 +976,12 @@ D3D_RenderPoint(SDL_Renderer * renderer, int x, int y) } static int -D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) +D3D_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) { D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; DWORD color; - Vertex vertices[2]; + Vertex *vertices; + int i; HRESULT result; if (data->beginScene) { @@ -981,24 +989,6 @@ D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) data->beginScene = SDL_FALSE; } - color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); - - vertices[0].x = (float) x1; - vertices[0].y = (float) y1; - vertices[0].z = 0.0f; - vertices[0].rhw = 1.0f; - vertices[0].color = color; - vertices[0].u = 0.0f; - vertices[0].v = 0.0f; - - vertices[1].x = (float) x2; - vertices[1].y = (float) y2; - vertices[1].z = 0.0f; - vertices[1].rhw = 1.0f; - vertices[1].color = color; - vertices[1].u = 0.0f; - vertices[1].v = 0.0f; - D3D_SetBlendMode(data, renderer->blendMode); result = @@ -1008,9 +998,23 @@ D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) D3D_SetError("SetTexture()", result); return -1; } + + color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); + + vertices = SDL_stack_alloc(Vertex, count); + for (i = 0; i < count; ++i) { + vertices[i].x = (float) points[i].x; + vertices[i].y = (float) points[i].y; + vertices[i].z = 0.0f; + vertices[i].rhw = 1.0f; + vertices[i].color = color; + vertices[i].u = 0.0f; + vertices[i].v = 0.0f; + } result = - IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINELIST, 1, + IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, count, vertices, sizeof(*vertices)); + SDL_stack_free(vertices); if (FAILED(result)) { D3D_SetError("DrawPrimitiveUP()", result); return -1; @@ -1019,11 +1023,12 @@ D3D_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) } static int -D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) +D3D_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) { D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; - float minx, miny, maxx, maxy; DWORD color; + int i; + float minx, miny, maxx, maxy; Vertex vertices[4]; HRESULT result; @@ -1032,45 +1037,6 @@ D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) data->beginScene = SDL_FALSE; } - minx = (float) rect->x; - miny = (float) rect->y; - maxx = (float) rect->x + rect->w; - maxy = (float) rect->y + rect->h; - - color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); - - vertices[0].x = minx; - vertices[0].y = miny; - vertices[0].z = 0.0f; - vertices[0].rhw = 1.0f; - vertices[0].color = color; - vertices[0].u = 0.0f; - vertices[0].v = 0.0f; - - vertices[1].x = maxx; - vertices[1].y = miny; - vertices[1].z = 0.0f; - vertices[1].rhw = 1.0f; - vertices[1].color = color; - vertices[1].u = 0.0f; - vertices[1].v = 0.0f; - - vertices[2].x = maxx; - vertices[2].y = maxy; - vertices[2].z = 0.0f; - vertices[2].rhw = 1.0f; - vertices[2].color = color; - vertices[2].u = 0.0f; - vertices[2].v = 0.0f; - - vertices[3].x = minx; - vertices[3].y = maxy; - vertices[3].z = 0.0f; - vertices[3].rhw = 1.0f; - vertices[3].color = color; - vertices[3].u = 0.0f; - vertices[3].v = 0.0f; - D3D_SetBlendMode(data, renderer->blendMode); result = @@ -1080,12 +1046,56 @@ D3D_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) D3D_SetError("SetTexture()", result); return -1; } - result = - IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, 2, - vertices, sizeof(*vertices)); - if (FAILED(result)) { - D3D_SetError("DrawPrimitiveUP()", result); - return -1; + + color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b); + + for (i = 0; i < count; ++i) { + const SDL_Rect *rect = rects[i]; + + minx = (float) rect->x; + miny = (float) rect->y; + maxx = (float) rect->x + rect->w; + maxy = (float) rect->y + rect->h; + + vertices[0].x = minx; + vertices[0].y = miny; + vertices[0].z = 0.0f; + vertices[0].rhw = 1.0f; + vertices[0].color = color; + vertices[0].u = 0.0f; + vertices[0].v = 0.0f; + + vertices[1].x = maxx; + vertices[1].y = miny; + vertices[1].z = 0.0f; + vertices[1].rhw = 1.0f; + vertices[1].color = color; + vertices[1].u = 0.0f; + vertices[1].v = 0.0f; + + vertices[2].x = maxx; + vertices[2].y = maxy; + vertices[2].z = 0.0f; + vertices[2].rhw = 1.0f; + vertices[2].color = color; + vertices[2].u = 0.0f; + vertices[2].v = 0.0f; + + vertices[3].x = minx; + vertices[3].y = maxy; + vertices[3].z = 0.0f; + vertices[3].rhw = 1.0f; + vertices[3].color = color; + vertices[3].u = 0.0f; + vertices[3].v = 0.0f; + + result = + IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_TRIANGLEFAN, + 2, vertices, sizeof(*vertices)); + if (FAILED(result)) { + D3D_SetError("DrawPrimitiveUP()", result); + return -1; + } } return 0; } diff --git a/src/video/win32/SDL_gdirender.c b/src/video/win32/SDL_gdirender.c index 26e2747de..9e618fcb2 100644 --- a/src/video/win32/SDL_gdirender.c +++ b/src/video/win32/SDL_gdirender.c @@ -61,10 +61,12 @@ static int GDI_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, void **pixels, int *pitch); static void GDI_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); static int GDI_SetDrawBlendMode(SDL_Renderer * renderer); -static int GDI_RenderPoint(SDL_Renderer * renderer, int x, int y); -static int GDI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, - int y2); -static int GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); +static int GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, + int count); +static int GDI_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, + int count); static int GDI_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); static int GDI_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, @@ -192,9 +194,9 @@ GDI_CreateRenderer(SDL_Window * window, Uint32 flags) renderer->LockTexture = GDI_LockTexture; renderer->UnlockTexture = GDI_UnlockTexture; renderer->SetDrawBlendMode = GDI_SetDrawBlendMode; - renderer->RenderPoint = GDI_RenderPoint; - renderer->RenderLine = GDI_RenderLine; - renderer->RenderFill = GDI_RenderFill; + renderer->RenderPoints = GDI_RenderPoints; + renderer->RenderLines = GDI_RenderLines; + renderer->RenderRects = GDI_RenderRects; renderer->RenderCopy = GDI_RenderCopy; renderer->RenderReadPixels = GDI_RenderReadPixels; renderer->RenderWritePixels = GDI_RenderWritePixels; @@ -685,96 +687,128 @@ GDI_SetDrawBlendMode(SDL_Renderer * renderer) } static int -GDI_RenderPoint(SDL_Renderer * renderer, int x, int y) +GDI_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) { GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata; + int i; + COLORREF color; if (data->makedirty) { + /* Get the smallest rectangle that contains everything */ + SDL_Window *window = SDL_GetWindowFromID(renderer->window); SDL_Rect rect; - rect.x = x; - rect.y = y; - rect.w = 1; - rect.h = 1; + rect.x = 0; + rect.y = 0; + rect.w = window->w; + rect.h = window->h; + if (!SDL_EnclosePoints(points, count, &rect, &rect)) { + /* Nothing to draw */ + return 0; + } SDL_AddDirtyRect(&data->dirty, &rect); } - SetPixel(data->current_hdc, x, y, - RGB(renderer->r, renderer->g, renderer->b)); + color = RGB(renderer->r, renderer->g, renderer->b); + for (i = 0; i < count; ++i) { + SetPixel(data->current_hdc, points[i].x, points[i].y, color); + } + return 0; } static int -GDI_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) +GDI_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) { GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata; - POINT points[2]; HPEN pen; BOOL status; if (data->makedirty) { - SDL_Rect rect; - - if (x1 < x2) { - rect.x = x1; - rect.w = (x2 - x1) + 1; - } else { - rect.x = x2; - rect.w = (x1 - x2) + 1; - } - if (y1 < y2) { - rect.y = y1; - rect.h = (y2 - y1) + 1; - } else { - rect.y = y2; - rect.h = (y1 - y2) + 1; + /* Get the smallest rectangle that contains everything */ + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_Rect clip, rect; + + clip.x = 0; + clip.y = 0; + clip.w = window->w; + clip.h = window->h; + SDL_EnclosePoints(points, count, NULL, &rect); + if (!SDL_IntersectRect(&rect, &clip, &rect)) { + /* Nothing to draw */ + return 0; } + SDL_AddDirtyRect(&data->dirty, &rect); } /* Should we cache the pen? .. it looks like GDI does for us. :) */ pen = CreatePen(PS_SOLID, 1, RGB(renderer->r, renderer->g, renderer->b)); SelectObject(data->current_hdc, pen); - points[0].x = x1; - points[0].y = y1; - points[1].x = x2; - points[1].y = y2; - status = Polyline(data->current_hdc, points, 2); + { + LPPOINT p = SDL_stack_alloc(POINT, count); + int i; + + for (i = 0; i < count; ++i) { + p[i].x = points[i].x; + p[i].y = points[i].y; + } + status = Polyline(data->current_hdc, p, count); + SDL_stack_free(p); + } DeleteObject(pen); /* Need to close the endpoint of the line */ - SetPixel(data->current_hdc, x2, y2, - RGB(renderer->r, renderer->g, renderer->b)); + if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) { + SetPixel(data->current_hdc, points[count-1].x, points[count-1].y, + RGB(renderer->r, renderer->g, renderer->b)); + } if (!status) { - WIN_SetError("FillRect()"); + WIN_SetError("Polyline()"); return -1; } return 0; } static int -GDI_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) +GDI_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) { GDI_RenderData *data = (GDI_RenderData *) renderer->driverdata; RECT rc; HBRUSH brush; - int status; + int i, status = 1; if (data->makedirty) { - SDL_AddDirtyRect(&data->dirty, rect); - } + SDL_Window *window = SDL_GetWindowFromID(renderer->window); + SDL_Rect clip, rect; + + clip.x = 0; + clip.y = 0; + clip.w = window->w; + clip.h = window->h; - rc.left = rect->x; - rc.top = rect->y; - rc.right = rect->x + rect->w; - rc.bottom = rect->y + rect->h; + for (i = 0; i < count; ++i) { + if (SDL_IntersectRect(rects[i], &clip, &rect)) { + SDL_AddDirtyRect(&data->dirty, &rect); + } + } + } /* Should we cache the brushes? .. it looks like GDI does for us. :) */ brush = CreateSolidBrush(RGB(renderer->r, renderer->g, renderer->b)); SelectObject(data->current_hdc, brush); - status = FillRect(data->current_hdc, &rc, brush); + for (i = 0; i < count; ++i) { + const SDL_Rect *rect = rects[i]; + + rc.left = rect->x; + rc.top = rect->y; + rc.right = rect->x + rect->w; + rc.bottom = rect->y + rect->h; + + status &= FillRect(data->current_hdc, &rc, brush); + } DeleteObject(brush); if (!status) { diff --git a/test/automated/render/render.c b/test/automated/render/render.c index 906e8cb53..91fe5138e 100644 --- a/test/automated/render/render.c +++ b/test/automated/render/render.c @@ -340,9 +340,9 @@ static int render_clearScreen (void) */ /* Clear screen. */ - ret = SDL_RenderFill( NULL ); + ret = SDL_RenderRect( NULL ); /* - if (SDL_ATassert( "SDL_RenderFill", ret == 0)) + if (SDL_ATassert( "SDL_RenderRect", ret == 0)) return -1; */ @@ -387,7 +387,7 @@ static int render_testPrimitives (void) ret = SDL_SetRenderDrawColor( 13, 73, 200, SDL_ALPHA_OPAQUE ); if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) return -1; - ret = SDL_RenderFill( &rect ); + ret = SDL_RenderRect( &rect ); if (SDL_ATassert( "SDL_RenderRect", ret == 0)) return -1; @@ -399,7 +399,7 @@ static int render_testPrimitives (void) ret = SDL_SetRenderDrawColor( 200, 0, 100, SDL_ALPHA_OPAQUE ); if (SDL_ATassert( "SDL_SetRenderDrawColor", ret == 0)) return -1; - ret = SDL_RenderFill( &rect ); + ret = SDL_RenderRect( &rect ); if (SDL_ATassert( "SDL_RenderRect", ret == 0)) return -1; @@ -480,8 +480,8 @@ static int render_testPrimitivesBlend (void) ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_NONE ); if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) return -1; - ret = SDL_RenderFill( NULL ); - if (SDL_ATassert( "SDL_RenderFill", ret == 0)) + ret = SDL_RenderRect( NULL ); + if (SDL_ATassert( "SDL_RenderRect", ret == 0)) return -1; rect.x = 10; rect.y = 25; @@ -493,8 +493,8 @@ static int render_testPrimitivesBlend (void) ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_ADD ); if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) return -1; - ret = SDL_RenderFill( &rect ); - if (SDL_ATassert( "SDL_RenderFill", ret == 0)) + ret = SDL_RenderRect( &rect ); + if (SDL_ATassert( "SDL_RenderRect", ret == 0)) return -1; rect.x = 30; rect.y = 40; @@ -506,8 +506,8 @@ static int render_testPrimitivesBlend (void) ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_BLEND ); if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) return -1; - ret = SDL_RenderFill( &rect ); - if (SDL_ATassert( "SDL_RenderFill", ret == 0)) + ret = SDL_RenderRect( &rect ); + if (SDL_ATassert( "SDL_RenderRect", ret == 0)) return -1; rect.x = 25; rect.y = 25; @@ -519,8 +519,8 @@ static int render_testPrimitivesBlend (void) ret = SDL_SetRenderDrawBlendMode( SDL_BLENDMODE_MOD ); if (SDL_ATassert( "SDL_SetRenderDrawBlendMode", ret == 0)) return -1; - ret = SDL_RenderFill( &rect ); - if (SDL_ATassert( "SDL_RenderFill", ret == 0)) + ret = SDL_RenderRect( &rect ); + if (SDL_ATassert( "SDL_RenderRect", ret == 0)) return -1; /* Draw blended lines, lines for everyone. */ diff --git a/test/testdraw2.c b/test/testdraw2.c index 80584ae28..325779646 100644 --- a/test/testdraw2.c +++ b/test/testdraw2.c @@ -159,7 +159,7 @@ DrawRects(SDL_WindowID window) rect.h = rand() % (window_h / 2); rect.x = (rand() % window_w) - (rect.w / 2); rect.y = (rand() % window_w) - (rect.h / 2); - SDL_RenderFill(&rect); + SDL_RenderRect(&rect); } SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); } @@ -231,7 +231,7 @@ main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { SDL_SelectRenderer(state->windows[i]); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); } srand(time(NULL)); @@ -251,7 +251,7 @@ main(int argc, char *argv[]) case SDL_WINDOWEVENT_EXPOSED: SDL_SelectRenderer(event.window.windowID); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); break; } break; @@ -262,7 +262,7 @@ main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { SDL_SelectRenderer(state->windows[i]); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); DrawRects(state->windows[i]); DrawLines(state->windows[i]); diff --git a/test/testintersections.c b/test/testintersections.c index b935788f2..b308c1d60 100644 --- a/test/testintersections.c +++ b/test/testintersections.c @@ -150,7 +150,7 @@ DrawRects(SDL_WindowID window) SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); for (i = 0; i < num_rects; ++i) { SDL_SetRenderDrawColor(255, 127, 0, 255); - SDL_RenderFill(&rects[i]); + SDL_RenderRect(&rects[i]); } SDL_SetRenderDrawBlendMode(SDL_BLENDMODE_NONE); } @@ -197,7 +197,7 @@ DrawRectRectIntersections(SDL_WindowID window) SDL_Rect r; if (SDL_IntersectRect(&rects[i], &rects[j], &r)) { SDL_SetRenderDrawColor(255, 200, 0, 255); - SDL_RenderFill(&r); + SDL_RenderRect(&r); } } @@ -272,7 +272,7 @@ main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { SDL_SelectRenderer(state->windows[i]); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); } srand(time(NULL)); @@ -326,7 +326,7 @@ main(int argc, char *argv[]) case SDL_WINDOWEVENT_EXPOSED: SDL_SelectRenderer(event.window.windowID); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); break; } break; @@ -337,7 +337,7 @@ main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { SDL_SelectRenderer(state->windows[i]); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); DrawRects(state->windows[i]); DrawPoints(state->windows[i]); diff --git a/test/testnative.c b/test/testnative.c index 7f531547e..014927df3 100644 --- a/test/testnative.c +++ b/test/testnative.c @@ -83,7 +83,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) /* Move the sprite, bounce at the wall, and draw */ n = 0; SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); for (i = 0; i < NUM_SPRITES; ++i) { position = &positions[i]; velocity = &velocities[i]; @@ -158,7 +158,7 @@ main(int argc, char *argv[]) /* Clear the window, load the sprite and go! */ SDL_SelectRenderer(window); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); sprite = LoadSprite(window, "icon.bmp"); if (!sprite) { @@ -199,7 +199,7 @@ main(int argc, char *argv[]) case SDL_WINDOWEVENT_EXPOSED: SDL_SelectRenderer(event.window.windowID); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); break; } break; diff --git a/test/testsprite2.c b/test/testsprite2.c index 94f338284..a8ab84ac7 100644 --- a/test/testsprite2.c +++ b/test/testsprite2.c @@ -141,7 +141,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) /* Draw a gray background */ SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); /* Test points */ SDL_SetRenderDrawColor(0xFF, 0x00, 0x00, 0xFF); @@ -163,25 +163,25 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) temp.y = 1; temp.w = sprite_w; temp.h = sprite_h; - SDL_RenderFill(&temp); + SDL_RenderRect(&temp); SDL_RenderCopy(sprite, NULL, &temp); temp.x = window_w-sprite_w-1; temp.y = 1; temp.w = sprite_w; temp.h = sprite_h; - SDL_RenderFill(&temp); + SDL_RenderRect(&temp); SDL_RenderCopy(sprite, NULL, &temp); temp.x = 1; temp.y = window_h-sprite_h-1; temp.w = sprite_w; temp.h = sprite_h; - SDL_RenderFill(&temp); + SDL_RenderRect(&temp); SDL_RenderCopy(sprite, NULL, &temp); temp.x = window_w-sprite_w-1; temp.y = window_h-sprite_h-1; temp.w = sprite_w; temp.h = sprite_h; - SDL_RenderFill(&temp); + SDL_RenderRect(&temp); SDL_RenderCopy(sprite, NULL, &temp); /* Test diagonal lines */ @@ -304,7 +304,7 @@ main(int argc, char *argv[]) for (i = 0; i < state->num_windows; ++i) { SDL_SelectRenderer(state->windows[i]); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); } if (LoadSprite("icon.bmp") < 0) { quit(2); @@ -350,7 +350,7 @@ main(int argc, char *argv[]) case SDL_WINDOWEVENT_EXPOSED: SDL_SelectRenderer(event.window.windowID); SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); break; } break; diff --git a/test/testspriteminimal.c b/test/testspriteminimal.c index b1f6055fd..3460496e6 100644 --- a/test/testspriteminimal.c +++ b/test/testspriteminimal.c @@ -87,7 +87,7 @@ MoveSprites(SDL_WindowID window, SDL_TextureID sprite) /* Draw a gray background */ SDL_SetRenderDrawColor(0xA0, 0xA0, 0xA0, 0xFF); - SDL_RenderFill(NULL); + SDL_RenderRect(NULL); /* Move the sprite, bounce at the wall, and draw */ for (i = 0; i < NUM_SPRITES; ++i) {