summaryrefslogtreecommitdiff
path: root/drivers/gles3
diff options
context:
space:
mode:
authorbinbitten <martinsjursen@gmail.com>2018-01-18 16:59:25 +0100
committerbinbitten <martinsjursen@gmail.com>2018-01-18 18:05:01 +0100
commit92473a9e9e0dd96352b7d323d286109c99287cf4 (patch)
tree516f8c25a7c01ccfa347eb2c4b0af24aece65a2a /drivers/gles3
parentd0d511b0f8d9cb4d48c861b2c097fa15876f432c (diff)
Convert special case RGB10_A2 to RGBA8 when obtaining texture data
Diffstat (limited to 'drivers/gles3')
-rw-r--r--drivers/gles3/rasterizer_storage_gles3.cpp25
1 files changed, 24 insertions, 1 deletions
diff --git a/drivers/gles3/rasterizer_storage_gles3.cpp b/drivers/gles3/rasterizer_storage_gles3.cpp
index ed7f3b24d0..71f475b655 100644
--- a/drivers/gles3/rasterizer_storage_gles3.cpp
+++ b/drivers/gles3/rasterizer_storage_gles3.cpp
@@ -876,11 +876,34 @@ Ref<Image> RasterizerStorageGLES3::texture_get_data(RID p_texture, VS::CubeMapSi
}
}
+ Image::Format img_format;
+
+ //convert special case RGB10_A2 to RGBA8 because it's not a supported image format
+ if (texture->gl_internal_format_cache == GL_RGB10_A2) {
+
+ img_format = Image::FORMAT_RGBA8;
+
+ uint32_t *ptr = (uint32_t *)wb.ptr();
+ uint32_t num_pixels = data_size / 4;
+
+ for (int ofs = 0; ofs < num_pixels; ofs++) {
+ uint32_t px = ptr[ofs];
+ uint32_t a = px >> 30 & 0xFF;
+
+ ptr[ofs] = (px >> 2 & 0xFF) |
+ (px >> 12 & 0xFF) << 8 |
+ (px >> 22 & 0xFF) << 16 |
+ (a | a << 2 | a << 4 | a << 6) << 24;
+ }
+ } else {
+ img_format = texture->format;
+ }
+
wb = PoolVector<uint8_t>::Write();
data.resize(data_size);
- Image *img = memnew(Image(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, texture->format, data));
+ Image *img = memnew(Image(texture->alloc_width, texture->alloc_height, texture->mipmaps > 1 ? true : false, img_format, data));
return Ref<Image>(img);
#else