Fixed clip_rect when drawing points and lines with software renderer.
authorSam Lantinga <slouken@libsdl.org>
Sun, 21 Dec 2008 20:17:41 +0000
changeset 2904fa81cc1ef3d0
parent 2903 e426c4fc9cf7
child 2905 d214e791c77c
Fixed clip_rect when drawing points and lines with software renderer.
Lock the minimal rect to minimize texture uploads
src/video/SDL_renderer_sw.c
     1.1 --- a/src/video/SDL_renderer_sw.c	Sun Dec 21 20:16:21 2008 +0000
     1.2 +++ b/src/video/SDL_renderer_sw.c	Sun Dec 21 20:17:41 2008 +0000
     1.3 @@ -543,36 +543,41 @@
     1.4  SW_RenderPoint(SDL_Renderer * renderer, int x, int y)
     1.5  {
     1.6      SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
     1.7 +    SDL_Rect rect;
     1.8      int status;
     1.9  
    1.10 +    rect.x = x;
    1.11 +    rect.y = y;
    1.12 +    rect.w = 1;
    1.13 +    rect.h = 1;
    1.14 +
    1.15      if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
    1.16 -        SDL_Rect rect;
    1.17 -
    1.18 -        rect.x = x;
    1.19 -        rect.y = y;
    1.20 -        rect.w = 1;
    1.21 -        rect.h = 1;
    1.22          SDL_AddDirtyRect(&data->dirty, &rect);
    1.23      }
    1.24  
    1.25      if (data->renderer->LockTexture(data->renderer,
    1.26                                      data->texture[data->current_texture],
    1.27 -                                    &data->surface.clip_rect, 1,
    1.28 +                                    &rect, 1,
    1.29                                      &data->surface.pixels,
    1.30                                      &data->surface.pitch) < 0) {
    1.31          return -1;
    1.32      }
    1.33  
    1.34 +    data->surface.w = 1;
    1.35 +    data->surface.h = 1;
    1.36 +    data->surface.clip_rect.w = 1;
    1.37 +    data->surface.clip_rect.h = 1;
    1.38 +
    1.39      if (renderer->blendMode == SDL_BLENDMODE_NONE ||
    1.40          renderer->blendMode == SDL_BLENDMODE_MASK) {
    1.41          Uint32 color =
    1.42              SDL_MapRGBA(data->surface.format, renderer->r, renderer->g,
    1.43                          renderer->b, renderer->a);
    1.44  
    1.45 -        status = SDL_DrawPoint(&data->surface, x, y, color);
    1.46 +        status = SDL_DrawPoint(&data->surface, 0, 0, color);
    1.47      } else {
    1.48          status =
    1.49 -            SDL_BlendPoint(&data->surface, x, y, renderer->blendMode,
    1.50 +            SDL_BlendPoint(&data->surface, 0, 0, renderer->blendMode,
    1.51                             renderer->r, renderer->g, renderer->b,
    1.52                             renderer->a);
    1.53      }
    1.54 @@ -586,36 +591,49 @@
    1.55  SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
    1.56  {
    1.57      SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
    1.58 +    SDL_Rect rect;
    1.59      int status;
    1.60  
    1.61 +    if (x1 < x2) {
    1.62 +        rect.x = x1;
    1.63 +        rect.w = (x2 - x1) + 1;
    1.64 +        x2 -= x1;
    1.65 +        x1 = 0;
    1.66 +    } else {
    1.67 +        rect.x = x2;
    1.68 +        rect.w = (x1 - x2) + 1;
    1.69 +        x1 -= x2;
    1.70 +        x2 = 0;
    1.71 +    }
    1.72 +    if (y1 < y2) {
    1.73 +        rect.y = y1;
    1.74 +        rect.h = (y2 - y1) + 1;
    1.75 +        y2 -= y1;
    1.76 +        y1 = 0;
    1.77 +    } else {
    1.78 +        rect.y = y2;
    1.79 +        rect.h = (y1 - y2) + 1;
    1.80 +        y1 -= y2;
    1.81 +        y2 = 0;
    1.82 +    }
    1.83 +
    1.84      if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
    1.85 -        SDL_Rect rect;
    1.86 -
    1.87 -        if (x1 < x2) {
    1.88 -            rect.x = x1;
    1.89 -            rect.w = (x2 - x1) + 1;
    1.90 -        } else {
    1.91 -            rect.x = x2;
    1.92 -            rect.w = (x1 - x2) + 1;
    1.93 -        }
    1.94 -        if (y1 < y2) {
    1.95 -            rect.y = y1;
    1.96 -            rect.h = (y2 - y1) + 1;
    1.97 -        } else {
    1.98 -            rect.y = y2;
    1.99 -            rect.h = (y1 - y2) + 1;
   1.100 -        }
   1.101          SDL_AddDirtyRect(&data->dirty, &rect);
   1.102      }
   1.103  
   1.104      if (data->renderer->LockTexture(data->renderer,
   1.105                                      data->texture[data->current_texture],
   1.106 -                                    &data->surface.clip_rect, 1,
   1.107 +                                    &rect, 1,
   1.108                                      &data->surface.pixels,
   1.109                                      &data->surface.pitch) < 0) {
   1.110          return -1;
   1.111      }
   1.112  
   1.113 +    data->surface.w = rect.w;
   1.114 +    data->surface.h = rect.h;
   1.115 +    data->surface.clip_rect.w = rect.w;
   1.116 +    data->surface.clip_rect.h = rect.h;
   1.117 +
   1.118      if (renderer->blendMode == SDL_BLENDMODE_NONE ||
   1.119          renderer->blendMode == SDL_BLENDMODE_MASK) {
   1.120          Uint32 color =