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

add ability to load .dds, .tga, and .jpeg texture formats #1038

Merged
merged 3 commits into from
Dec 10, 2020

Conversation

blunted2night
Copy link
Contributor

controled by non-defaulted features of the same name

@Moxinilian Moxinilian added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen labels Dec 9, 2020
@cart
Copy link
Member

cart commented Dec 10, 2020

Two small notes:

  • In general I would prefer to not use macros in cases like this. It might involve a bit of extra code duplication, but it improves debuggability / legibility.
  • In this case I think the macro conversation isn't super important because this seems like the right call:
const FILE_EXTENSIONS: &[&str] = &["png", "dds", "tga", "jpg", "jpeg"];

impl AssetLoader for ImageTextureLoader {
    fn load<'a>(
        &'a self,
        bytes: &'a [u8],
        load_context: &'a mut LoadContext,
    ) -> BoxedFuture<'a, Result<()>> {
        Box::pin(async move {
            use bevy_core::AsBytes;

            // Find the image type we expect. A file with the extension "png" should
            // probably load as a PNG.

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

            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();

@blunted2night
Copy link
Contributor Author

That is much better, I updated the pull request.

@cart cart merged commit 9239621 into bevyengine:master Dec 10, 2020
@blunted2night blunted2night deleted the expanded-img-formats branch December 12, 2020 16:23
@fopsdev fopsdev mentioned this pull request Jan 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Feature A new feature, making something new possible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants