veloren_voxygen/render/
consts.rs

1use super::buffer::DynamicBuffer;
2use bytemuck::Pod;
3
4/// A handle to a series of constants sitting on the GPU. This is used to hold
5/// information used in the rendering process that does not change throughout a
6/// single render pass.
7pub struct Consts<T: Copy + Pod> {
8    buf: DynamicBuffer<T>,
9}
10
11impl<T: Copy + Pod> Consts<T> {
12    /// Create a new `Const<T>`.
13    pub fn new(device: &wgpu::Device, len: usize) -> Self {
14        Self {
15            // TODO: examine if all our consts need to be updatable
16            buf: DynamicBuffer::new(device, len, wgpu::BufferUsages::UNIFORM),
17        }
18    }
19
20    /// Update the GPU-side value represented by this constant handle.
21    pub fn update(&mut self, queue: &wgpu::Queue, vals: &[T], offset: usize) {
22        self.buf.update(queue, vals, offset)
23    }
24
25    pub fn buf(&self) -> &wgpu::Buffer { &self.buf.buf }
26}