Skip to content

Add new ImageLoaderSettings member for loading as stacked 2d array#20536

Closed
KirmesBude wants to merge 4 commits into
bevyengine:mainfrom
KirmesBude:feature/image-loader-2d-array
Closed

Add new ImageLoaderSettings member for loading as stacked 2d array#20536
KirmesBude wants to merge 4 commits into
bevyengine:mainfrom
KirmesBude:feature/image-loader-2d-array

Conversation

@KirmesBude

@KirmesBude KirmesBude commented Aug 12, 2025

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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).

Comment thread crates/bevy_image/src/image_loader.rs Outdated
})?;

if let Some(layers) = settings.layers {
image.reinterpret_stacked_2d_as_array(layers.into());

Copy link
Copy Markdown
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
Copy Markdown
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 :)

github-merge-queue Bot pushed a commit that referenced this pull request Oct 6, 2025
…w return a Result (#20797)

# Objective

Remove panics from image reinterpretation methods.

## Solution

Introduce new errors and emit those instead of panicking.

## Testing

- Did you test these changes? If so, how?
  - CI + changed examples
- Are there any parts that need more testing?
  - No
- How can other people (reviewers) test your changes? Is there anything
specific they need to know?
  - examples, no
- 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

---

Moved out of #20536

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
@KirmesBude KirmesBude closed this Oct 6, 2025
tigregalis pushed a commit to tigregalis/bevy that referenced this pull request Oct 7, 2025
…w return a Result (bevyengine#20797)

# Objective

Remove panics from image reinterpretation methods.

## Solution

Introduce new errors and emit those instead of panicking.

## Testing

- Did you test these changes? If so, how?
  - CI + changed examples
- Are there any parts that need more testing?
  - No
- How can other people (reviewers) test your changes? Is there anything
specific they need to know?
  - examples, no
- 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

---

Moved out of bevyengine#20536

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
mate-h pushed a commit to mate-h/bevy that referenced this pull request Oct 22, 2025
…w return a Result (bevyengine#20797)

# Objective

Remove panics from image reinterpretation methods.

## Solution

Introduce new errors and emit those instead of panicking.

## Testing

- Did you test these changes? If so, how?
  - CI + changed examples
- Are there any parts that need more testing?
  - No
- How can other people (reviewers) test your changes? Is there anything
specific they need to know?
  - examples, no
- 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

---

Moved out of bevyengine#20536

---------

Co-authored-by: Alice Cecile <alice.i.cecile@gmail.com>
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

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

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

2 participants