Skip to content

Commit 03d648c

Browse files
committed
Merge pull request #92344 from fire/vsk-3d-texture-alpha-4.3
Fix Texture3D import not working
2 parents d4f14aa + 06a7b11 commit 03d648c

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

scene/resources/compressed_texture.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,6 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
310310
Vector<Ref<Image>> mipmap_images;
311311
uint64_t total_size = 0;
312312

313-
bool first = true;
314-
315313
for (uint32_t i = 0; i < mipmaps + 1; i++) {
316314
uint32_t size = f->get_32();
317315

@@ -340,14 +338,17 @@ Ref<Image> CompressedTexture2D::load_image_from_file(Ref<FileAccess> f, int p_si
340338
if (img.is_null() || img->is_empty()) {
341339
ERR_FAIL_COND_V(img.is_null() || img->is_empty(), Ref<Image>());
342340
}
343-
344-
if (first) {
345-
//format will actually be the format of the first image,
346-
//as it may have changed on compression
347-
format = img->get_format();
348-
first = false;
349-
} else if (img->get_format() != format) {
350-
img->convert(format); //all needs to be the same format
341+
// If the image is compressed and its format doesn't match the desired format, return an empty reference.
342+
// This is done to avoid recompressing the image on load.
343+
ERR_FAIL_COND_V(img->is_compressed() && format != img->get_format(), Ref<Image>());
344+
345+
// The format will actually be the format of the header,
346+
// as it may have changed on compression.
347+
if (format != img->get_format()) {
348+
// Convert the image to the desired format.
349+
// Note: We are not decompressing the image here, just changing its format.
350+
// It's important that all images in the texture array share the same format for correct rendering.
351+
img->convert(format);
351352
}
352353

353354
total_size += img->get_data().size();

0 commit comments

Comments
 (0)