From 3084ed4bffc41600727dc509569ac2c619fb20af Mon Sep 17 00:00:00 2001 From: Stuart Carnie Date: Sat, 8 Feb 2025 08:11:35 +1100 Subject: [PATCH] editor: Fix AtlasTexture editor previews for compressed textures --- editor/plugins/editor_preview_plugins.cpp | 7 +++++++ editor/plugins/texture_editor_plugin.cpp | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index 0f7af27d072e..5b003f53e9b0 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -100,6 +100,13 @@ Ref EditorTexturePreviewPlugin::generate(const Ref &p_from, return Ref(); } + if (atlas->is_compressed()) { + atlas = atlas->duplicate(); + if (atlas->decompress() != OK) { + return Ref(); + } + } + if (!tex_atlas->get_region().has_area()) { return Ref(); } diff --git a/editor/plugins/texture_editor_plugin.cpp b/editor/plugins/texture_editor_plugin.cpp index 561146be4259..fcda832c9111 100644 --- a/editor/plugins/texture_editor_plugin.cpp +++ b/editor/plugins/texture_editor_plugin.cpp @@ -132,8 +132,21 @@ static Image::Format get_texture_2d_format(const Ref &p_texture) { static int get_texture_mipmaps_count(const Ref &p_texture) { ERR_FAIL_COND_V(p_texture.is_null(), -1); + // We are having to download the image only to get its mipmaps count. It would be nice if we didn't have to. - Ref image = p_texture->get_image(); + Ref image; + Ref at = p_texture; + if (at.is_valid()) { + // The AtlasTexture tries to obtain the region from the atlas as an image, + // which will fail if it is a compressed format. + Ref atlas = at->get_atlas(); + if (atlas.is_valid()) { + image = atlas->get_image(); + } + } else { + image = p_texture->get_image(); + } + if (image.is_valid()) { return image->get_mipmap_count(); }