From 95aa387cd04ff43637641b8afcd85d597d408549 Mon Sep 17 00:00:00 2001 From: KernelUwU Date: Tue, 28 Mar 2023 14:53:55 -0500 Subject: [PATCH] Added `WebP` image format support (#8220) # Objective WebP is a modern image format developed by Google that offers a significant reduction in file size compared to other image formats such as PNG and JPEG, while still maintaining good image quality. This makes it particularly useful for games with large numbers of images, such as those with high-quality textures or detailed sprites, where file size and loading times can have a significant impact on performance. By adding support for WebP images in Bevy, game developers using this engine can now take advantage of this modern image format and reduce the memory usage and loading times of their games. This improvement can ultimately result in a better gaming experience for players. In summary, the objective of adding WebP image format support in Bevy is to enable game developers to use a modern image format that provides better compression rates and smaller file sizes, resulting in faster loading times and reduced memory usage for their games. ## Solution To add support for WebP images in Bevy, this pull request leverages the existing `image` crate support for WebP. This implementation is easily integrated into the existing Bevy asset-loading system. To maintain compatibility with existing Bevy projects, WebP image support is disabled by default, and developers can enable it by adding a feature flag to their project's `Cargo.toml` file. With this feature, Bevy becomes even more versatile for game developers and provides a valuable addition to the game engine. --- ## Changelog - Added support for WebP image format in Bevy game engine ## Migration Guide To enable WebP image support in your Bevy project, add the following line to your project's Cargo.toml file: ```toml bevy = { version = "*", features = ["webp"]} ``` --- Cargo.toml | 3 +++ crates/bevy_internal/Cargo.toml | 1 + crates/bevy_render/Cargo.toml | 1 + crates/bevy_render/src/texture/image_texture_loader.rs | 2 ++ docs/cargo_features.md | 1 + 5 files changed, 8 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 10bd1c431e1cc..2cc66e61449f6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -132,6 +132,9 @@ jpeg = ["bevy_internal/jpeg"] # BMP image format support bmp = ["bevy_internal/bmp"] +# WebP image format support +webp = ["bevy_internal/webp"] + # Basis Universal compressed texture support basis-universal = ["bevy_internal/basis-universal"] diff --git a/crates/bevy_internal/Cargo.toml b/crates/bevy_internal/Cargo.toml index 8ad1c1a14fd08..75b30067a7728 100644 --- a/crates/bevy_internal/Cargo.toml +++ b/crates/bevy_internal/Cargo.toml @@ -32,6 +32,7 @@ png = ["bevy_render/png"] tga = ["bevy_render/tga"] jpeg = ["bevy_render/jpeg"] bmp = ["bevy_render/bmp"] +webp = ["bevy_render/webp"] basis-universal = ["bevy_render/basis-universal"] dds = ["bevy_render/dds"] ktx2 = ["bevy_render/ktx2"] diff --git a/crates/bevy_render/Cargo.toml b/crates/bevy_render/Cargo.toml index a42ef073b6231..e10f7f6da5841 100644 --- a/crates/bevy_render/Cargo.toml +++ b/crates/bevy_render/Cargo.toml @@ -15,6 +15,7 @@ hdr = ["image/hdr"] tga = ["image/tga"] jpeg = ["image/jpeg"] bmp = ["image/bmp"] +webp = ["image/webp"] dds = ["ddsfile"] # For ktx2 supercompression diff --git a/crates/bevy_render/src/texture/image_texture_loader.rs b/crates/bevy_render/src/texture/image_texture_loader.rs index 791161411506c..577f83626853f 100644 --- a/crates/bevy_render/src/texture/image_texture_loader.rs +++ b/crates/bevy_render/src/texture/image_texture_loader.rs @@ -34,6 +34,8 @@ const FILE_EXTENSIONS: &[&str] = &[ "jpeg", #[cfg(feature = "ktx2")] "ktx2", + #[cfg(feature = "webp")] + "webp", ]; impl AssetLoader for ImageTextureLoader { diff --git a/docs/cargo_features.md b/docs/cargo_features.md index aac27b3185381..af8961ffd68c8 100644 --- a/docs/cargo_features.md +++ b/docs/cargo_features.md @@ -68,5 +68,6 @@ The default feature set enables most of the expected features of a game engine, |trace_tracy|Tracing support, exposing a port for Tracy| |wav|WAV audio format support| |wayland|Wayland display server support| +|webp|WebP image format support| |wgpu_trace|Save a trace of all wgpu calls| |zlib|For KTX2 supercompression|