mirror of
https://github.com/bevyengine/bevy
synced 2025-02-16 22:18:33 +00:00
Remove unnecessary alternate create_texture path in prepare_asset for Image (#6671)
# Objective `prepare_asset` for Image has an alternate path for texture creation that is used when the image is not compressed and does not contain mipmaps. This additional code path is unnecessary as `render_device.create_texture_with_data()` will handle both cases correctly. ## Solution Use `render_device.create_texture_with_data()` in all cases. Tested successfully with the following examples: - load_gltf - render_to_texture - texture - 3d_shapes - sprite - sprite_sheet - array_texture - shader_material_screenspace_texture - skybox (though this already would use the `create_texture_with_data()` branch anyway)
This commit is contained in:
parent
e621acd7f2
commit
f9ad051e61
1 changed files with 6 additions and 39 deletions
|
@ -18,10 +18,7 @@ use bevy_math::Vec2;
|
|||
use bevy_reflect::{FromReflect, Reflect, TypeUuid};
|
||||
use std::hash::Hash;
|
||||
use thiserror::Error;
|
||||
use wgpu::{
|
||||
Extent3d, ImageCopyTexture, ImageDataLayout, Origin3d, TextureDimension, TextureFormat,
|
||||
TextureViewDescriptor,
|
||||
};
|
||||
use wgpu::{Extent3d, TextureDimension, TextureFormat, TextureViewDescriptor};
|
||||
|
||||
pub const TEXTURE_ASSET_INDEX: u64 = 0;
|
||||
pub const SAMPLER_ASSET_INDEX: u64 = 1;
|
||||
|
@ -629,41 +626,11 @@ impl RenderAsset for Image {
|
|||
image: Self::ExtractedAsset,
|
||||
(render_device, render_queue, default_sampler): &mut SystemParamItem<Self::Param>,
|
||||
) -> Result<Self::PreparedAsset, PrepareAssetError<Self::ExtractedAsset>> {
|
||||
let texture = if image.texture_descriptor.mip_level_count > 1 || image.is_compressed() {
|
||||
render_device.create_texture_with_data(
|
||||
render_queue,
|
||||
&image.texture_descriptor,
|
||||
&image.data,
|
||||
)
|
||||
} else {
|
||||
let texture = render_device.create_texture(&image.texture_descriptor);
|
||||
let format_size = image.texture_descriptor.format.pixel_size();
|
||||
render_queue.write_texture(
|
||||
ImageCopyTexture {
|
||||
texture: &texture,
|
||||
mip_level: 0,
|
||||
origin: Origin3d::ZERO,
|
||||
aspect: wgpu::TextureAspect::All,
|
||||
},
|
||||
&image.data,
|
||||
ImageDataLayout {
|
||||
offset: 0,
|
||||
bytes_per_row: Some(
|
||||
std::num::NonZeroU32::new(
|
||||
image.texture_descriptor.size.width * format_size as u32,
|
||||
)
|
||||
.unwrap(),
|
||||
),
|
||||
rows_per_image: if image.texture_descriptor.size.depth_or_array_layers > 1 {
|
||||
std::num::NonZeroU32::new(image.texture_descriptor.size.height)
|
||||
} else {
|
||||
None
|
||||
},
|
||||
},
|
||||
image.texture_descriptor.size,
|
||||
);
|
||||
texture
|
||||
};
|
||||
let texture = render_device.create_texture_with_data(
|
||||
render_queue,
|
||||
&image.texture_descriptor,
|
||||
&image.data,
|
||||
);
|
||||
|
||||
let texture_view = texture.create_view(
|
||||
image
|
||||
|
|
Loading…
Add table
Reference in a new issue