SDL/src/render
Sam Lantinga ab8bd3d96b Fixed bug 3359 - Software renderer does incorrect blending with SDL_RenderCopyEx
Simon Hug

The software renderer produces incorrect results when blending textures at an angle with certain blend modes. It seems that there were some edge cases that weren't considered when the SW_RenderCopyEx function was last changed. Or another bug possibly covered up the problem. (More on that in another bug report.)

Most of the issues come from the fact that the rotating function sets a black colorkey. This is problematic because black is most likely appearing in the surface and the final blit will ignore these pixels. Unless a colorkey is already set (the software renderer currently never sets one), it's very hard to find a free color. Of course it could scan over the whole image until one is found, but that seems inefficient.

The following blend modes have issues when drawn at an angle.

NONE: The black pixels get ignored, making them essentially transparent. This breaks the 'dstRGBA = srcRGBA' definition of the NONE blend mode.

MOD: Again, the black pixels get ignored. This also breaks the 'dstRGB = dstRGB * srcRGB' definition of the MOD blend mode, where black pixels would make the destination black as well. A white colorkey will work though, with some preparations.

BLEND: There are some issues when blending a texture with a translucent RGBA target texture. I - uh - forgot what the problem here exactly is.

This patch fixes the issues mentioned above. It mainly changes the code so it tries to do things without the colorkey and removes the automatic format conversion part from the SDLgfx_rotateSurface function. Getting the format right is something the caller has to do now and the required code has been added to the SW_RenderCopyEx function.

There's a small change to the SW_CreateTexture function. RLE encoding a surface with an alpha mask can be a lossy process. Depending on how the user uses the RGBA channels, this may be undesired. The change that surfaces with an alpha mask don't get encoded makes the software renderer consistent with the other renderers.

The SW_RenderCopyEx function now does these steps: Lock the source surface if necessary. Create a clone of the source by using the pixel buffer directly. Check the format and set a flag if a conversion is necessary. Check if scaling or cropping is necessary and set the flag for that as well. Check if color and alpha modulation has to be done before the rotate. Check if the source is an opaque surface. If not, it creates a mask surface that is necessary for the NONE blend mode. If any of the flags were set, a new surface is created and the source will be converted, scaled, cropped, and modulated. The rest of the function stays somewhat the same. The mask also needs to be rotated of course and then there is the NONE blend mode...

It's surprisingly hard to get the pixel from a rotated surface to the destination buffer without affecting the pixel outside the rotated area. I found a way to do this with three blits which is pretty hard on the performance. Perhaps someone has an idea how to do this faster?

As mentioned above, the SDLgfx_rotateSurface now only takes 8-bit paletted or 32-bit with alpha mask surfaces. It additionally sets the new surfaces up for the MOD blend mode.

I shortly tested the 8-bit path of SDLgfx_rotateSurface and it seemed to work so far. This path is not used by the software renderer anyway.
2016-11-15 01:12:27 -08:00
..
direct3d Fixed bug 2421 for D3D9 - SDL_RenderCopyEx off by one when rotating by 90 and -90 2016-11-06 08:42:46 -08:00
direct3d11 Better fix for last point in D3D11 renderer, thanks to Nader Golbaz 2016-11-06 15:15:32 -08:00
opengl Patch from Sylvain to fix clang warnings 2016-11-13 22:57:41 -08:00
opengles Patch from Sylvain to fix clang warnings 2016-11-13 22:57:41 -08:00
opengles2 Patch from Sylvain to fix clang warnings 2016-11-13 22:57:41 -08:00
psp PSP: Fixed returning success from unsupported SDL_RenderReadPixels(). 2016-04-01 21:13:58 +02:00
software Fixed bug 3359 - Software renderer does incorrect blending with SDL_RenderCopyEx 2016-11-15 01:12:27 -08:00
SDL_d3dmath.c Updated copyright to 2016 2016-01-02 10:10:34 -08:00
SDL_d3dmath.h Updated copyright to 2016 2016-01-02 10:10:34 -08:00
SDL_render.c Fixed divide by zero if setting integer scale without setting logical width and height 2016-10-14 00:51:57 -07:00
SDL_sysrender.h SDL_RenderSetIntegerScale 2016-01-05 16:39:18 -05:00
SDL_yuv_mmx.c Updated copyright to 2016 2016-01-02 10:10:34 -08:00
SDL_yuv_sw.c Updated copyright to 2016 2016-01-02 10:10:34 -08:00
SDL_yuv_sw_c.h Updated copyright to 2016 2016-01-02 10:10:34 -08:00
mmx.h Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00