Open
Description
What problem does this solve or what need does it fill?
We have lots of code such as this:
bevy/examples/ui/viewport_node.rs
Line 49 in 775fae5
Search for TextureDimension
in the examples folder and there are many hits.
It typically looks like so:
let size = Extent3d {
width: window_size.x,
height: window_size.y,
..default()
};
let format = TextureFormat::Bgra8UnormSrgb;
let image = Image {
data: Some(vec![0; size.volume() * format.pixel_size()]),
texture_descriptor: TextureDescriptor {
label: None,
size,
dimension: TextureDimension::D2,
format,
mip_level_count: 1,
sample_count: 1,
usage: TextureUsages::TEXTURE_BINDING
| TextureUsages::COPY_DST
| TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
},
..default()
};
let image_handle = images.add(image);
It's quite verbose and is (arguably) needlessly close to the wgpu innards.
What solution would you like?
We could expose a builder pattern which would look along the lines of:
let image = ImageBuilder::new_2d(vec2(window_size.x, window_size.y))
.data(vec![0; size.volume() * format.pixel_size()])
.usage(TextureUsages::TEXTURE_BINDING
| TextureUsages::COPY_DST
| TextureUsages::RENDER_ATTACHMENT);
// mip level, sample count, texture format, view formats have sane defaults
// and have builder methods for users who need them
let image_handle = images.add(image.build());
and similar for 3d (maybe 1d?).
Some bikeshedding opportunities:
usage(flags)
vsusage_texture_binding()
+usage_copy_destination()
+ ...new_2d(size)
could zero by default, making.data()
unnecessary unless there was actual non-zero data to provide
What alternative(s) have you considered?
Just keeping things as-is.
Additional context
Some discord context: https://discordapp.com/channels/691052431525675048/692572690833473578/1369263245608620082