diff --git a/Cargo.toml b/Cargo.toml index 0805c2890a..2bf46c8a7f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -55,6 +55,9 @@ wgpu_trace = ["bevy_internal/wgpu_trace"] # Image format support for texture loading (PNG and HDR are enabled by default) hdr = ["bevy_internal/hdr"] png = ["bevy_internal/png"] +dds = ["bevy_internal/dds"] +tga = ["bevy_internal/tga"] +jpeg = ["bevy_internal/jpeg"] # Audio format support (MP3 is enabled by default) flac = ["bevy_internal/flac"] diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 4475b06e80..49cd22cb77 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -21,6 +21,9 @@ trace_chrome = [ "bevy_log/tracing-chrome" ] # Image format support for texture loading (PNG and HDR are enabled by default) hdr = ["bevy_render/hdr"] png = ["bevy_render/png"] +dds = ["bevy_render/dds"] +tga = ["bevy_render/tga"] +jpeg = ["bevy_render/jpeg"] # Audio format support (MP3 is enabled by default) flac = ["bevy_audio/flac"] diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index 8528587e03..8732535ac2 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -53,3 +53,6 @@ shaderc = "0.7.0" [features] png = ["image/png"] hdr = ["image/hdr"] +dds = ["image/dds"] +tga = ["image/tga"] +jpeg = ["image/jpeg"] diff --git a/crates/bevy_render/src/texture/image_texture_loader.rs b/crates/bevy_render/src/texture/image_texture_loader.rs index ef0ed28eb7..f866a07518 100644 --- a/crates/bevy_render/src/texture/image_texture_loader.rs +++ b/crates/bevy_render/src/texture/image_texture_loader.rs @@ -9,6 +9,8 @@ use bevy_utils::BoxedFuture; #[derive(Clone, Default)] pub struct ImageTextureLoader; +const FILE_EXTENSIONS: &[&str] = &["png", "dds", "tga", "jpg", "jpeg"]; + impl AssetLoader for ImageTextureLoader { fn load<'a>( &'a self, @@ -23,16 +25,15 @@ impl AssetLoader for ImageTextureLoader { let ext = load_context.path().extension().unwrap().to_str().unwrap(); - // NOTE: If more formats are added they can be added here. - let img_format = if ext.eq_ignore_ascii_case("png") { - image::ImageFormat::Png - } else { - panic!( + let img_format = image::ImageFormat::from_extension(ext) + .ok_or_else(|| { + format!( "Unexpected image format {:?} for file {}, this is an error in `bevy_render`.", ext, load_context.path().display() ) - }; + }) + .unwrap(); // Load the image in the expected format. // Some formats like PNG allow for R or RG textures too, so the texture @@ -159,6 +160,6 @@ impl AssetLoader for ImageTextureLoader { } fn extensions(&self) -> &[&str] { - &["png"] + FILE_EXTENSIONS } }