Skip to content

Conversation

KirmesBude
Copy link
Contributor

@KirmesBude KirmesBude commented Aug 12, 2025

Objective

Loading images for use as texture 2d array is tedious and should be supported in the context of loading the asset.
Partially fixes #17145

Solution

Add a new layers member to ImageLoaderSettings which determines if and how we call reinterpret_stacked_2d_as_array during asset loading.

Testing

  • Did you test these changes? If so, how?
    • I ran ci locally and simplified and ran the current texture 2d array example
  • Are there any parts that need more testing?
    • I do not think so
  • How can other people (reviewers) test your changes? Is there anything specific they need to know?
    • Run array_texture example
  • If relevant, what platforms did you test these changes on, and are there any important ones you can't test?
    • linux, amd cpu, amd gpu

Showcase

I believe the changes in examples/shader/array_texture.rs show quite well how this is nicer to work with.

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use X-Uncontroversial This work is generally agreed upon D-Straightforward Simple bug fixes and API improvements, docs, test and examples labels Aug 12, 2025
@alice-i-cecile alice-i-cecile added the S-Needs-Review Needs reviewer attention (from anyone!) to move forward label Aug 12, 2025
@alice-i-cecile
Copy link
Member

Very nice!

@KirmesBude KirmesBude force-pushed the feature/image-loader-2d-array branch from abe31c6 to 13a4d42 Compare August 14, 2025 17:45
@KirmesBude
Copy link
Contributor Author

I also changed the tilemap example. I see one use of reinterpret_stacked_2d_as_array in the skybox example. Maybe it is better to use something like TextureViewDimension as suggested in the issue to also cover the cubemap case (and possibly more).

})?;

if let Some(layers) = settings.layers {
image.reinterpret_stacked_2d_as_array(layers.into());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized this actually panics. So I want to change this so it returns a Result, but I am not sure if I should keep the panicing version? Is there any benefit to it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please swap it to return a Result. Panicking APIs are only worth it when the operation is extremely common and the panics are extremely rare. Neither is the case here :)

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-Usability A targeted quality-of-life change that makes Bevy easier to use D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Uncontroversial This work is generally agreed upon
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Allow users to provide image dimensions type/layers count in ImageLoaderSettings
2 participants