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 2646 - Problems with software renderer when SDL_SetRenderLogicalSize set
Summary: Problems with software renderer when SDL_SetRenderLogicalSize set
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: HG 2.0
Hardware: x86_64 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-07-16 10:40 UTC by Damian Kaczmarek
Modified: 2017-08-14 05:50 UTC (History)
2 users (show)

See Also:


Attachments
Example showing the problem (3.82 KB, text/x-c++src)
2014-07-16 10:40 UTC, Damian Kaczmarek
Details
Example showing the problem (3.84 KB, text/x-c++src)
2014-07-16 11:50 UTC, Damian Kaczmarek
Details
Screenshot of bug (17.45 KB, image/png)
2014-07-16 11:52 UTC, Damian Kaczmarek
Details
SetLogicalSize patch (7.57 KB, patch)
2014-07-17 10:49 UTC, Melker Narikka
Details | Diff
Example showing the problem (3.86 KB, patch)
2014-07-17 11:49 UTC, Damian Kaczmarek
Details | Diff
SetLogicalSize patch - v2 (8.21 KB, patch)
2014-07-18 21:02 UTC, Melker Narikka
Details | Diff
Example showing the problem (3.93 KB, text/x-c++src)
2014-07-18 22:33 UTC, Damian Kaczmarek
Details
SetLogicalSize patch - v3 (8.22 KB, patch)
2014-07-18 23:04 UTC, Melker Narikka
Details | Diff
SetLogicalSize patch - v4 (7.69 KB, patch)
2014-07-19 16:52 UTC, Melker Narikka
Details | Diff
Patch for current SDL2 version (754 bytes, patch)
2016-04-03 00:33 UTC, Roberto Prieto
Details | Diff
SetLogicalSize patch - v5 (1.20 KB, patch)
2016-04-03 00:44 UTC, Roberto Prieto
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Damian Kaczmarek 2014-07-16 10:40:08 UTC
Created attachment 1761 [details]
Example showing the problem

When SDL_RenderSetLogicalSize is set the behavior of software renderer is buggy:

Couple of problems:
1) Weird software renderer texture contraption while rendering textures on edges
2) Software renderer does not add black borders at all which makes it not viable to use with resizeable windows at all.

Also there is an accidentally discovered problem with black borders on hardware renderer - see Hardware window #2 in the demo


Note: requires latest HG since the test is based on other bugs being fixed


Compile and run with:
g++ sdl_software_renderer_logical_size_problems.cpp -lSDL2 && ./a.out
Comment 1 Damian Kaczmarek 2014-07-16 11:50:54 UTC
Created attachment 1762 [details]
Example showing the problem
Comment 2 Damian Kaczmarek 2014-07-16 11:52:11 UTC
Created attachment 1763 [details]
Screenshot of bug
Comment 3 Melker Narikka 2014-07-17 10:49:05 UTC
Created attachment 1767 [details]
SetLogicalSize patch

(Note that this patch also includes patches 1754 and 1755 from bug #2198.)

This patch seems to fix the behaviour of the test case.

I also added these lines to the test case after the RenderCopy call to
test the RenderCopyEx clipping (which this patch addresses as well):

    SDL_SetTextureColorMod(semiTransparentTexture, 255, 0, 255);
    SDL_RenderCopyEx(renderer, semiTransparentTexture, &a, &b, 45.0, NULL, SDL_FLIP_NONE);
    SDL_SetTextureColorMod(semiTransparentTexture, 255, 255, 255);
Comment 4 Damian Kaczmarek 2014-07-17 11:49:09 UTC
Created attachment 1769 [details]
Example showing the problem

Updated test case to show problems when rendering the texture at x < 0
Comment 5 Melker Narikka 2014-07-18 21:02:38 UTC
Created attachment 1774 [details]
SetLogicalSize patch - v2

Here's an updated patch that should work, mostly at the very least. There's a weird offset issue with this patch with RenderCopyEx and rotated surfaces though, where I'm getting results that are (1px, 2px) off. This might be due to lossy integer arithmetic.
Comment 6 Damian Kaczmarek 2014-07-18 22:21:52 UTC
Thanks for the latest patch. It is much better but I still find a lot of issues .. need to think how to update the test code.
Comment 7 Damian Kaczmarek 2014-07-18 22:33:42 UTC
Created attachment 1775 [details]
Example showing the problem

Two problems, first see the difference of rendering at the beginning of the rendering code. The rectangle is displayed well .. kind of shifted at the beginning. Second problem is triggered by playing with the size of the window with the mouse, lots of artifacts are being created when resizing the software windows with the mouse.
Comment 8 Melker Narikka 2014-07-18 23:04:33 UTC
Created attachment 1776 [details]
SetLogicalSize patch - v3

I was supposed to make the if/elif/else blocks if+if/else. Hmm, here I thought I had done just that. Anyway, that addresses the shifted rectangle issue, which was caused by ignoring some fairly important offsets when the rectangle was rendered at negative coordinates.

As for the visual artifact issue, I think that's due to not clearing the renderer between frames. I'm getting some really nasty window damage when resizing the hardware-backed renderer[1]. Curiously enough, the software renderer doesn't do this on my system...
Is this similar to what you're seeing?

[1] http://i.imgur.com/9tBag9t.png
Comment 9 Damian Kaczmarek 2014-07-18 23:11:49 UTC
I confirm the newest patch fixes the shift. For me hardware renderer works properly and only software leaves the window damage [1] I am using NVIDIA blob drivers.

[1] http://x.rushbase.net/ebb4c6f9a824f424944497e1f78572b560f13c7e/damage.png
Comment 10 Melker Narikka 2014-07-19 16:52:45 UTC
Created attachment 1777 [details]
SetLogicalSize patch - v4

Here's an updated patch with some silliness removed. Should behave identically to v3.
Comment 11 Roberto Prieto 2016-04-03 00:33:50 UTC
Created attachment 2405 [details]
Patch for current SDL2 version

Minimum patch file for fixing this bug on current SDL2 version (as of 29-March-2016), based on SetLogicalSize patch - v4
Comment 12 Roberto Prieto 2016-04-03 00:44:32 UTC
Created attachment 2406 [details]
SetLogicalSize patch - v5

(Now with the right format)

Minimum patch file for fixing this bug on current SDL2 version (as of 29-March-2016), based on SetLogicalSize patch - v4.

It passed the example attached to this bug report and the issues I found during my developement.

Many thanks to the original author (Melker Narikka)!!!

Cheers
Roberto
Comment 13 Sam Lantinga 2017-08-14 05:50:41 UTC
Fixed, thanks!
https://hg.libsdl.org/SDL/rev/42b62c737891