summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRay <[email protected]>2019-12-11 23:22:10 +0100
committerRay <[email protected]>2019-12-11 23:22:10 +0100
commite614942a2d52ea79c3a7f0fda4f0357035a6cc53 (patch)
treebb878862078195dbc1ca9c918ac427f15311bb3d
parent1397242d885b8ae65e61dfb025872029d7a671f2 (diff)
downloadraylib-e614942a2d52ea79c3a7f0fda4f0357035a6cc53.tar.gz
raylib-e614942a2d52ea79c3a7f0fda4f0357035a6cc53.zip
Read texture data as RGBA from FBO on GLES 2.0
-rw-r--r--src/rlgl.h12
-rw-r--r--src/textures.c11
2 files changed, 9 insertions, 14 deletions
diff --git a/src/rlgl.h b/src/rlgl.h
index 681db962..9a746873 100644
--- a/src/rlgl.h
+++ b/src/rlgl.h
@@ -2904,15 +2904,9 @@ void *rlReadTexturePixels(Texture2D texture)
// NOTE: Previoust attached texture is automatically detached
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture.id, 0);
- // Allocate enough memory to read back our texture data
- pixels = (unsigned char *)RL_MALLOC(GetPixelDataSize(texture.width, texture.height, texture.format));
-
- // Get OpenGL internal formats and data type from our texture format
- unsigned int glInternalFormat, glFormat, glType;
- rlGetGlTextureFormats(texture.format, &glInternalFormat, &glFormat, &glType);
-
- // NOTE: We read data as RGBA because FBO texture is configured as RGBA, despite binding a RGB texture...
- glReadPixels(0, 0, texture.width, texture.height, glFormat, glType, pixels);
+ // We read data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
+ pixels = (unsigned char *)RL_MALLOC(GetPixelDataSize(texture.width, texture.height, UNCOMPRESSED_R8G8B8A8));
+ glReadPixels(0, 0, texture.width, texture.height, UNCOMPRESSED_R8G8B8A8, GL_UNSIGNED_BYTE, pixels);
// Re-attach internal FBO color texture before deleting it
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, fbo.texture.id, 0);
diff --git a/src/textures.c b/src/textures.c
index ed6b8e6a..ba90c320 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -773,11 +773,12 @@ Image GetTextureData(Texture2D texture)
image.format = texture.format;
image.mipmaps = 1;
- // NOTE: Data retrieved on OpenGL ES 2.0 should be RGBA
- // coming from FBO color buffer, but it seems original
- // texture format is retrieved on RPI... weird...
- //image.format = UNCOMPRESSED_R8G8B8A8;
-
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ // NOTE: Data retrieved on OpenGL ES 2.0 should be RGBA,
+ // coming from FBO color buffer attachment, but it seems
+ // original texture format is retrieved on RPI...
+ image.format = UNCOMPRESSED_R8G8B8A8;
+#endif
TraceLog(LOG_INFO, "Texture pixel data obtained successfully");
}
else TraceLog(LOG_WARNING, "Texture pixel data could not be obtained");