Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editor: Fix AtlasTexture editor previews for compressed textures #102559

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions editor/plugins/editor_preview_plugins.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ Ref<Texture2D> EditorTexturePreviewPlugin::generate(const Ref<Resource> &p_from,
return Ref<Texture2D>();
}

if (atlas->is_compressed()) {
atlas = atlas->duplicate();
if (atlas->decompress() != OK) {
return Ref<Texture2D>();
}
}

if (!tex_atlas->get_region().has_area()) {
return Ref<Texture2D>();
}
Expand Down
15 changes: 14 additions & 1 deletion editor/plugins/texture_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,21 @@ static Image::Format get_texture_2d_format(const Ref<Texture2D> &p_texture) {

static int get_texture_mipmaps_count(const Ref<Texture2D> &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> image = p_texture->get_image();
Ref<Image> image;
Ref<AtlasTexture> 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<Texture2D> 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();
}
Expand Down