use crate::context::Context;
pub struct Accumulation {
pub buffer: wgpu::Buffer,
pub width: u32,
pub height: u32,
}
const PIXEL_SIZE: u64 = 16; pub const REGIONS: u64 = 3;
impl Accumulation {
pub fn new(width: u32, height: u32) -> Accumulation {
Accumulation {
buffer: Self::make_buffer(width, height),
width,
height,
}
}
fn make_buffer(width: u32, height: u32) -> wgpu::Buffer {
let ctxt = Context::get();
let count = (width.max(1) as u64) * (height.max(1) as u64);
ctxt.create_buffer_simple(
Some("rt_accumulation"),
count * REGIONS * PIXEL_SIZE,
wgpu::BufferUsages::STORAGE | wgpu::BufferUsages::COPY_SRC,
)
}
pub fn ensure(&mut self, width: u32, height: u32) -> bool {
if width == self.width && height == self.height {
return false;
}
self.buffer = Self::make_buffer(width, height);
self.width = width;
self.height = height;
true
}
}