pub(crate) struct StencilTarget {
view: Option<wgpu::TextureView>,
width: u32,
height: u32,
sample_count: u32,
}
impl StencilTarget {
pub(crate) fn new(sample_count: u32) -> Self {
Self { view: None, width: 0, height: 0, sample_count }
}
pub(crate) fn ensure(&mut self, device: &wgpu::Device, width: u32, height: u32) {
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_stencil"),
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: wgpu::TextureFormat::Stencil8,
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 view(&self) -> &wgpu::TextureView {
self.view
.as_ref()
.expect("StencilTarget::ensure must run before view() — only call when a frame is armed")
}
}