From 061cc5e75f7f24ff7cc24707eb8563a4142d5ce7 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Sat, 1 Oct 2016 11:38:53 -0700 Subject: [PATCH] Fixed bug 3349 - GLES2_RenderReadPixels doesn't use target texture format Simon Hug The OpenGL ES 2 renderer does not check the target texture format when using SDL_RenderReadPixels and just always uses ABGR8888. This can result in swapped or wrong colors. The attached patch adds a check and selects the target texture format, if a texture is set as the target. --- src/render/opengl/SDL_render_gl.c | 2 +- src/render/opengles/SDL_render_gles.c | 2 +- src/render/opengles2/SDL_render_gles2.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c index 971b3175d..7c6f80d44 100644 --- a/src/render/opengl/SDL_render_gl.c +++ b/src/render/opengl/SDL_render_gl.c @@ -1414,7 +1414,7 @@ GL_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 pixel_format, void * pixels, int pitch) { GL_RenderData *data = (GL_RenderData *) renderer->driverdata; - Uint32 temp_format = SDL_PIXELFORMAT_ARGB8888; + Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888; void *temp_pixels; int temp_pitch; GLint internalFormat; diff --git a/src/render/opengles/SDL_render_gles.c b/src/render/opengles/SDL_render_gles.c index 9d13bfe1f..9b725970d 100644 --- a/src/render/opengles/SDL_render_gles.c +++ b/src/render/opengles/SDL_render_gles.c @@ -1069,7 +1069,7 @@ GLES_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 pixel_format, void * pixels, int pitch) { GLES_RenderData *data = (GLES_RenderData *) renderer->driverdata; - Uint32 temp_format = SDL_PIXELFORMAT_ABGR8888; + Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888; void *temp_pixels; int temp_pitch; Uint8 *src, *dst, *tmp; diff --git a/src/render/opengles2/SDL_render_gles2.c b/src/render/opengles2/SDL_render_gles2.c index 7ff22b4ba..edefa6415 100644 --- a/src/render/opengles2/SDL_render_gles2.c +++ b/src/render/opengles2/SDL_render_gles2.c @@ -1817,7 +1817,7 @@ GLES2_RenderReadPixels(SDL_Renderer * renderer, const SDL_Rect * rect, Uint32 pixel_format, void * pixels, int pitch) { GLES2_DriverContext *data = (GLES2_DriverContext *)renderer->driverdata; - Uint32 temp_format = SDL_PIXELFORMAT_ABGR8888; + Uint32 temp_format = renderer->target ? renderer->target->format : SDL_PIXELFORMAT_ABGR8888; void *temp_pixels; int temp_pitch; Uint8 *src, *dst, *tmp;