We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2639

Summary: SDL_BLENDMODE_BLEND not working properly for software renderer
Product: SDL Reporter: Damian Kaczmarek <rush>
Component: renderAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2 CC: meklu
Version: HG 2.0   
Hardware: x86_64   
OS: Linux   
Attachments: Source coding showing the problem
software blending patch
software blending patch - non-eaten version
software blending patch - v2
Updated test code
software blending patch - v3

Description Damian Kaczmarek 2014-07-12 19:40:34 UTC
Created attachment 1742 [details]
Source coding showing the problem

I attach a program showing the problem. 

g++ sdl2bug.cpp -lSDL2 && ./a.out

Window on the right shows software renderer which is wrong
Window on the left shows hardware renderer which is right

I would also appreciate suggestions if there are possible workarounds
Comment 1 Damian Kaczmarek 2014-07-12 19:46:05 UTC
I should also add that setting render mode does not fail.
Comment 2 Sam Lantinga 2014-07-12 20:08:00 UTC
Great bug report, I'll look into it.

Thanks!
Comment 3 Melker Narikka 2014-07-12 20:57:22 UTC
Created attachment 1743 [details]
software blending patch

Does this patch help?
Comment 4 Melker Narikka 2014-07-12 21:04:39 UTC
Created attachment 1744 [details]
software blending patch - non-eaten version

Oops, bugzilla ate the patch headers :(
Comment 5 Damian Kaczmarek 2014-07-12 21:08:25 UTC
I applied the patch manually and it works! Thanks!
Comment 7 Melker Narikka 2014-07-12 22:01:42 UTC
Created attachment 1745 [details]
software blending patch - v2

Here's an updated patch. Does it make a difference?
Comment 8 Damian Kaczmarek 2014-07-12 22:29:55 UTC
Created attachment 1746 [details]
Updated test code

Added a semi-transparent green rectangle being blended, again this shows different results from software and hardware renderers
Comment 9 Damian Kaczmarek 2014-07-12 22:30:41 UTC
Otherwise your latest patch fixes the most obvious problems, we're getting there! Good work.
Comment 10 Melker Narikka 2014-07-12 23:01:06 UTC
Created attachment 1747 [details]
software blending patch - v3

Okay, let's try that again, shall we? This one only touches the alpha, and seems to act right with the updated test case.
Comment 11 Damian Kaczmarek 2014-07-12 23:10:07 UTC
Seems to work perfectly, thank you!
Comment 12 Sam Lantinga 2014-07-12 23:12:48 UTC
Does this work?
sa = DRAW_MUL(inva, sa) + a;
Comment 13 Melker Narikka 2014-07-12 23:14:14 UTC
(In reply to Sam Lantinga from comment #12)
> Does this work?
> sa = DRAW_MUL(inva, sa) + a;

v3 does just that :)
Comment 14 Sam Lantinga 2014-07-12 23:15:04 UTC
Yeah, I just wanted to see if ordering mattered, for consistency with the previous lines.
Comment 15 Damian Kaczmarek 2014-07-12 23:16:05 UTC
It works quite fine.
Comment 16 Sam Lantinga 2014-07-12 23:22:30 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/515be38f3f37