pub(crate) fn no_write_depth(format: wgpu::TextureFormat) -> wgpu::DepthStencilState {
wgpu::DepthStencilState {
format,
depth_write_enabled: Some(false),
depth_compare: Some(wgpu::CompareFunction::Always),
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
}
}
pub(crate) fn depth_test(format: wgpu::TextureFormat) -> wgpu::DepthStencilState {
wgpu::DepthStencilState {
format,
depth_write_enabled: Some(true),
depth_compare: Some(wgpu::CompareFunction::Less),
stencil: wgpu::StencilState::default(),
bias: wgpu::DepthBiasState::default(),
}
}
pub(crate) fn multisample(sample_count: u32) -> wgpu::MultisampleState {
wgpu::MultisampleState {
count: sample_count,
mask: !0,
alpha_to_coverage_enabled: false,
}
}
pub(crate) struct Targets<'a> {
pub color: &'a wgpu::TextureView,
pub resolve: Option<&'a wgpu::TextureView>,
pub depth: Option<&'a wgpu::TextureView>,
}
impl<'a> Targets<'a> {
pub fn color_attachment(
&self,
load: wgpu::LoadOp<wgpu::Color>,
) -> wgpu::RenderPassColorAttachment<'a> {
wgpu::RenderPassColorAttachment {
view: self.color,
depth_slice: None,
resolve_target: self.resolve,
ops: wgpu::Operations {
load,
store: wgpu::StoreOp::Store,
},
}
}
pub fn depth_attachment(
&self,
load: wgpu::LoadOp<f32>,
) -> Option<wgpu::RenderPassDepthStencilAttachment<'a>> {
self.depth
.map(|view| wgpu::RenderPassDepthStencilAttachment {
view,
depth_ops: Some(wgpu::Operations {
load,
store: wgpu::StoreOp::Store,
}),
stencil_ops: None,
})
}
}