pub(crate) struct MsaaTarget {
view: Option<wgpu::TextureView>,
width: u32,
height: u32,
sample_count: u32,
format: wgpu::TextureFormat,
}
impl MsaaTarget {
pub(crate) fn new(sample_count: u32, format: wgpu::TextureFormat) -> Self {
Self { view: None, width: 0, height: 0, sample_count, format }
}
pub(crate) fn ensure(&mut self, device: &wgpu::Device, width: u32, height: u32) {
if self.sample_count <= 1 {
return;
}
let w = width.max(1);
let h = height.max(1);
if self.view.is_some() && w == self.width && h == self.height {
return;
}
let tex = device.create_texture(&wgpu::TextureDescriptor {
label: Some("uzor_urx_wgpu.native_msaa_color"),
size: wgpu::Extent3d { width: w, height: h, depth_or_array_layers: 1 },
mip_level_count: 1,
sample_count: self.sample_count,
dimension: wgpu::TextureDimension::D2,
format: self.format,
usage: wgpu::TextureUsages::RENDER_ATTACHMENT,
view_formats: &[],
});
self.view = Some(tex.create_view(&wgpu::TextureViewDescriptor::default()));
self.width = w;
self.height = h;
}
pub(crate) fn color_view(&self) -> &wgpu::TextureView {
self.view
.as_ref()
.expect("MsaaTarget::ensure must run before color_view at sample_count > 1")
}
}