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