Skip to content

Commit

Permalink
Use as_image_copy where possible (#10733)
Browse files Browse the repository at this point in the history
# Objective

`wgpu` has a helper method `texture.as_image_copy()` for a common
pattern when making a default-like `ImageCopyTexture` from a texture.

This is used in various places in Bevy for texture copy operations, but
it was not used where `write_texture` is called.

## Solution

- Replace struct `ImageCopyTexture` initialization with
`texture.as_image_copy()` where appropriate

Signed-off-by: Torstein Grindvik <torstein.grindvik@muybridge.com>
Co-authored-by: Torstein Grindvik <torstein.grindvik@muybridge.com>
  • Loading branch information
torsteingrindvik and Torstein Grindvik authored Nov 26, 2023
1 parent 89d652b commit 4788315
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 18 deletions.
7 changes: 1 addition & 6 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,7 @@ impl FromWorld for MeshPipeline {

let format_size = image.texture_descriptor.format.pixel_size();
render_queue.write_texture(
ImageCopyTexture {
texture: &texture,
mip_level: 0,
origin: Origin3d::ZERO,
aspect: TextureAspect::All,
},
texture.as_image_copy(),
&image.data,
ImageDataLayout {
offset: 0,
Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_sprite/src/mesh2d/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,7 @@ impl FromWorld for Mesh2dPipeline {

let format_size = image.texture_descriptor.format.pixel_size();
render_queue.write_texture(
ImageCopyTexture {
texture: &texture,
mip_level: 0,
origin: Origin3d::ZERO,
aspect: TextureAspect::All,
},
texture.as_image_copy(),
&image.data,
ImageDataLayout {
offset: 0,
Expand Down
7 changes: 1 addition & 6 deletions crates/bevy_sprite/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,7 @@ impl FromWorld for SpritePipeline {

let format_size = image.texture_descriptor.format.pixel_size();
render_queue.write_texture(
ImageCopyTexture {
texture: &texture,
mip_level: 0,
origin: Origin3d::ZERO,
aspect: TextureAspect::All,
},
texture.as_image_copy(),
&image.data,
ImageDataLayout {
offset: 0,
Expand Down

0 comments on commit 4788315

Please sign in to comment.