Skip to content

Commit 9239621

Browse files
add ability to load .dds, .tga, and .jpeg texture formats (#1038)
add ability to load `.dds`, `.tga`, and `.jpeg` texture formats
1 parent 4a5bccc commit 9239621

File tree

4 files changed

+17
-7
lines changed

4 files changed

+17
-7
lines changed

Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ wgpu_trace = ["bevy_internal/wgpu_trace"]
5555
# Image format support for texture loading (PNG and HDR are enabled by default)
5656
hdr = ["bevy_internal/hdr"]
5757
png = ["bevy_internal/png"]
58+
dds = ["bevy_internal/dds"]
59+
tga = ["bevy_internal/tga"]
60+
jpeg = ["bevy_internal/jpeg"]
5861

5962
# Audio format support (MP3 is enabled by default)
6063
flac = ["bevy_internal/flac"]

crates/bevy_internal/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ trace_chrome = [ "bevy_log/tracing-chrome" ]
2121
# Image format support for texture loading (PNG and HDR are enabled by default)
2222
hdr = ["bevy_render/hdr"]
2323
png = ["bevy_render/png"]
24+
dds = ["bevy_render/dds"]
25+
tga = ["bevy_render/tga"]
26+
jpeg = ["bevy_render/jpeg"]
2427

2528
# Audio format support (MP3 is enabled by default)
2629
flac = ["bevy_audio/flac"]

crates/bevy_render/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,6 @@ shaderc = "0.7.0"
5353
[features]
5454
png = ["image/png"]
5555
hdr = ["image/hdr"]
56+
dds = ["image/dds"]
57+
tga = ["image/tga"]
58+
jpeg = ["image/jpeg"]

crates/bevy_render/src/texture/image_texture_loader.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use bevy_utils::BoxedFuture;
99
#[derive(Clone, Default)]
1010
pub struct ImageTextureLoader;
1111

12+
const FILE_EXTENSIONS: &[&str] = &["png", "dds", "tga", "jpg", "jpeg"];
13+
1214
impl AssetLoader for ImageTextureLoader {
1315
fn load<'a>(
1416
&'a self,
@@ -23,16 +25,15 @@ impl AssetLoader for ImageTextureLoader {
2325

2426
let ext = load_context.path().extension().unwrap().to_str().unwrap();
2527

26-
// NOTE: If more formats are added they can be added here.
27-
let img_format = if ext.eq_ignore_ascii_case("png") {
28-
image::ImageFormat::Png
29-
} else {
30-
panic!(
28+
let img_format = image::ImageFormat::from_extension(ext)
29+
.ok_or_else(|| {
30+
format!(
3131
"Unexpected image format {:?} for file {}, this is an error in `bevy_render`.",
3232
ext,
3333
load_context.path().display()
3434
)
35-
};
35+
})
36+
.unwrap();
3637

3738
// Load the image in the expected format.
3839
// Some formats like PNG allow for R or RG textures too, so the texture
@@ -159,6 +160,6 @@ impl AssetLoader for ImageTextureLoader {
159160
}
160161

161162
fn extensions(&self) -> &[&str] {
162-
&["png"]
163+
FILE_EXTENSIONS
163164
}
164165
}

0 commit comments

Comments
 (0)