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

mipmap levels can be 0 and they should be interpreted as 1 #11767

Merged
merged 10 commits into from
Feb 11, 2024
14 changes: 13 additions & 1 deletion crates/bevy_render/src/texture/dds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use wgpu::{
use super::{CompressedImageFormats, Image, TextureError};

pub fn dds_buffer_to_image(
#[cfg(debug_assertions)] name: String,
buffer: &[u8],
supported_compressed_formats: CompressedImageFormats,
is_srgb: bool,
Expand Down Expand Up @@ -45,7 +46,18 @@ pub fn dds_buffer_to_image(
depth_or_array_layers,
}
.physical_size(texture_format);
image.texture_descriptor.mip_level_count = dds.get_num_mipmap_levels();
let mip_map_level = match dds.get_num_mipmap_levels() {
0 => {
#[cfg(debug_assertions)]
warn_once!(
"Mipmap levels for texture {} are 0, bumping them to 1",
name
);
1
}
t => t,
};
image.texture_descriptor.mip_level_count = mip_map_level;
superdump marked this conversation as resolved.
Show resolved Hide resolved
image.texture_descriptor.format = texture_format;
image.texture_descriptor.dimension = if dds.get_depth() > 1 {
TextureDimension::D3
Expand Down
9 changes: 8 additions & 1 deletion crates/bevy_render/src/texture/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,7 @@ impl Image {
/// Load a bytes buffer in a [`Image`], according to type `image_type`, using the `image`
/// crate
pub fn from_buffer(
#[cfg(debug_assertions)] name: String,
buffer: &[u8],
image_type: ImageType,
#[allow(unused_variables)] supported_compressed_formats: CompressedImageFormats,
Expand All @@ -664,7 +665,13 @@ impl Image {
basis_buffer_to_image(buffer, supported_compressed_formats, is_srgb)?
}
#[cfg(feature = "dds")]
ImageFormat::Dds => dds_buffer_to_image(buffer, supported_compressed_formats, is_srgb)?,
ImageFormat::Dds => dds_buffer_to_image(
#[cfg(debug_assertions)]
name,
buffer,
supported_compressed_formats,
is_srgb,
)?,
#[cfg(feature = "ktx2")]
ImageFormat::Ktx2 => {
ktx2_buffer_to_image(buffer, supported_compressed_formats, is_srgb)?
Expand Down
2 changes: 2 additions & 0 deletions crates/bevy_render/src/texture/image_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ impl AssetLoader for ImageLoader {
ImageFormatSetting::Format(format) => ImageType::Format(format),
};
Ok(Image::from_buffer(
#[cfg(debug_assertions)]
load_context.path().display().to_string(),
&bytes,
image_type,
self.supported_compressed_formats,
Expand Down
Loading