1pub struct TextureSpec {
2 pub width: u32,
3 pub height: u32,
4 pub format: wgpu::TextureFormat,
5 pub data: Vec<u8>,
6 pub generate_mips: bool,
7}
8
9impl TextureSpec {
10 pub fn wgpu_descriptor(&self) -> wgpu::TextureDescriptor<'static> {
12 wgpu::TextureDescriptor {
13 label: None,
14 size: wgpu::Extent3d {
15 width: self.width,
16 height: self.height,
17 depth_or_array_layers: 1,
18 },
19 mip_level_count: 1,
20 sample_count: 1,
21 dimension: wgpu::TextureDimension::D2,
22 format: self.format,
23 usage: wgpu::TextureUsages::TEXTURE_BINDING | wgpu::TextureUsages::COPY_DST,
24 view_formats: &[],
25 }
26 }
27}
28
29impl TextureSpec {
30 pub fn new(width: u32, height: u32, data: Vec<u8>, generate_mips: bool) -> Self {
31 Self {
32 width,
33 height,
34 format: wgpu::TextureFormat::Rgba8Unorm,
35 data,
36 generate_mips,
37 }
38 }
39
40 pub fn with_format(mut self, format: wgpu::TextureFormat) -> Self {
41 self.format = format;
42 self
43 }
44}