Added depth buffer to sort drawing indices
This commit is contained in:
parent
d5f5949107
commit
6c0cfbefce
@ -31,6 +31,7 @@ pub struct State<'a> {
|
|||||||
global_buffer: wgpu::Buffer,
|
global_buffer: wgpu::Buffer,
|
||||||
|
|
||||||
camera: Camera,
|
camera: Camera,
|
||||||
|
depth_texture: wgpu::TextureView,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> State<'a> {
|
impl<'a> State<'a> {
|
||||||
@ -93,6 +94,8 @@ impl<'a> State<'a> {
|
|||||||
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
usage: wgpu::BufferUsages::VERTEX | wgpu::BufferUsages::COPY_DST,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let depth_texture = Self::create_depth_texture(&device, config.width, config.height, sample_count.get());
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
surface,
|
surface,
|
||||||
device,
|
device,
|
||||||
@ -108,9 +111,28 @@ impl<'a> State<'a> {
|
|||||||
instances,
|
instances,
|
||||||
instance_buffer,
|
instance_buffer,
|
||||||
camera,
|
camera,
|
||||||
|
depth_texture,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_depth_texture(device: &Device, width: u32, height: u32, sample_count: u32) -> wgpu::TextureView {
|
||||||
|
let texture = device.create_texture(&wgpu::TextureDescriptor {
|
||||||
|
label: Some("Depth Texture"),
|
||||||
|
size: wgpu::Extent3d {
|
||||||
|
width,
|
||||||
|
height,
|
||||||
|
depth_or_array_layers: 1,
|
||||||
|
},
|
||||||
|
mip_level_count: 1,
|
||||||
|
sample_count,
|
||||||
|
dimension: wgpu::TextureDimension::D2,
|
||||||
|
format: wgpu::TextureFormat::Depth32Float,
|
||||||
|
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
|
||||||
|
view_formats: &[],
|
||||||
|
});
|
||||||
|
texture.create_view(&Default::default())
|
||||||
|
}
|
||||||
|
|
||||||
fn create_geometries(device: &Device) -> HashMap<Shape, Geometry> {
|
fn create_geometries(device: &Device) -> HashMap<Shape, Geometry> {
|
||||||
let mut geometries = HashMap::new();
|
let mut geometries = HashMap::new();
|
||||||
|
|
||||||
@ -229,7 +251,13 @@ impl<'a> State<'a> {
|
|||||||
// Requires Features::CONSERVATIVE_RASTERIZATION
|
// Requires Features::CONSERVATIVE_RASTERIZATION
|
||||||
conservative: false,
|
conservative: false,
|
||||||
},
|
},
|
||||||
depth_stencil: None,
|
depth_stencil: Some(wgpu::DepthStencilState {
|
||||||
|
format: wgpu::TextureFormat::Depth32Float,
|
||||||
|
depth_write_enabled: true,
|
||||||
|
depth_compare: wgpu::CompareFunction::Less,
|
||||||
|
stencil: wgpu::StencilState::default(),
|
||||||
|
bias: wgpu::DepthBiasState::default(),
|
||||||
|
}),
|
||||||
multisample: wgpu::MultisampleState {
|
multisample: wgpu::MultisampleState {
|
||||||
count: sample_count,
|
count: sample_count,
|
||||||
mask: !0,
|
mask: !0,
|
||||||
@ -301,6 +329,7 @@ impl<'a> State<'a> {
|
|||||||
view_proj: view_proj.into(),
|
view_proj: view_proj.into(),
|
||||||
};
|
};
|
||||||
self.queue.write_buffer(&self.global_buffer, 0, bytemuck::cast_slice(&[new_globals]));
|
self.queue.write_buffer(&self.global_buffer, 0, bytemuck::cast_slice(&[new_globals]));
|
||||||
|
self.depth_texture = Self::create_depth_texture(&self.device, self.config.width, self.config.height, self.sample_count.get());
|
||||||
|
|
||||||
println!("Resized to {:?} from state!", new_size);
|
println!("Resized to {:?} from state!", new_size);
|
||||||
}
|
}
|
||||||
@ -350,7 +379,14 @@ impl<'a> State<'a> {
|
|||||||
store: wgpu::StoreOp::Store,
|
store: wgpu::StoreOp::Store,
|
||||||
}
|
}
|
||||||
})],
|
})],
|
||||||
depth_stencil_attachment: None,
|
depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment {
|
||||||
|
view: &self.depth_texture,
|
||||||
|
depth_ops: Some(wgpu::Operations {
|
||||||
|
load: wgpu::LoadOp::Clear(1.0),
|
||||||
|
store: wgpu::StoreOp::Store,
|
||||||
|
}),
|
||||||
|
stencil_ops: None,
|
||||||
|
}),
|
||||||
occlusion_query_set: None,
|
occlusion_query_set: None,
|
||||||
timestamp_writes: None,
|
timestamp_writes: None,
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user