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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
diff --git a/src/render/opengl/SDL_render_gl.c b/src/render/opengl/SDL_render_gl.c
index 971b317..7c6f80d 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 9d13bfe..9b72597 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 7ff22b4..edefa64 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;