pub struct DepthTexture {
pub texture: wgpu::Texture,
pub view: wgpu::TextureView,
pub format: wgpu::TextureFormat,
pub sample_count: u32,
}
impl DepthTexture {
pub const FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;
pub fn new(device: &wgpu::Device, width: u32, height: u32, sample_count: u32) -> Self {
let size = wgpu::Extent3d {
width: width.max(1),
height: height.max(1),
depth_or_array_layers: 1,
};
let texture = device.create_texture(&wgpu::TextureDescriptor {
label: Some("Depth Texture"),
size,
mip_level_count: 1,
sample_count,
dimension: wgpu::TextureDimension::D2,
format: Self::FORMAT,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING,
view_formats: &[],
});
let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
Self {
texture,
view,
format: Self::FORMAT,
sample_count,
}
}
pub fn resize(&mut self, device: &wgpu::Device, width: u32, height: u32) {
let sample_count = self.sample_count;
*self = Self::new(device, width, height, sample_count);
}
}