Mercurial > sdl-ios-xcode
comparison src/video/SDL_renderer_sw.c @ 2888:32e8bbba1e94
Added stubs for software implementations of blending fills and line drawing
author | Sam Lantinga <slouken@libsdl.org> |
---|---|
date | Sat, 20 Dec 2008 13:14:28 +0000 |
parents | 9dde605c7540 |
children | 67f84eb26ea1 |
comparison
equal
deleted
inserted
replaced
2887:f8c0c5ef6d54 | 2888:32e8bbba1e94 |
---|---|
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_SetDrawColor(SDL_Renderer * renderer); | 62 static int SW_SetDrawColor(SDL_Renderer * renderer); |
63 static int SW_SetDrawBlendMode(SDL_Renderer * renderer); | |
64 static int SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, | |
65 int y2); | |
63 static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); | 66 static int SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); |
64 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, | 67 static int SW_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, |
65 const SDL_Rect * srcrect, const SDL_Rect * dstrect); | 68 const SDL_Rect * srcrect, const SDL_Rect * dstrect); |
66 static void SW_RenderPresent(SDL_Renderer * renderer); | 69 static void SW_RenderPresent(SDL_Renderer * renderer); |
67 static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); | 70 static void SW_DestroyTexture(SDL_Renderer * renderer, SDL_Texture * texture); |
221 } | 224 } |
222 renderer->ActivateRenderer = SW_ActivateRenderer; | 225 renderer->ActivateRenderer = SW_ActivateRenderer; |
223 renderer->DisplayModeChanged = SW_DisplayModeChanged; | 226 renderer->DisplayModeChanged = SW_DisplayModeChanged; |
224 | 227 |
225 renderer->SetDrawColor = SW_SetDrawColor; | 228 renderer->SetDrawColor = SW_SetDrawColor; |
226 /* FIXME : Implement | 229 renderer->SetDrawBlendMode = SW_SetDrawBlendMode; |
227 renderer->SetDrawBlendMode = GL_SetDrawBlendMode; | 230 renderer->RenderLine = SW_RenderLine; |
228 renderer->RenderLine = GL_RenderLine; | |
229 */ | |
230 | |
231 renderer->RenderFill = SW_RenderFill; | 231 renderer->RenderFill = SW_RenderFill; |
232 renderer->RenderCopy = SW_RenderCopy; | 232 renderer->RenderCopy = SW_RenderCopy; |
233 renderer->RenderPresent = SW_RenderPresent; | 233 renderer->RenderPresent = SW_RenderPresent; |
234 renderer->DestroyRenderer = SW_DestroyRenderer; | 234 renderer->DestroyRenderer = SW_DestroyRenderer; |
235 renderer->info.name = SW_RenderDriver.info.name; | 235 renderer->info.name = SW_RenderDriver.info.name; |
530 { | 530 { |
531 return 0; | 531 return 0; |
532 } | 532 } |
533 | 533 |
534 static int | 534 static int |
535 SW_SetDrawBlendMode(SDL_Renderer * renderer) | |
536 { | |
537 return 0; | |
538 } | |
539 | |
540 static int | |
541 SW_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) | |
542 { | |
543 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; | |
544 int status; | |
545 | |
546 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { | |
547 SDL_Rect rect; | |
548 | |
549 if (x1 < x2) { | |
550 rect.x = x1; | |
551 rect.w = (x2 - x1) + 1; | |
552 } else { | |
553 rect.x = x2; | |
554 rect.w = (x1 - x2) + 1; | |
555 } | |
556 if (y1 < y2) { | |
557 rect.y = y1; | |
558 rect.h = (y2 - y1) + 1; | |
559 } else { | |
560 rect.y = y2; | |
561 rect.h = (y1 - y2) + 1; | |
562 } | |
563 SDL_AddDirtyRect(&data->dirty, &rect); | |
564 } | |
565 | |
566 if (data->renderer->LockTexture(data->renderer, | |
567 data->texture[data->current_texture], | |
568 NULL, 1, &data->surface.pixels, | |
569 &data->surface.pitch) < 0) { | |
570 return -1; | |
571 } | |
572 | |
573 if (renderer->blendMode == SDL_BLENDMODE_NONE) { | |
574 Uint32 color = | |
575 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g, | |
576 renderer->b, renderer->a); | |
577 | |
578 status = SDL_DrawLine(&data->surface, x1, y1, x2, y2, color); | |
579 } else { | |
580 status = | |
581 SDL_BlendLine(&data->surface, x1, y1, x2, y2, renderer->blendMode, | |
582 renderer->r, renderer->g, renderer->b, renderer->a); | |
583 } | |
584 | |
585 data->renderer->UnlockTexture(data->renderer, | |
586 data->texture[data->current_texture]); | |
587 return status; | |
588 } | |
589 | |
590 static int | |
535 SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) | 591 SW_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) |
536 { | 592 { |
537 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; | 593 SW_RenderData *data = (SW_RenderData *) renderer->driverdata; |
538 Uint32 color; | |
539 SDL_Rect real_rect; | 594 SDL_Rect real_rect; |
540 int status; | 595 int status; |
541 | 596 |
542 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { | 597 if (data->renderer->info.flags & SDL_RENDERER_PRESENTCOPY) { |
543 SDL_AddDirtyRect(&data->dirty, rect); | 598 SDL_AddDirtyRect(&data->dirty, rect); |
544 } | 599 } |
545 | |
546 color = SDL_MapRGBA(data->surface.format, | |
547 renderer->r, renderer->g, renderer->b, renderer->a); | |
548 | 600 |
549 if (data->renderer->LockTexture(data->renderer, | 601 if (data->renderer->LockTexture(data->renderer, |
550 data->texture[data->current_texture], | 602 data->texture[data->current_texture], |
551 rect, 1, &data->surface.pixels, | 603 rect, 1, &data->surface.pixels, |
552 &data->surface.pitch) < 0) { | 604 &data->surface.pitch) < 0) { |
553 return -1; | 605 return -1; |
554 } | 606 } |
607 | |
555 data->surface.w = rect->w; | 608 data->surface.w = rect->w; |
556 data->surface.h = rect->h; | 609 data->surface.h = rect->h; |
557 data->surface.clip_rect.w = rect->w; | 610 data->surface.clip_rect.w = rect->w; |
558 data->surface.clip_rect.h = rect->h; | 611 data->surface.clip_rect.h = rect->h; |
559 real_rect = data->surface.clip_rect; | 612 real_rect = data->surface.clip_rect; |
560 | 613 |
561 status = SDL_FillRect(&data->surface, &real_rect, color); | 614 if (renderer->blendMode == SDL_BLENDMODE_NONE) { |
615 Uint32 color = | |
616 SDL_MapRGBA(data->surface.format, renderer->r, renderer->g, | |
617 renderer->b, renderer->a); | |
618 | |
619 status = SDL_FillRect(&data->surface, &real_rect, color); | |
620 } else { | |
621 status = | |
622 SDL_BlendRect(&data->surface, &real_rect, renderer->blendMode, | |
623 renderer->r, renderer->g, renderer->b, renderer->a); | |
624 } | |
562 | 625 |
563 data->renderer->UnlockTexture(data->renderer, | 626 data->renderer->UnlockTexture(data->renderer, |
564 data->texture[data->current_texture]); | 627 data->texture[data->current_texture]); |
565 return status; | 628 return status; |
566 } | 629 } |