mirror of https://github.com/encounter/SDL.git
Fixed bug 3350 - GL renderers don't need to flip rows after reading back pixels from the target texture
Simon Hug All OpenGL renderers always flip the rows of the pixels that come from glReadPixels. This is unnecessary for target textures since these are already top down. Also, the rect->y value can be used directly for target textures for the same reason. I don't see any code that would handle the logical render size for target textures. Or am I missing something? The attached patch makes the renderers only the flip rows if the data comes from the default framebuffer.
This commit is contained in:
parent
9fff05f8d6
commit
51d6371ec1
|
@ -1439,15 +1439,16 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
data->glPixelStorei(GL_PACK_ROW_LENGTH,
|
data->glPixelStorei(GL_PACK_ROW_LENGTH,
|
||||||
(temp_pitch / SDL_BYTESPERPIXEL(temp_format)));
|
(temp_pitch / SDL_BYTESPERPIXEL(temp_format)));
|
||||||
|
|
||||||
data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
|
data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
|
||||||
format, type, temp_pixels);
|
rect->w, rect->h, format, type, temp_pixels);
|
||||||
|
|
||||||
if (GL_CheckError("glReadPixels()", renderer) < 0) {
|
if (GL_CheckError("glReadPixels()", renderer) < 0) {
|
||||||
SDL_free(temp_pixels);
|
SDL_free(temp_pixels);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flip the rows to be top-down */
|
/* Flip the rows to be top-down if necessary */
|
||||||
|
if (!renderer->target) {
|
||||||
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||||
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
||||||
dst = (Uint8*)temp_pixels;
|
dst = (Uint8*)temp_pixels;
|
||||||
|
@ -1461,6 +1462,7 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
src -= temp_pitch;
|
src -= temp_pitch;
|
||||||
}
|
}
|
||||||
SDL_stack_free(tmp);
|
SDL_stack_free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
status = SDL_ConvertPixels(rect->w, rect->h,
|
status = SDL_ConvertPixels(rect->w, rect->h,
|
||||||
temp_format, temp_pixels, temp_pitch,
|
temp_format, temp_pixels, temp_pitch,
|
||||||
|
|
|
@ -1088,10 +1088,11 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
|
|
||||||
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
data->glPixelStorei(GL_PACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
|
data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
|
rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
|
||||||
|
|
||||||
/* Flip the rows to be top-down */
|
/* Flip the rows to be top-down if necessary */
|
||||||
|
if (!renderer->target) {
|
||||||
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||||
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
||||||
dst = (Uint8*)temp_pixels;
|
dst = (Uint8*)temp_pixels;
|
||||||
|
@ -1105,6 +1106,7 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
src -= temp_pitch;
|
src -= temp_pitch;
|
||||||
}
|
}
|
||||||
SDL_stack_free(tmp);
|
SDL_stack_free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
status = SDL_ConvertPixels(rect->w, rect->h,
|
status = SDL_ConvertPixels(rect->w, rect->h,
|
||||||
temp_format, temp_pixels, temp_pitch,
|
temp_format, temp_pixels, temp_pitch,
|
||||||
|
|
|
@ -1834,13 +1834,14 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
|
|
||||||
SDL_GetRendererOutputSize(renderer, &w, &h);
|
SDL_GetRendererOutputSize(renderer, &w, &h);
|
||||||
|
|
||||||
data->glReadPixels(rect->x, (h-rect->y)-rect->h, rect->w, rect->h,
|
data->glReadPixels(rect->x, renderer->target ? rect->y : (h-rect->y)-rect->h,
|
||||||
GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
|
rect->w, rect->h, GL_RGBA, GL_UNSIGNED_BYTE, temp_pixels);
|
||||||
if (GL_CheckError("glReadPixels()", renderer) < 0) {
|
if (GL_CheckError("glReadPixels()", renderer) < 0) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Flip the rows to be top-down */
|
/* Flip the rows to be top-down if necessary */
|
||||||
|
if (!renderer->target) {
|
||||||
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
length = rect->w * SDL_BYTESPERPIXEL(temp_format);
|
||||||
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
src = (Uint8*)temp_pixels + (rect->h-1)*temp_pitch;
|
||||||
dst = (Uint8*)temp_pixels;
|
dst = (Uint8*)temp_pixels;
|
||||||
|
@ -1854,6 +1855,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect,
|
||||||
src -= temp_pitch;
|
src -= temp_pitch;
|
||||||
}
|
}
|
||||||
SDL_stack_free(tmp);
|
SDL_stack_free(tmp);
|
||||||
|
}
|
||||||
|
|
||||||
status = SDL_ConvertPixels(rect->w, rect->h,
|
status = SDL_ConvertPixels(rect->w, rect->h,
|
||||||
temp_format, temp_pixels, temp_pitch,
|
temp_format, temp_pixels, temp_pitch,
|
||||||
|
|
Loading…
Reference in New Issue