Skip to main content

oxide_renderer/
depth.rs

1//! Depth texture for depth buffering
2
3use wgpu::{Device, Texture, TextureDescriptor, TextureDimension, TextureFormat, TextureUsages};
4
5pub struct DepthTexture {
6    pub texture: Texture,
7    pub view: wgpu::TextureView,
8}
9
10impl DepthTexture {
11    pub fn new(device: &Device, width: u32, height: u32, label: Option<&str>) -> Self {
12        let texture = device.create_texture(&TextureDescriptor {
13            label,
14            size: wgpu::Extent3d {
15                width,
16                height,
17                depth_or_array_layers: 1,
18            },
19            mip_level_count: 1,
20            sample_count: 1,
21            dimension: TextureDimension::D2,
22            format: TextureFormat::Depth24PlusStencil8,
23            usage: TextureUsages::RENDER_ATTACHMENT,
24            view_formats: &[],
25        });
26
27        let view = texture.create_view(&wgpu::TextureViewDescriptor::default());
28
29        Self { texture, view }
30    }
31
32    pub fn resize(&mut self, device: &Device, width: u32, height: u32) {
33        *self = Self::new(device, width, height, Some("Depth Texture"));
34    }
35}