changeset 5151:5429daf5e3f9

The DrawRect API is implemented using lines
author Sam Lantinga <slouken@libsdl.org>
date Tue, 01 Feb 2011 20:50:04 -0800
parents ad50b3db78bd
children be02be2ea897
files src/video/SDL_renderer_gl.c src/video/SDL_renderer_gles.c src/video/SDL_renderer_sw.c src/video/SDL_sysvideo.h src/video/SDL_video.c src/video/directfb/SDL_DirectFB_render.c src/video/dummy/SDL_nullrender.c src/video/windows/SDL_d3drender.c
diffstat 8 files changed, 30 insertions(+), 273 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_renderer_gl.c	Tue Feb 01 19:19:43 2011 -0800
+++ b/src/video/SDL_renderer_gl.c	Tue Feb 01 20:50:04 2011 -0800
@@ -93,8 +93,6 @@
                                const SDL_Point * points, int count);
 static int GL_RenderDrawLines(SDL_Renderer * renderer,
                               const SDL_Point * points, int count);
-static int GL_RenderDrawRects(SDL_Renderer * renderer,
-                              const SDL_Rect ** rects, int count);
 static int GL_RenderFillRects(SDL_Renderer * renderer,
                               const SDL_Rect ** rects, int count);
 static int GL_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
@@ -289,7 +287,6 @@
     renderer->RenderClear = GL_RenderClear;
     renderer->RenderDrawPoints = GL_RenderDrawPoints;
     renderer->RenderDrawLines = GL_RenderDrawLines;
-    renderer->RenderDrawRects = GL_RenderDrawRects;
     renderer->RenderFillRects = GL_RenderFillRects;
     renderer->RenderCopy = GL_RenderCopy;
     renderer->RenderReadPixels = GL_RenderReadPixels;
@@ -1139,46 +1136,6 @@
 }
 
 static int
-GL_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
-{
-    GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
-    int i, x, y;
-
-    GL_ActivateRenderer(renderer);
-
-    GL_SetBlendMode(data, renderer->blendMode);
-
-    data->glColor4f((GLfloat) renderer->r * inv255f,
-                    (GLfloat) renderer->g * inv255f,
-                    (GLfloat) renderer->b * inv255f,
-                    (GLfloat) renderer->a * inv255f);
-
-    data->glBegin(GL_LINE_LOOP);
-    for (i = 0; i < count; ++i) {
-        const SDL_Rect *rect = rects[i];
-
-        x = rect->x;
-        y = rect->y;
-        data->glVertex2f(0.5f + x, 0.5f + y);
-
-        x = rect->x+rect->w-1;
-        y = rect->y;
-        data->glVertex2f(0.5f + x, 0.5f + y);
-
-        x = rect->x+rect->w-1;
-        y = rect->y+rect->h-1;
-        data->glVertex2f(0.5f + x, 0.5f + y);
-
-        x = rect->x;
-        y = rect->y+rect->h-1;
-        data->glVertex2f(0.5f + x, 0.5f + y);
-    }
-    data->glEnd();
-
-    return 0;
-}
-
-static int
 GL_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
 {
     GL_RenderData *data = (GL_RenderData *) renderer->driverdata;
--- a/src/video/SDL_renderer_gles.c	Tue Feb 01 19:19:43 2011 -0800
+++ b/src/video/SDL_renderer_gles.c	Tue Feb 01 20:50:04 2011 -0800
@@ -81,8 +81,6 @@
                                  const SDL_Point * points, int count);
 static int GLES_RenderDrawLines(SDL_Renderer * renderer,
                                 const SDL_Point * points, int count);
-static int GLES_RenderDrawRects(SDL_Renderer * renderer,
-                                const SDL_Rect ** rects, int count);
 static int GLES_RenderFillRects(SDL_Renderer * renderer,
                                 const SDL_Rect ** rects, int count);
 static int GLES_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
@@ -229,7 +227,6 @@
     renderer->DirtyTexture = GLES_DirtyTexture;
     renderer->RenderDrawPoints = GLES_RenderDrawPoints;
     renderer->RenderDrawLines = GLES_RenderDrawLines;
-    renderer->RenderDrawRects = GLES_RenderDrawRects;
     renderer->RenderFillRects = GLES_RenderFillRects;
     renderer->RenderCopy = GLES_RenderCopy;
     renderer->RenderPresent = GLES_RenderPresent;
@@ -668,45 +665,6 @@
 }
 
 static int
-GLES_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
-                     int count)
-{
-    GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata;
-    int i;
-
-    GLES_ActivateRenderer(renderer);
-
-    GLES_SetBlendMode(data, renderer->blendMode);
-
-    data->glColor4f((GLfloat) renderer->r * inv255f,
-                    (GLfloat) renderer->g * inv255f,
-                    (GLfloat) renderer->b * inv255f,
-                    (GLfloat) renderer->a * inv255f);
-
-    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_LINE_LOOP, 0, 4);
-    }
-
-    return 0;
-}
-
-static int
 GLES_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
                      int count)
 {
--- a/src/video/SDL_renderer_sw.c	Tue Feb 01 19:19:43 2011 -0800
+++ b/src/video/SDL_renderer_sw.c	Tue Feb 01 20:50:04 2011 -0800
@@ -62,8 +62,6 @@
                                const SDL_Point * points, int count);
 static int SW_RenderDrawLines(SDL_Renderer * renderer,
                               const SDL_Point * points, int count);
-static int SW_RenderDrawRects(SDL_Renderer * renderer,
-                              const SDL_Rect ** rects, int count);
 static int SW_RenderFillRects(SDL_Renderer * renderer,
                               const SDL_Rect ** rects, int count);
 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
@@ -216,7 +214,6 @@
 
     renderer->RenderDrawPoints = SW_RenderDrawPoints;
     renderer->RenderDrawLines = SW_RenderDrawLines;
-    renderer->RenderDrawRects = SW_RenderDrawRects;
     renderer->RenderFillRects = SW_RenderFillRects;
     renderer->RenderCopy = SW_RenderCopy;
     renderer->RenderReadPixels = SW_RenderReadPixels;
@@ -609,62 +606,6 @@
 }
 
 static int
-SW_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
-                   int count)
-{
-    SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
-    SDL_Texture *texture = SW_ActivateRenderer(renderer);
-    SDL_Rect clip, rect;
-    Uint32 color = 0;
-    int i;
-    int status = 0;
-
-    if (!texture) {
-        return -1;
-    }
-
-    clip.x = 0;
-    clip.y = 0;
-    clip.w = texture->w;
-    clip.h = texture->h;
-
-    if (renderer->blendMode == SDL_BLENDMODE_NONE) {
-        color = SDL_MapRGBA(data->surface.format,
-                            renderer->r, renderer->g, renderer->b,
-                            renderer->a);
-    }
-
-    for (i = 0; i < count; ++i) {
-        /* FIXME: We don't want to draw clipped edges */
-        if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
-            /* Nothing to draw */
-            continue;
-        }
-
-        if (data->renderer->LockTexture(data->renderer, texture, &rect, 1,
-                                        &data->surface.pixels,
-                                        &data->surface.pitch) < 0) {
-            return -1;
-        }
-
-        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) {
-            status = SDL_DrawRect(&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;
-}
-
-static int
 SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
                    int count)
 {
--- a/src/video/SDL_sysvideo.h	Tue Feb 01 19:19:43 2011 -0800
+++ b/src/video/SDL_sysvideo.h	Tue Feb 01 20:50:04 2011 -0800
@@ -93,8 +93,6 @@
                              int count);
     int (*RenderDrawLines) (SDL_Renderer * renderer, const SDL_Point * points,
                             int count);
-    int (*RenderDrawRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
-                            int count);
     int (*RenderFillRects) (SDL_Renderer * renderer, const SDL_Rect ** rects,
                             int count);
     int (*RenderCopy) (SDL_Renderer * renderer, SDL_Texture * texture,
--- a/src/video/SDL_video.c	Tue Feb 01 19:19:43 2011 -0800
+++ b/src/video/SDL_video.c	Tue Feb 01 20:50:04 2011 -0800
@@ -2319,7 +2319,33 @@
 int
 SDL_RenderDrawRect(SDL_Renderer * renderer, const SDL_Rect * rect)
 {
-    return SDL_RenderDrawRects(renderer, &rect, 1);
+    SDL_Rect full_rect;
+    SDL_Point points[5];
+
+    CHECK_RENDERER_MAGIC(renderer, -1);
+
+    /* If 'rect' == NULL, then outline the whole surface */
+    if (!rect) {
+        SDL_Window *window = renderer->window;
+
+        full_rect.x = 0;
+        full_rect.y = 0;
+        full_rect.w = window->w;
+        full_rect.h = window->h;
+        rect = &full_rect;
+    }
+
+    points[0].x = rect->x;
+    points[0].y = rect->y;
+    points[1].x = rect->x+rect->w-1;
+    points[1].y = rect->y;
+    points[2].x = rect->x+rect->w-1;
+    points[2].y = rect->y+rect->h-1;
+    points[3].x = rect->x;
+    points[3].y = rect->y+rect->h-1;
+    points[4].x = rect->x;
+    points[4].y = rect->y;
+    return SDL_RenderDrawLines(renderer, points, 5);
 }
 
 int
@@ -2340,20 +2366,11 @@
 
     /* Check for NULL rect, which means fill entire window */
     for (i = 0; i < count; ++i) {
-        if (rects[i] == NULL) {
-            SDL_Window *window = renderer->window;
-            SDL_Rect full_rect;
-            const SDL_Rect *rect;
-
-            full_rect.x = 0;
-            full_rect.y = 0;
-            full_rect.w = window->w;
-            full_rect.h = window->h;
-            rect = &full_rect;
-            return renderer->RenderDrawRects(renderer, &rect, 1);
+        if (SDL_RenderDrawRect(renderer, rects[i]) < 0) {
+            return -1;
         }
     }
-    return renderer->RenderDrawRects(renderer, rects, count);
+    return 0;
 }
 
 int
--- a/src/video/directfb/SDL_DirectFB_render.c	Tue Feb 01 19:19:43 2011 -0800
+++ b/src/video/directfb/SDL_DirectFB_render.c	Tue Feb 01 20:50:04 2011 -0800
@@ -68,8 +68,6 @@
                                 const SDL_Point * points, int count);
 static int DirectFB_RenderDrawLines(SDL_Renderer * renderer,
                                const SDL_Point * points, int count);
-static int DirectFB_RenderDrawRects(SDL_Renderer * renderer,
-		const SDL_Rect ** rects, int count);
 static int DirectFB_RenderFillRects(SDL_Renderer * renderer,
 		const SDL_Rect ** rects, int count);
 static int DirectFB_RenderCopy(SDL_Renderer * renderer,
@@ -271,7 +269,6 @@
     renderer->RenderDrawPoints = DirectFB_RenderDrawPoints;
     renderer->RenderDrawLines = DirectFB_RenderDrawLines;
     renderer->RenderFillRects = DirectFB_RenderFillRects;
-    renderer->RenderDrawRects = DirectFB_RenderDrawRects;
     /* RenderDrawEllipse - no reference implementation yet */
     /* RenderFillEllipse - no reference implementation yet */
     renderer->RenderCopy = DirectFB_RenderCopy;
@@ -817,24 +814,6 @@
 }
 
 static int
-DirectFB_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
-{
-    DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
-    SDL_DFB_WINDOWSURFACE(data->window);
-    int i;
-
-    PrepareDraw(renderer);
-
-    for (i=0; i<count; i++)
-    	SDL_DFB_CHECKERR(destsurf->DrawRectangle(destsurf, rects[i]->x, rects[i]->y,
-    			rects[i]->w, rects[i]->h));
-
-    return 0;
-  error:
-    return -1;
-}
-
-static int
 DirectFB_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count)
 {
     DirectFB_RenderData *data = (DirectFB_RenderData *) renderer->driverdata;
--- a/src/video/dummy/SDL_nullrender.c	Tue Feb 01 19:19:43 2011 -0800
+++ b/src/video/dummy/SDL_nullrender.c	Tue Feb 01 20:50:04 2011 -0800
@@ -35,8 +35,6 @@
                                       const SDL_Point * points, int count);
 static int SDL_DUMMY_RenderDrawLines(SDL_Renderer * renderer,
                                      const SDL_Point * points, int count);
-static int SDL_DUMMY_RenderDrawRects(SDL_Renderer * renderer,
-                                     const SDL_Rect ** rects, int count);
 static int SDL_DUMMY_RenderFillRects(SDL_Renderer * renderer,
                                      const SDL_Rect ** rects, int count);
 static int SDL_DUMMY_RenderCopy(SDL_Renderer * renderer,
@@ -100,7 +98,6 @@
 
     renderer->RenderDrawPoints = SDL_DUMMY_RenderDrawPoints;
     renderer->RenderDrawLines = SDL_DUMMY_RenderDrawLines;
-    renderer->RenderDrawRects = SDL_DUMMY_RenderDrawRects;
     renderer->RenderFillRects = SDL_DUMMY_RenderFillRects;
     renderer->RenderCopy = SDL_DUMMY_RenderCopy;
     renderer->RenderReadPixels = SDL_DUMMY_RenderReadPixels;
@@ -168,28 +165,6 @@
 }
 
 static int
-SDL_DUMMY_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
-                          int count)
-{
-    SDL_DUMMY_RenderData *data =
-        (SDL_DUMMY_RenderData *) renderer->driverdata;
-    SDL_Surface *target = data->screen;
-
-    if (renderer->blendMode == SDL_BLENDMODE_NONE) {
-        Uint32 color = SDL_MapRGBA(target->format,
-                                   renderer->r, renderer->g, renderer->b,
-                                   renderer->a);
-
-        return SDL_DrawRects(target, rects, count, color);
-    } else {
-        return SDL_BlendRects(target, rects, count,
-                              renderer->blendMode,
-                              renderer->r, renderer->g, renderer->b,
-                              renderer->a);
-    }
-}
-
-static int
 SDL_DUMMY_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
                           int count)
 {
--- a/src/video/windows/SDL_d3drender.c	Tue Feb 01 19:19:43 2011 -0800
+++ b/src/video/windows/SDL_d3drender.c	Tue Feb 01 20:50:04 2011 -0800
@@ -114,8 +114,6 @@
                                 const SDL_Point * points, int count);
 static int D3D_RenderDrawLines(SDL_Renderer * renderer,
                                const SDL_Point * points, int count);
-static int D3D_RenderDrawRects(SDL_Renderer * renderer,
-                               const SDL_Rect ** rects, int count);
 static int D3D_RenderFillRects(SDL_Renderer * renderer,
                                const SDL_Rect ** rects, int count);
 static int D3D_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
@@ -446,7 +444,6 @@
     renderer->DirtyTexture = D3D_DirtyTexture;
     renderer->RenderDrawPoints = D3D_RenderDrawPoints;
     renderer->RenderDrawLines = D3D_RenderDrawLines;
-    renderer->RenderDrawRects = D3D_RenderDrawRects;
     renderer->RenderFillRects = D3D_RenderFillRects;
     renderer->RenderCopy = D3D_RenderCopy;
     renderer->RenderReadPixels = D3D_RenderReadPixels;
@@ -987,71 +984,6 @@
 }
 
 static int
-D3D_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
-                    int count)
-{
-    D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata;
-    DWORD color;
-    int i;
-    Vertex vertices[5];
-    HRESULT result;
-
-    if (data->beginScene) {
-        IDirect3DDevice9_BeginScene(data->device);
-        data->beginScene = SDL_FALSE;
-    }
-
-    D3D_SetBlendMode(data, renderer->blendMode);
-
-    result =
-        IDirect3DDevice9_SetTexture(data->device, 0,
-                                    (IDirect3DBaseTexture9 *) 0);
-    if (FAILED(result)) {
-        D3D_SetError("SetTexture()", result);
-        return -1;
-    }
-
-    color = D3DCOLOR_ARGB(renderer->a, renderer->r, renderer->g, renderer->b);
-
-    for (i = 0; i < SDL_arraysize(vertices); ++i) {
-        vertices[i].z = 0.0f;
-        vertices[i].rhw = 1.0f;
-        vertices[i].color = color;
-        vertices[i].u = 0.0f;
-        vertices[i].v = 0.0f;
-    }
-
-    for (i = 0; i < count; ++i) {
-        const SDL_Rect *rect = rects[i];
-
-        vertices[0].x = (float) rect->x;
-        vertices[0].y = (float) rect->y;
-
-        vertices[1].x = (float) rect->x+rect->w-1;
-        vertices[1].y = (float) rect->y;
-
-        vertices[2].x = (float) rect->x+rect->w-1;
-        vertices[2].y = (float) rect->y+rect->h-1;
-
-        vertices[3].x = (float) rect->x;
-        vertices[3].y = (float) rect->y+rect->h-1;
-
-        vertices[4].x = (float) rect->x;
-        vertices[4].y = (float) rect->y;
-
-        result =
-            IDirect3DDevice9_DrawPrimitiveUP(data->device, D3DPT_LINESTRIP, 4,
-                                             vertices, sizeof(*vertices));
-
-        if (FAILED(result)) {
-            D3D_SetError("DrawPrimitiveUP()", result);
-            return -1;
-        }
-    }
-    return 0;
-}
-
-static int
 D3D_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
                     int count)
 {