use crate::wgpu::backend::WGPUBackend;
pub struct TextureView {
view: wgpu::TextureView,
_texture: wgpu::Texture,
}
impl TextureView {
pub(crate) fn raw(&self) -> &wgpu::TextureView {
&self.view
}
}
pub struct TextureBuilder<'a> {
label: Option<&'a str>,
width: u32,
height: u32,
format: wgpu::TextureFormat,
usage: wgpu::TextureUsages,
mip_level_count: u32,
}
impl<'a> TextureBuilder<'a> {
pub fn new(width: u32, height: u32, format: wgpu::TextureFormat) -> Self {
Self { label: None, width, height, format, usage: wgpu::TextureUsages::empty(), mip_level_count: 1 }
}
pub fn label(mut self, label: impl Into<Option<&'a str>>) -> Self {
self.label = label.into();
self
}
pub fn usage(mut self, usage: wgpu::TextureUsages) -> Self {
self.usage = usage;
self
}
pub fn mip_level_count(mut self, count: u32) -> Self {
self.mip_level_count = count;
self
}
pub fn build(self, backend: &WGPUBackend) -> TextureView {
let texture = backend.device.create_texture(&wgpu::TextureDescriptor {
label: self.label,
size: wgpu::Extent3d { width: self.width, height: self.height, depth_or_array_layers: 1 },
mip_level_count: self.mip_level_count,
sample_count: 1,
dimension: wgpu::TextureDimension::D2,
format: self.format,
usage: self.usage,
view_formats: &[],
});
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
TextureView { view, _texture: texture }
}
}