diff options
| author | Ray <[email protected]> | 2021-06-28 09:39:31 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2021-06-28 09:39:31 +0200 |
| commit | e5cf3f9555bc8b0d6e379c4fae95358049a1b37c (patch) | |
| tree | a0a3da3d23e4c9124c4aa703513552d073a83c11 /src/textures.c | |
| parent | 5f03201616e32b04d969e8c4f2918f17df5447b6 (diff) | |
| download | raylib-e5cf3f9555bc8b0d6e379c4fae95358049a1b37c.tar.gz raylib-e5cf3f9555bc8b0d6e379c4fae95358049a1b37c.zip | |
WARNING: BREAKING: Functions renamed for consistency
RENAMED: GetTextureData() -> LoadImageFromTexture()
RENAMED: GetScreenData() -> LoadImageFromScreen()
Diffstat (limited to 'src/textures.c')
| -rw-r--r-- | src/textures.c | 92 |
1 files changed, 46 insertions, 46 deletions
diff --git a/src/textures.c b/src/textures.c index 7d1057fb..9cc997ed 100644 --- a/src/textures.c +++ b/src/textures.c @@ -385,6 +385,52 @@ Image LoadImageFromMemory(const char *fileType, const unsigned char *fileData, i return image; } +// Load image from GPU texture data +// NOTE: Compressed texture formats not supported +Image LoadImageFromTexture(Texture2D texture) +{ + Image image = { 0 }; + + if (texture.format < PIXELFORMAT_COMPRESSED_DXT1_RGB) + { + image.data = rlReadTexturePixels(texture); + + if (image.data != NULL) + { + image.width = texture.width; + image.height = texture.height; + image.format = texture.format; + 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); + } + else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to retrieve compressed pixel data", texture.id); + + return image; +} + +// Load image from screen buffer and (screenshot) +Image LoadImageFromScreen(void) +{ + Image image = { 0 }; + + image.width = GetScreenWidth(); + image.height = GetScreenHeight(); + image.mipmaps = 1; + image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; + image.data = rlReadScreenPixels(image.width, image.height); + + return image; +} + // Unload image from CPU memory (RAM) void UnloadImage(Image image) { @@ -2804,52 +2850,6 @@ void UpdateTextureRec(Texture2D texture, Rectangle rec, const void *pixels) rlUpdateTexture(texture.id, (int)rec.x, (int)rec.y, (int)rec.width, (int)rec.height, texture.format, pixels); } -// Get pixel data from GPU texture and return an Image -// NOTE: Compressed texture formats not supported -Image GetTextureData(Texture2D texture) -{ - Image image = { 0 }; - - if (texture.format < PIXELFORMAT_COMPRESSED_DXT1_RGB) - { - image.data = rlReadTexturePixels(texture); - - if (image.data != NULL) - { - image.width = texture.width; - image.height = texture.height; - image.format = texture.format; - 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); - } - else TRACELOG(LOG_WARNING, "TEXTURE: [ID %i] Failed to retrieve compressed pixel data", texture.id); - - return image; -} - -// Get pixel data from GPU frontbuffer and return an Image (screenshot) -Image GetScreenData(void) -{ - Image image = { 0 }; - - image.width = GetScreenWidth(); - image.height = GetScreenHeight(); - image.mipmaps = 1; - image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; - image.data = rlReadScreenPixels(image.width, image.height); - - return image; -} - //------------------------------------------------------------------------------------ // Texture configuration functions //------------------------------------------------------------------------------------ |
