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 1810 - xxx_RenderReadPixels - incorrect behaviour in certain conditions
Summary: xxx_RenderReadPixels - incorrect behaviour in certain conditions
Status: RESOLVED FIXED
Alias: None
Product: SDL
Classification: Unclassified
Component: video (show other bugs)
Version: HG 2.0
Hardware: All Other
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-18 02:35 UTC by PoopiSan
Modified: 2013-07-12 03:55 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description PoopiSan 2013-04-18 02:35:32 UTC
GLES2_RenderReadPixels, GLES_RenderReadPixels, GL_RenderReadPixels and possibly other backends is incorrectly implemented.

If the current target viewport is different than window size the function is reading garbage and according to the function documentation should work with any rendering target "Read pixels from the current rendering target.".

this seems to be caused by this line:

...
SDL_GetWindowSize(window, &w, &h);
...

quick fix and change to 


if(renderer->target == NULL)
{
  SDL_GetWindowSize(window, &w, &h);
}
else
{
  w=rect->w;h=rect->h;
}

seem to solve my case ( viewport is equal to texture size, no scaling ).

After this change all textures are read correctly. This function is very useful for texture rendering debugging.
Comment 1 Sam Lantinga 2013-07-12 02:41:36 UTC
Can you double check this in the current snapshot?
http://www.libsdl.org/tmp/SDL-2.0.zip

I think this was fixed at some point, since the viewport is actually used now:
    real_rect.x = renderer->viewport.x;
    real_rect.y = renderer->viewport.y;
    real_rect.w = renderer->viewport.w;
    real_rect.h = renderer->viewport.h;
Comment 2 Sam Lantinga 2013-07-12 03:55:50 UTC
Actually, I just ran into this bug myself and fixed it.  Thanks!
http://hg.libsdl.org/SDL/rev/fe82b639c4d6