changeset 2904:fa81cc1ef3d0

Fixed clip_rect when drawing points and lines with software renderer. Lock the minimal rect to minimize texture uploads
author Sam Lantinga <slouken@libsdl.org>
date Sun, 21 Dec 2008 20:17:41 +0000
parents e426c4fc9cf7
children d214e791c77c
files src/video/SDL_renderer_sw.c
diffstat 1 files changed, 44 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/video/SDL_renderer_sw.c	Sun Dec 21 20:16:21 2008 +0000
+++ b/src/video/SDL_renderer_sw.c	Sun Dec 21 20:17:41 2008 +0000
@@ -543,36 +543,41 @@
 SW_RenderPoint(SDL_Renderer * renderer, int x, int y)
 {
     SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
+    SDL_Rect rect;
     int status;
 
+    rect.x = x;
+    rect.y = y;
+    rect.w = 1;
+    rect.h = 1;
+
     if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
-        SDL_Rect rect;
-
-        rect.x = x;
-        rect.y = y;
-        rect.w = 1;
-        rect.h = 1;
         SDL_AddDirtyRect(&data->dirty, &rect);
     }
 
     if (data->renderer->LockTexture(data->renderer,
                                     data->texture[data->current_texture],
-                                    &data->surface.clip_rect, 1,
+                                    &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;
+
     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);
 
-        status = SDL_DrawPoint(&data->surface, x, y, color);
+        status = SDL_DrawPoint(&data->surface, 0, 0, color);
     } else {
         status =
-            SDL_BlendPoint(&data->surface, x, y, renderer->blendMode,
+            SDL_BlendPoint(&data->surface, 0, 0, renderer->blendMode,
                            renderer->r, renderer->g, renderer->b,
                            renderer->a);
     }
@@ -586,36 +591,49 @@
 SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
 {
     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;
+    }
+
     if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
-        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;
-        }
         SDL_AddDirtyRect(&data->dirty, &rect);
     }
 
     if (data->renderer->LockTexture(data->renderer,
                                     data->texture[data->current_texture],
-                                    &data->surface.clip_rect, 1,
+                                    &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;
+
     if (renderer->blendMode == SDL_BLENDMODE_NONE ||
         renderer->blendMode == SDL_BLENDMODE_MASK) {
         Uint32 color =