comparison src/video/SDL_renderer_sw.c @ 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 133601e3b255
children d214e791c77c
comparison
equal deleted inserted replaced
2903:e426c4fc9cf7 2904:fa81cc1ef3d0
541 541
542 static int 542 static int
543 SW_RenderPoint(SDL_Renderer * renderer, int x, int y) 543 SW_RenderPoint(SDL_Renderer * renderer, int x, int y)
544 { 544 {
545 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; 545 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
546 SDL_Rect rect;
546 int status; 547 int status;
547 548
549 rect.x = x;
550 rect.y = y;
551 rect.w = 1;
552 rect.h = 1;
553
548 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { 554 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
549 SDL_Rect rect;
550
551 rect.x = x;
552 rect.y = y;
553 rect.w = 1;
554 rect.h = 1;
555 SDL_AddDirtyRect(&data->dirty, &rect); 555 SDL_AddDirtyRect(&data->dirty, &rect);
556 } 556 }
557 557
558 if (data->renderer->LockTexture(data->renderer, 558 if (data->renderer->LockTexture(data->renderer,
559 data->texture[data->current_texture], 559 data->texture[data->current_texture],
560 &data->surface.clip_rect, 1, 560 &rect, 1,
561 &data->surface.pixels, 561 &data->surface.pixels,
562 &data->surface.pitch) < 0) { 562 &data->surface.pitch) < 0) {
563 return -1; 563 return -1;
564 } 564 }
565
566 data->surface.w = 1;
567 data->surface.h = 1;
568 data->surface.clip_rect.w = 1;
569 data->surface.clip_rect.h = 1;
565 570
566 if (renderer->blendMode == SDL_BLENDMODE_NONE || 571 if (renderer->blendMode == SDL_BLENDMODE_NONE ||
567 renderer->blendMode == SDL_BLENDMODE_MASK) { 572 renderer->blendMode == SDL_BLENDMODE_MASK) {
568 Uint32 color = 573 Uint32 color =
569 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g, 574 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g,
570 renderer->b, renderer->a); 575 renderer->b, renderer->a);
571 576
572 status = SDL_DrawPoint(&data->surface, x, y, color); 577 status = SDL_DrawPoint(&data->surface, 0, 0, color);
573 } else { 578 } else {
574 status = 579 status =
575 SDL_BlendPoint(&data->surface, x, y, renderer->blendMode, 580 SDL_BlendPoint(&data->surface, 0, 0, renderer->blendMode,
576 renderer->r, renderer->g, renderer->b, 581 renderer->r, renderer->g, renderer->b,
577 renderer->a); 582 renderer->a);
578 } 583 }
579 584
580 data->renderer->UnlockTexture(data->renderer, 585 data->renderer->UnlockTexture(data->renderer,
584 589
585 static int 590 static int
586 SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) 591 SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
587 { 592 {
588 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; 593 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
594 SDL_Rect rect;
589 int status; 595 int status;
590 596
597 if (x1 < x2) {
598 rect.x = x1;
599 rect.w = (x2 - x1) + 1;
600 x2 -= x1;
601 x1 = 0;
602 } else {
603 rect.x = x2;
604 rect.w = (x1 - x2) + 1;
605 x1 -= x2;
606 x2 = 0;
607 }
608 if (y1 < y2) {
609 rect.y = y1;
610 rect.h = (y2 - y1) + 1;
611 y2 -= y1;
612 y1 = 0;
613 } else {
614 rect.y = y2;
615 rect.h = (y1 - y2) + 1;
616 y1 -= y2;
617 y2 = 0;
618 }
619
591 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { 620 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
592 SDL_Rect rect;
593
594 if (x1 < x2) {
595 rect.x = x1;
596 rect.w = (x2 - x1) + 1;
597 } else {
598 rect.x = x2;
599 rect.w = (x1 - x2) + 1;
600 }
601 if (y1 < y2) {
602 rect.y = y1;
603 rect.h = (y2 - y1) + 1;
604 } else {
605 rect.y = y2;
606 rect.h = (y1 - y2) + 1;
607 }
608 SDL_AddDirtyRect(&data->dirty, &rect); 621 SDL_AddDirtyRect(&data->dirty, &rect);
609 } 622 }
610 623
611 if (data->renderer->LockTexture(data->renderer, 624 if (data->renderer->LockTexture(data->renderer,
612 data->texture[data->current_texture], 625 data->texture[data->current_texture],
613 &data->surface.clip_rect, 1, 626 &rect, 1,
614 &data->surface.pixels, 627 &data->surface.pixels,
615 &data->surface.pitch) < 0) { 628 &data->surface.pitch) < 0) {
616 return -1; 629 return -1;
617 } 630 }
631
632 data->surface.w = rect.w;
633 data->surface.h = rect.h;
634 data->surface.clip_rect.w = rect.w;
635 data->surface.clip_rect.h = rect.h;
618 636
619 if (renderer->blendMode == SDL_BLENDMODE_NONE || 637 if (renderer->blendMode == SDL_BLENDMODE_NONE ||
620 renderer->blendMode == SDL_BLENDMODE_MASK) { 638 renderer->blendMode == SDL_BLENDMODE_MASK) {
621 Uint32 color = 639 Uint32 color =
622 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g, 640 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g,