comparison src/video/SDL_renderer_sw.c @ 3596:f638ded38b8a

Added SDL_RenderClear() as a fast method of clearing the screen to the drawing color. Renamed SDL_RenderPoint() and SDL_RenderLine() to SDL_RenderDrawPoint() and SDL_RenderDrawLine(). Added API for rectangle drawing (as opposed to filling) Added placeholder API functions for circles and ellipses ... I'm not sure whether these will stay. Optimized software line drawing quite a bit. Added support for Wu's anti-aliased line drawing, currently disabled by default.
author Sam Lantinga <slouken@libsdl.org>
date Wed, 23 Dec 2009 01:55:00 +0000
parents 0267b8b1595c
children 0f958e527e5e
comparison
equal deleted inserted replaced
3595:b7c6828d4039 3596:f638ded38b8a
57 int pitch); 57 int pitch);
58 static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 58 static int SW_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
59 const SDL_Rect * rect, int markDirty, void **pixels, 59 const SDL_Rect * rect, int markDirty, void **pixels,
60 int *pitch); 60 int *pitch);
61 static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); 61 static void SW_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
62 static int SW_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, 62 static int SW_RenderDrawPoints(SDL_Renderer * renderer,
63 int count); 63 const SDL_Point * points, int count);
64 static int SW_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, 64 static int SW_RenderDrawLines(SDL_Renderer * renderer,
65 int count); 65 const SDL_Point * points, int count);
66 static int SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, 66 static int SW_RenderDrawRects(SDL_Renderer * renderer,
67 int count); 67 const SDL_Rect ** rects, int count);
68 static int SW_RenderFillRects(SDL_Renderer * renderer,
69 const SDL_Rect ** rects, int count);
68 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 70 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
69 const SDL_Rect * srcrect, const SDL_Rect * dstrect); 71 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
70 static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, 72 static int SW_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
71 Uint32 format, void * pixels, int pitch); 73 Uint32 format, void * pixels, int pitch);
72 static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect, 74 static int SW_RenderWritePixels(SDL_Renderer * renderer, const SDL_Rect * rect,
228 return NULL; 230 return NULL;
229 } 231 }
230 renderer->ActivateRenderer = SW_ActivateRenderer; 232 renderer->ActivateRenderer = SW_ActivateRenderer;
231 renderer->DisplayModeChanged = SW_DisplayModeChanged; 233 renderer->DisplayModeChanged = SW_DisplayModeChanged;
232 234
233 renderer->RenderPoints = SW_RenderPoints; 235 renderer->RenderDrawPoints = SW_RenderDrawPoints;
234 renderer->RenderLines = SW_RenderLines; 236 renderer->RenderDrawLines = SW_RenderDrawLines;
235 renderer->RenderRects = SW_RenderRects; 237 renderer->RenderDrawRects = SW_RenderDrawRects;
238 renderer->RenderFillRects = SW_RenderFillRects;
236 renderer->RenderCopy = SW_RenderCopy; 239 renderer->RenderCopy = SW_RenderCopy;
237 renderer->RenderReadPixels = SW_RenderReadPixels; 240 renderer->RenderReadPixels = SW_RenderReadPixels;
238 renderer->RenderWritePixels = SW_RenderWritePixels; 241 renderer->RenderWritePixels = SW_RenderWritePixels;
239 renderer->RenderPresent = SW_RenderPresent; 242 renderer->RenderPresent = SW_RenderPresent;
240 renderer->DestroyRenderer = SW_DestroyRenderer; 243 renderer->DestroyRenderer = SW_DestroyRenderer;
537 SDL_SW_UnlockYUVTexture((SDL_SW_YUVTexture *) texture->driverdata); 540 SDL_SW_UnlockYUVTexture((SDL_SW_YUVTexture *) texture->driverdata);
538 } 541 }
539 } 542 }
540 543
541 static int 544 static int
542 SW_RenderPoints(SDL_Renderer * renderer, const SDL_Point * points, int count) 545 SW_RenderDrawPoints(SDL_Renderer * renderer, const SDL_Point * points,
546 int count)
543 { 547 {
544 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; 548 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
545 SDL_Texture *texture = data->texture[data->current_texture]; 549 SDL_Texture *texture = data->texture[data->current_texture];
546 SDL_Rect rect; 550 SDL_Rect rect;
547 int i; 551 int i;
600 604
601 return status; 605 return status;
602 } 606 }
603 607
604 static int 608 static int
605 SW_RenderLines(SDL_Renderer * renderer, const SDL_Point * points, int count) 609 SW_RenderDrawLines(SDL_Renderer * renderer, const SDL_Point * points,
610 int count)
606 { 611 {
607 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; 612 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
608 SDL_Texture *texture = data->texture[data->current_texture]; 613 SDL_Texture *texture = data->texture[data->current_texture];
609 SDL_Rect clip, rect; 614 SDL_Rect clip, rect;
610 int i; 615 int i;
668 673
669 return status; 674 return status;
670 } 675 }
671 676
672 static int 677 static int
673 SW_RenderRects(SDL_Renderer * renderer, const SDL_Rect ** rects, int count) 678 SW_RenderDrawRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
679 int count)
674 { 680 {
675 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; 681 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
676 SDL_Texture *texture = data->texture[data->current_texture]; 682 SDL_Texture *texture = data->texture[data->current_texture];
677 SDL_Rect clip, rect; 683 SDL_Rect clip, rect;
678 Uint32 color = 0; 684 Uint32 color = 0;
710 data->surface.clip_rect.w = data->surface.w = rect.w; 716 data->surface.clip_rect.w = data->surface.w = rect.w;
711 data->surface.clip_rect.h = data->surface.h = rect.h; 717 data->surface.clip_rect.h = data->surface.h = rect.h;
712 718
713 if (renderer->blendMode == SDL_BLENDMODE_NONE || 719 if (renderer->blendMode == SDL_BLENDMODE_NONE ||
714 renderer->blendMode == SDL_BLENDMODE_MASK) { 720 renderer->blendMode == SDL_BLENDMODE_MASK) {
715 status = SDL_FillRect(&data->surface, NULL, color); 721 status = SDL_DrawRect(&data->surface, NULL, color);
716 } else { 722 } else {
717 status = SDL_BlendRect(&data->surface, NULL, 723 status = SDL_BlendRect(&data->surface, NULL,
718 renderer->blendMode, 724 renderer->blendMode,
719 renderer->r, renderer->g, renderer->b, 725 renderer->r, renderer->g, renderer->b,
720 renderer->a); 726 renderer->a);
727 }
728
729 data->renderer->UnlockTexture(data->renderer, texture);
730 }
731 return status;
732 }
733
734 static int
735 SW_RenderFillRects(SDL_Renderer * renderer, const SDL_Rect ** rects,
736 int count)
737 {
738 SW_RenderData *data = (SW_RenderData *) renderer->driverdata;
739 SDL_Texture *texture = data->texture[data->current_texture];
740 SDL_Rect clip, rect;
741 Uint32 color = 0;
742 int i;
743 int status = 0;
744
745 clip.x = 0;
746 clip.y = 0;
747 clip.w = texture->w;
748 clip.h = texture->h;
749
750 if (renderer->blendMode == SDL_BLENDMODE_NONE ||
751 renderer->blendMode == SDL_BLENDMODE_MASK) {
752 color = SDL_MapRGBA(data->surface.format,
753 renderer->r, renderer->g, renderer->b,
754 renderer->a);
755 }
756
757 for (i = 0; i < count; ++i) {
758 if (!SDL_IntersectRect(rects[i], &clip, &rect)) {
759 /* Nothing to draw */
760 continue;
761 }
762
763 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) {
764 SDL_AddDirtyRect(&data->dirty, &rect);
765 }
766
767 if (data->renderer->LockTexture(data->renderer, texture, &rect, 1,
768 &data->surface.pixels,
769 &data->surface.pitch) < 0) {
770 return -1;
771 }
772
773 data->surface.clip_rect.w = data->surface.w = rect.w;
774 data->surface.clip_rect.h = data->surface.h = rect.h;
775
776 if (renderer->blendMode == SDL_BLENDMODE_NONE ||
777 renderer->blendMode == SDL_BLENDMODE_MASK) {
778 status = SDL_FillRect(&data->surface, NULL, color);
779 } else {
780 status = SDL_BlendFillRect(&data->surface, NULL,
781 renderer->blendMode,
782 renderer->r, renderer->g, renderer->b,
783 renderer->a);
721 } 784 }
722 785
723 data->renderer->UnlockTexture(data->renderer, texture); 786 data->renderer->UnlockTexture(data->renderer, texture);
724 } 787 }
725 return status; 788 return status;