Mercurial > sdl-ios-xcode
diff 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 |
line wrap: on
line diff
--- a/src/video/x11/SDL_x11render.c Sat Dec 20 08:41:05 2008 +0000 +++ b/src/video/x11/SDL_x11render.c Sat Dec 20 12:00:00 2008 +0000 @@ -47,8 +47,11 @@ const SDL_Rect * rect, int markDirty, void **pixels, int *pitch); static void X11_UnlockTexture(SDL_Renderer * renderer, SDL_Texture * texture); -static int X11_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, - Uint8 a, const SDL_Rect * rect); +static int X11_SetDrawColor(SDL_Renderer * renderer); +static int X11_SetDrawBlendMode(SDL_Renderer * renderer); +static int X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, + int y2); +static int X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect); static int X11_RenderCopy(SDL_Renderer * renderer, SDL_Texture * texture, const SDL_Rect * srcrect, const SDL_Rect * dstrect); static void X11_RenderPresent(SDL_Renderer * renderer); @@ -65,7 +68,7 @@ SDL_RENDERER_PRESENTFLIP2 | SDL_RENDERER_PRESENTFLIP3 | SDL_RENDERER_PRESENTDISCARD | SDL_RENDERER_ACCELERATED), SDL_TEXTUREMODULATE_NONE, - SDL_TEXTUREBLENDMODE_NONE, + SDL_BLENDMODE_NONE, SDL_TEXTURESCALEMODE_NONE, 0, {0}, @@ -191,6 +194,9 @@ renderer->UpdateTexture = X11_UpdateTexture; renderer->LockTexture = X11_LockTexture; renderer->UnlockTexture = X11_UnlockTexture; + renderer->SetDrawColor = X11_SetDrawColor; + renderer->SetDrawBlendMode = X11_SetDrawBlendMode; + renderer->RenderLine = X11_RenderLine; renderer->RenderFill = X11_RenderFill; renderer->RenderCopy = X11_RenderCopy; renderer->RenderPresent = X11_RenderPresent; @@ -445,11 +451,11 @@ X11_SetTextureBlendMode(SDL_Renderer * renderer, SDL_Texture * texture) { switch (texture->blendMode) { - case SDL_TEXTUREBLENDMODE_NONE: + case SDL_BLENDMODE_NONE: return 0; default: SDL_Unsupported(); - texture->blendMode = SDL_TEXTUREBLENDMODE_NONE; + texture->blendMode = SDL_BLENDMODE_NONE; return -1; } } @@ -552,8 +558,73 @@ } static int -X11_RenderFill(SDL_Renderer * renderer, Uint8 r, Uint8 g, Uint8 b, Uint8 a, - const SDL_Rect * rect) +X11_SetDrawColor(SDL_Renderer * renderer) +{ + return 0; +} + +static int +X11_SetDrawBlendMode(SDL_Renderer * renderer) +{ + switch (renderer->blendMode) { + case SDL_BLENDMODE_NONE: + return 0; + default: + SDL_Unsupported(); + renderer->blendMode = SDL_BLENDMODE_NONE; + return -1; + } +} + +static Uint32 +renderdrawcolor(SDL_Renderer * renderer, int premult) +{ + X11_RenderData *data = (X11_RenderData *) renderer->driverdata; + Uint8 r = renderer->r; + Uint8 g = renderer->g; + Uint8 b = renderer->b; + Uint8 a = renderer->a; + if (premult) + return SDL_MapRGBA(data->format, ((int) r * (int) a) / 255, + ((int) g * (int) a) / 255, + ((int) b * (int) a) / 255, 255); + else + return SDL_MapRGBA(data->format, r, g, b, a); +} + +static int +X11_RenderLine(SDL_Renderer * renderer, int x1, int y1, int x2, int y2) +{ + X11_RenderData *data = (X11_RenderData *) renderer->driverdata; + unsigned long foreground; + if (data->makedirty) { + SDL_Rect rect; + + if (x1 < x2) { + rect.x = x1; + rect.w = (x2 - x1) + 1; + } else { + rect.x = x2; + rect.w = (x1 - x2) + 1; + } + if (y1 < y2) { + rect.y = y1; + rect.h = (y2 - y1) + 1; + } else { + rect.y = y2; + rect.h = (y1 - y2) + 1; + } + SDL_AddDirtyRect(&data->dirty, &rect); + } + + foreground = renderdrawcolor(renderer, 1); + XSetForeground(data->display, data->gc, foreground); + XDrawLine(data->display, data->drawable, data->gc, x1, y1, x2, y2); + +} + +static int +X11_RenderFill(SDL_Renderer * renderer, const SDL_Rect * rect) { X11_RenderData *data = (X11_RenderData *) renderer->driverdata; unsigned long foreground; @@ -562,9 +633,9 @@ SDL_AddDirtyRect(&data->dirty, rect); } - foreground = SDL_MapRGBA(data->format, r, g, b, a); + foreground = renderdrawcolor(renderer, 1); XSetForeground(data->display, data->gc, foreground); - XDrawRectangle(data->display, data->drawable, data->gc, rect->x, rect->y, + XFillRectangle(data->display, data->drawable, data->gc, rect->x, rect->y, rect->w, rect->h); return 0; }