Simple Directmedia Layer
Go to file
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
acinclude Fixed bug 3481 - Configure fails to detect dynamic library support on powerpc64le 2016-11-06 20:26:48 -08:00
android-project Fixed bug 3444 - Android-TV: no more handling of back button on remote 2016-10-17 22:09:22 -07:00
build-scripts nacl: pepper_49 SDK apparently has problems, move buildbot back to pepper_47. 2016-11-10 11:26:44 -05:00
cmake cmake: Now generates Wayland protocol source bits like the configure script. 2016-10-11 16:36:40 -04:00
debian Replaced SDL_qsort with public domain code from PDCLib: http://pdclib.e43.eu/ 2016-02-15 03:16:46 -05:00
docs Fixed outdated info in README. 2016-10-30 21:01:33 +01:00
include Fixed build error with missing function prototype in the SDL_test_harness.h header 2016-11-13 23:09:42 -08:00
src Fixed bug 3359 - Software renderer does incorrect blending with SDL_RenderCopyEx 2016-11-15 01:12:27 -08:00
test Added USB VID/PID information to the SDL test programs 2016-11-10 18:53:50 -08:00
VisualC Fixed compiler option warning for 64-bit builds on Visual Studio 2008 2016-10-14 08:56:04 -07:00
VisualC-WinRT Merge audio capture work back into the mainline. 2016-08-28 13:36:13 -04:00
visualtest Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
Xcode Build SDL as universal binary 2016-10-12 18:46:17 -07:00
Xcode-iOS iOS: Updated demo README. 2016-10-09 20:30:49 +02:00
.hgignore audio: Initial bits to enable audio capture support. 2016-08-01 00:18:56 -04:00
Android.mk Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
autogen.sh Fix running autogen.sh out-of-tree 2016-10-01 10:39:03 -07:00
BUGS.txt BUGS.txt: Bugzilla supports SSL; changed link to https:// ... 2016-08-01 13:36:43 -04:00
cmake_uninstall.cmake.in Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
CMakeLists.txt Fixed building with cmake when fcitx isn't installed 2016-10-14 01:04:21 -07:00
configure Standardized the format of the SDL joystick GUID and added functions to retrieve the USB VID/PID from a joystick and game controller. 2016-11-10 17:19:34 -08:00
configure.in Standardized the format of the SDL joystick GUID and added functions to retrieve the USB VID/PID from a joystick and game controller. 2016-11-10 17:19:34 -08:00
COPYING.txt Updated copyright to 2016 2016-01-02 10:10:34 -08:00
CREDITS.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
INSTALL.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
Makefile.in wayland: Build own version of core protocol 2016-06-23 18:39:05 +08:00
Makefile.minimal Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
Makefile.pandora Pandora: Fixed referring to no more existing atomic source file in Makefile. 2016-07-19 21:01:13 +02:00
Makefile.psp PSP: Added missing object for generic TLS to Makefile. 2016-02-13 17:34:14 +01:00
Makefile.wiz Pandora: Updated SDL version in Makefile. 2016-07-19 21:01:30 +02:00
README-SDL.txt Another commit to test revision control. 2016-03-08 20:26:26 -05:00
README.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
sdl2-config.cmake.in Applied Ubuntu patch bug_822210_fix_sdl2-config.cmake_whitespace.patch 2016-10-07 15:08:37 -07:00
sdl2-config.in Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
sdl2.m4 Fixed bug 3429 - Update AM_PATH_SDL2() to also check for SDL2.framework 2016-09-29 16:37:08 -07:00
sdl2.pc.in Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
SDL2.spec.in Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
TODO.txt Fixed crash if initialization of EGL failed but was tried again later. 2015-06-21 17:33:46 +02:00
VisualC.html Fixed two typos in documentation. 2016-01-12 22:23:53 +01:00
WhatsNew.txt Added note for David Carlier's work on OpenBSD 2016-10-12 18:57:12 -07:00

                         Simple DirectMedia Layer

                                  (SDL)

                                Version 2.0

---
http://www.libsdl.org/

Simple DirectMedia Layer is a cross-platform development library designed
to provide low level access to audio, keyboard, mouse, joystick, and graphics
hardware via OpenGL and Direct3D. It is used by video playback software,
emulators, and popular games including Valve's award winning catalog
and many Humble Bundle games.

More extensive documentation is available in the docs directory, starting
with README.md

Enjoy!
	Sam Lantinga				(slouken@libsdl.org)