comparison src/video/x11/SDL_x11render.c @ 2884:9dde605c7540

Date: Fri, 19 Dec 2008 20:17:35 +0100 From: Couriersud Subject: Re: Aw: Experience using SDL1.3 in sdlmame/Proposal for api additions > For consistency you'd probably want: > SDL_SetRenderDrawColor(Uint8 r, Uint8 g, Uint8 b, Uint8 a); > SDL_SetRenderDrawBlendMode(SDL_BlendMode blendMode); > SDL_RenderLine(int x1, int y1, int x2, int y2); > SDL_RenderFill(SDL_Rect *rect); > > You probably also want to add API functions query the current state. > I have implemented the above api for the opengl, x11, directfb and software renderers. I have also renamed *TEXTUREBLENDMODE* constants to BLENDMODE*. The unix build compiles. The windows renderer still needs to be updated, but I have no windows development machine at hand. Have a look at the x11 renderer for a sample. Vector games now run at 90% both on opengl and directfb in comparison to sdlmame's own opengl renderer. The same applies to raster games. The diff also includes a) Changed XDrawRect to XFillRect in x11 renderer b) A number of changes to fix blending and modulation issues in the directfb renderer.
author Sam Lantinga <slouken@libsdl.org>
date Sat, 20 Dec 2008 12:00:00 +0000
parents 04e89201f6ed
children 32e8bbba1e94
comparison
equal deleted inserted replaced
2883:11626a53e7bc 2884:9dde605c7540
45 int pitch); 45 int pitch);
46 static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture, 46 static int X11_LockTexture(SDL_Renderer * renderer, SDL_Texture * texture,
47 const SDL_Rect * rect, int markDirty, 47 const SDL_Rect * rect, int markDirty,
48 void **pixels, int *pitch); 48 void **pixels, int *pitch);
49 static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); 49 static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture);
50 static int X11_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, 50 static int X11_SetDrawColor(SDL_Renderer * renderer);
51 Uint8 a, const SDL_Rect * rect); 51 static int X11_SetDrawBlendMode(SDL_Renderer * renderer);
52 static int X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2,
53 int y2);
54 static int X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect);
52 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, 55 static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture,
53 const SDL_Rect * srcrect, const SDL_Rect * dstrect); 56 const SDL_Rect * srcrect, const SDL_Rect * dstrect);
54 static void X11_RenderPresent(SDL_Renderer * renderer); 57 static void X11_RenderPresent(SDL_Renderer * renderer);
55 static void X11_DestroyTexture(SDL_Renderer * renderer, 58 static void X11_DestroyTexture(SDL_Renderer * renderer,
56 SDL_Texture * texture); 59 SDL_Texture * texture);
63 "x11", 66 "x11",
64 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY | 67 (SDL_RENDERER_SINGLEBUFFER | SDL_RENDERER_PRESENTCOPY |
65 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | 68 SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 |
66 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED), 69 SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED),
67 SDL_TEXTUREMODULATE_NONE, 70 SDL_TEXTUREMODULATE_NONE,
68 SDL_TEXTUREBLENDMODE_NONE, 71 SDL_BLENDMODE_NONE,
69 SDL_TEXTURESCALEMODE_NONE, 72 SDL_TEXTURESCALEMODE_NONE,
70 0, 73 0,
71 {0}, 74 {0},
72 0, 75 0,
73 0} 76 0}
189 renderer->SetTextureBlendMode = X11_SetTextureBlendMode; 192 renderer->SetTextureBlendMode = X11_SetTextureBlendMode;
190 renderer->SetTextureScaleMode = X11_SetTextureScaleMode; 193 renderer->SetTextureScaleMode = X11_SetTextureScaleMode;
191 renderer->UpdateTexture = X11_UpdateTexture; 194 renderer->UpdateTexture = X11_UpdateTexture;
192 renderer->LockTexture = X11_LockTexture; 195 renderer->LockTexture = X11_LockTexture;
193 renderer->UnlockTexture = X11_UnlockTexture; 196 renderer->UnlockTexture = X11_UnlockTexture;
197 renderer->SetDrawColor = X11_SetDrawColor;
198 renderer->SetDrawBlendMode = X11_SetDrawBlendMode;
199 renderer->RenderLine = X11_RenderLine;
194 renderer->RenderFill = X11_RenderFill; 200 renderer->RenderFill = X11_RenderFill;
195 renderer->RenderCopy = X11_RenderCopy; 201 renderer->RenderCopy = X11_RenderCopy;
196 renderer->RenderPresent = X11_RenderPresent; 202 renderer->RenderPresent = X11_RenderPresent;
197 renderer->DestroyTexture = X11_DestroyTexture; 203 renderer->DestroyTexture = X11_DestroyTexture;
198 renderer->DestroyRenderer = X11_DestroyRenderer; 204 renderer->DestroyRenderer = X11_DestroyRenderer;
443 449
444 static int 450 static int
445 X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) 451 X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture)
446 { 452 {
447 switch (texture->blendMode) { 453 switch (texture->blendMode) {
448 case SDL_TEXTUREBLENDMODE_NONE: 454 case SDL_BLENDMODE_NONE:
449 return 0; 455 return 0;
450 default: 456 default:
451 SDL_Unsupported(); 457 SDL_Unsupported();
452 texture->blendMode = SDL_TEXTUREBLENDMODE_NONE; 458 texture->blendMode = SDL_BLENDMODE_NONE;
453 return -1; 459 return -1;
454 } 460 }
455 } 461 }
456 462
457 static int 463 static int
550 UpdateYUVTextureData(texture); 556 UpdateYUVTextureData(texture);
551 } 557 }
552 } 558 }
553 559
554 static int 560 static int
555 X11_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, 561 X11_SetDrawColor(SDL_Renderer * renderer)
556 const SDL_Rect * rect) 562 {
563 return 0;
564 }
565
566 static int
567 X11_SetDrawBlendMode(SDL_Renderer * renderer)
568 {
569 switch (renderer->blendMode) {
570 case SDL_BLENDMODE_NONE:
571 return 0;
572 default:
573 SDL_Unsupported();
574 renderer->blendMode = SDL_BLENDMODE_NONE;
575 return -1;
576 }
577 }
578
579 static Uint32
580 renderdrawcolor(SDL_Renderer * renderer, int premult)
581 {
582 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
583 Uint8 r = renderer->r;
584 Uint8 g = renderer->g;
585 Uint8 b = renderer->b;
586 Uint8 a = renderer->a;
587 if (premult)
588 return SDL_MapRGBA(data->format, ((int) r * (int) a) / 255,
589 ((int) g * (int) a) / 255,
590 ((int) b * (int) a) / 255, 255);
591 else
592 return SDL_MapRGBA(data->format, r, g, b, a);
593 }
594
595 static int
596 X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2)
557 { 597 {
558 X11_RenderData *data = (X11_RenderData *) renderer->driverdata; 598 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
559 unsigned long foreground; 599 unsigned long foreground;
600 if (data->makedirty) {
601 SDL_Rect rect;
602
603 if (x1 < x2) {
604 rect.x = x1;
605 rect.w = (x2 - x1) + 1;
606 } else {
607 rect.x = x2;
608 rect.w = (x1 - x2) + 1;
609 }
610 if (y1 < y2) {
611 rect.y = y1;
612 rect.h = (y2 - y1) + 1;
613 } else {
614 rect.y = y2;
615 rect.h = (y1 - y2) + 1;
616 }
617 SDL_AddDirtyRect(&data->dirty, &rect);
618 }
619
620 foreground = renderdrawcolor(renderer, 1);
621 XSetForeground(data->display, data->gc, foreground);
622 XDrawLine(data->display, data->drawable, data->gc, x1, y1, x2, y2);
623
624 }
625
626 static int
627 X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect)
628 {
629 X11_RenderData *data = (X11_RenderData *) renderer->driverdata;
630 unsigned long foreground;
560 631
561 if (data->makedirty) { 632 if (data->makedirty) {
562 SDL_AddDirtyRect(&data->dirty, rect); 633 SDL_AddDirtyRect(&data->dirty, rect);
563 } 634 }
564 635
565 foreground = SDL_MapRGBA(data->format, r, g, b, a); 636 foreground = renderdrawcolor(renderer, 1);
566 XSetForeground(data->display, data->gc, foreground); 637 XSetForeground(data->display, data->gc, foreground);
567 XDrawRectangle(data->display, data->drawable, data->gc, rect->x, rect->y, 638 XFillRectangle(data->display, data->drawable, data->gc, rect->x, rect->y,
568 rect->w, rect->h); 639 rect->w, rect->h);
569 return 0; 640 return 0;
570 } 641 }
571 642
572 static int 643 static int