mirror of
https://github.com/raysan5/raylib.git
synced 2026-07-10 15:51:56 -04:00
Compare commits
2 Commits
3973766b84
...
fa8aca8789
| Author | SHA1 | Date | |
|---|---|---|---|
| fa8aca8789 | |||
| efef4e31dd |
@ -3777,9 +3777,17 @@ void *rlReadTexturePixels(unsigned int id, int width, int height, int format)
|
||||
// Attach our texture to FBO
|
||||
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, id, 0);
|
||||
|
||||
#if defined(FBO_READ_TEXTURE_AS_RGBA)
|
||||
// Reading data as RGBA because FBO texture is configured as RGBA, despite binding another texture format
|
||||
pixels = RL_CALLOC(rlGetPixelDataSize(width, height, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8), 1);
|
||||
glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
|
||||
#else
|
||||
// Reading data as original texture format, in some platforms (RPI, Wasm) it works
|
||||
pixels = (unsigned char *)RL_MALLOC(GetPixelDataSize(width, height, format));
|
||||
unsigned int glInternalFormat = 0, glFormat = 0, glType = 0;
|
||||
rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType);
|
||||
glReadPixels(0, 0, width, height, glFormat, glType, pixels);
|
||||
#endif
|
||||
|
||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
|
||||
|
||||
@ -562,15 +562,18 @@ Image LoadImageFromTexture(Texture2D texture)
|
||||
{
|
||||
image.width = texture.width;
|
||||
image.height = texture.height;
|
||||
#if defined(FBO_READ_TEXTURE_AS_RGBA)
|
||||
// WARNING: On OpenGL ES 2.0/WebGL 1.0, there is no glGetTexImage() so,
|
||||
// texture data is retrieved by creating an RGBA fbo, binding the texture
|
||||
// to the fbo color attachment, and reading it as RGBA data with glReadPixels()
|
||||
// Returned data *should* be RGBA but it seems on some platforms (RPI, WASM)
|
||||
// original texture format is retrieved, so adding a define for this patch
|
||||
image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
#else
|
||||
image.format = texture.format;
|
||||
#endif
|
||||
image.mipmaps = 1;
|
||||
|
||||
#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 = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
|
||||
#endif
|
||||
TRACELOG(LOG_INFO, "TEXTURE: [ID %i] Pixel data retrieved successfully", texture.id);
|
||||
}
|
||||
else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to retrieve pixel data", texture.id);
|
||||
|
||||
Reference in New Issue
Block a user