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 1968 - SDL_RenderCopy stretch loses proportion on viewport boundaries
Summary: SDL_RenderCopy stretch loses proportion on viewport boundaries
Status: ASSIGNED
Alias: None
Product: SDL
Classification: Unclassified
Component: render (show other bugs)
Version: HG 2.0
Hardware: x86 Linux
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-13 07:51 UTC by driedfruit
Modified: 2013-08-01 12:17 UTC (History)
0 users

See Also:


Attachments
minimal test case (1.66 KB, text/plain)
2013-07-13 07:51 UTC, driedfruit
Details
proposed patch (1.19 KB, text/plain)
2013-07-13 08:38 UTC, driedfruit
Details

Note You need to log in before you can comment on or make changes to this bug.
Description driedfruit 2013-07-13 07:51:43 UTC
Created attachment 1225 [details]
minimal test case

SDL_RenderCopy clips dstrect against the viewport. Then it adjusts the
srcrect by "appropriate" amount of pixels. This amount is actually
wrong, quite a lot, because of the rounding errors introduced in the "*
factor / factor" scale.

            real_srcrect.x += (deltax * real_srcrect.w) / dstrect->w;
            real_srcrect.w += (deltaw * real_srcrect.w) / dstrect->w;

For example:

I have a 32 x 32 srcrect and a 64 x 64 dstrect. So far the
stretching is done perfectly, by a factor of 2.

Now, consider dstrect being clipped against the viewport, so it becomes
56 x 64. Now, the factor becomes 1.75 ! The adjustment to "srcrect"
can't handle this, cause srcrect is in integers. 

And thus we now have incorrect mapping, with dstrect not being in the
right proportion to srcrect.

The problem is most evident when upscaling stuff, like displaying a 8x8
texture with a zoom of 64 or more, and moving it beyond the corners of
the screen. It *looks* really really bad.

Note: RenderCopyEX does no such clipping, and is right to do so. The fix would be to remove any such clipping from RenderCopy too. And then fix the software renderer, because it has the same fault, independently of RenderCopy.
Comment 1 driedfruit 2013-07-13 08:38:11 UTC
Created attachment 1226 [details]
proposed patch

this leaves Software Renderer buggy, as it does it's own clipping later on
Comment 2 Sam Lantinga 2013-08-01 12:17:34 UTC
This patch is applied, which fixes it for the 3D renderers.
http://hg.libsdl.org/SDL/rev/c128ed448c30

I'm leaving this bug open for the software renderer to be fixed post 2.0 release.
You can reproduce it by taking the test case and running:
SDL_RENDER_DRIVER=software ./rect

Thanks!