mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
add ability to load .dds
, .tga
, and .jpeg
texture formats (#1038)
add ability to load `.dds`, `.tga`, and `.jpeg` texture formats
This commit is contained in:
parent
4a5bcccde2
commit
9239621ffc
4 changed files with 17 additions and 7 deletions
|
@ -55,6 +55,9 @@ wgpu_trace = ["bevy_internal/wgpu_trace"]
|
||||||
# Image format support for texture loading (PNG and HDR are enabled by default)
|
# Image format support for texture loading (PNG and HDR are enabled by default)
|
||||||
hdr = ["bevy_internal/hdr"]
|
hdr = ["bevy_internal/hdr"]
|
||||||
png = ["bevy_internal/png"]
|
png = ["bevy_internal/png"]
|
||||||
|
dds = ["bevy_internal/dds"]
|
||||||
|
tga = ["bevy_internal/tga"]
|
||||||
|
jpeg = ["bevy_internal/jpeg"]
|
||||||
|
|
||||||
# Audio format support (MP3 is enabled by default)
|
# Audio format support (MP3 is enabled by default)
|
||||||
flac = ["bevy_internal/flac"]
|
flac = ["bevy_internal/flac"]
|
||||||
|
|
|
@ -21,6 +21,9 @@ trace_chrome = [ "bevy_log/tracing-chrome" ]
|
||||||
# Image format support for texture loading (PNG and HDR are enabled by default)
|
# Image format support for texture loading (PNG and HDR are enabled by default)
|
||||||
hdr = ["bevy_render/hdr"]
|
hdr = ["bevy_render/hdr"]
|
||||||
png = ["bevy_render/png"]
|
png = ["bevy_render/png"]
|
||||||
|
dds = ["bevy_render/dds"]
|
||||||
|
tga = ["bevy_render/tga"]
|
||||||
|
jpeg = ["bevy_render/jpeg"]
|
||||||
|
|
||||||
# Audio format support (MP3 is enabled by default)
|
# Audio format support (MP3 is enabled by default)
|
||||||
flac = ["bevy_audio/flac"]
|
flac = ["bevy_audio/flac"]
|
||||||
|
|
|
@ -53,3 +53,6 @@ shaderc = "0.7.0"
|
||||||
[features]
|
[features]
|
||||||
png = ["image/png"]
|
png = ["image/png"]
|
||||||
hdr = ["image/hdr"]
|
hdr = ["image/hdr"]
|
||||||
|
dds = ["image/dds"]
|
||||||
|
tga = ["image/tga"]
|
||||||
|
jpeg = ["image/jpeg"]
|
||||||
|
|
|
@ -9,6 +9,8 @@ use bevy_utils::BoxedFuture;
|
||||||
#[derive(Clone, Default)]
|
#[derive(Clone, Default)]
|
||||||
pub struct ImageTextureLoader;
|
pub struct ImageTextureLoader;
|
||||||
|
|
||||||
|
const FILE_EXTENSIONS: &[&str] = &["png", "dds", "tga", "jpg", "jpeg"];
|
||||||
|
|
||||||
impl AssetLoader for ImageTextureLoader {
|
impl AssetLoader for ImageTextureLoader {
|
||||||
fn load<'a>(
|
fn load<'a>(
|
||||||
&'a self,
|
&'a self,
|
||||||
|
@ -23,16 +25,15 @@ impl AssetLoader for ImageTextureLoader {
|
||||||
|
|
||||||
let ext = load_context.path().extension().unwrap().to_str().unwrap();
|
let ext = load_context.path().extension().unwrap().to_str().unwrap();
|
||||||
|
|
||||||
// NOTE: If more formats are added they can be added here.
|
let img_format = image::ImageFormat::from_extension(ext)
|
||||||
let img_format = if ext.eq_ignore_ascii_case("png") {
|
.ok_or_else(|| {
|
||||||
image::ImageFormat::Png
|
format!(
|
||||||
} else {
|
|
||||||
panic!(
|
|
||||||
"Unexpected image format {:?} for file {}, this is an error in `bevy_render`.",
|
"Unexpected image format {:?} for file {}, this is an error in `bevy_render`.",
|
||||||
ext,
|
ext,
|
||||||
load_context.path().display()
|
load_context.path().display()
|
||||||
)
|
)
|
||||||
};
|
})
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// Load the image in the expected format.
|
// Load the image in the expected format.
|
||||||
// Some formats like PNG allow for R or RG textures too, so the texture
|
// 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] {
|
fn extensions(&self) -> &[&str] {
|
||||||
&["png"]
|
FILE_EXTENSIONS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue