bevyengine / bevyengine/bevy

Configure image attributes using ImageLoaderSettings

Open
#11,200 5 comments 0 reactions 0 assignees View on GitHub
A-Assets C-Feature C-Usability D-Complex S-Needs-Design
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## What problem does this solve or what need does it fill?

When loading images/textures for my projects I have encountered the need to change some attributes of the image descriptor, like the format, the dimensions, etc.
To do this, I currently have to poll for the image to be loaded, then change the properties and mark the image as fully loaded somewhere.

This looks currently something like this:

```rust
#[derive(Resource)]
struct LoadingTexture {
is_loaded: bool,
gradient: Handle,
}

fn setup(...) {
let gradient = asset_server.load("textures/gradient.png");
commands.insert_resource(LoadingTexture {
is_loaded: false,
gradient: gradient.clone(),
});
}

fn create_array_texture(...) {
if loading_texture.is_loaded
|| asset_server.load_state(loading_texture.gradient.clone()) != LoadState::Loaded
{
return;
}

loading_texture.is_loaded = true;

let image = images.get_mut(&loading_texture.gradient).unwrap();
image.texture_descriptor.dimension = TextureDimension::D1;
}
```

## What solution would you like?

The current approach is very cumbersome and verbose.
It would be way nicer to configure the optional parameters through the `ImageLoaderSettings`.
It is already possible to define the image sampler in this way.

I would propose, that we extend these settings to be able to select the `TextureDescriptor` properties as well.

Since we may only want to override some properties at a time, we can not specify the texture descriptor directly.

A better API would be to add optional fields to the image loader settings, for format, size, dimension, etc.

Alternatively, we could store this configuration in a separate struct named TextureSettings, or similar.

Before making a PR I would like to get your feedback on the implementation of the feature.

Let me know whether you prefer to configure all properties in the ImageLoaderSettings directly, or rather like to have a separate struct.

A possible example would look like this:

```rust
fn setup(...) {
let gradient = asset_server.load_with_Settings(
"textures/gradient.png",
ImageLoaderSettings {
dimension: Some(TextureDimension::D1),
..default()
},
);
}
```

## What alternative(s) have you considered?

Keep things as they are?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.