veloren/voxygen/src/render/instances.rs

33 lines
885 B
Rust
Raw Normal View History

use super::buffer::DynamicBuffer;
use bytemuck::Pod;
2019-08-19 17:23:47 +00:00
/// Represents a mesh that has been sent to the GPU.
pub struct Instances<T: Copy + Pod> {
buf: DynamicBuffer<T>,
2019-08-19 17:23:47 +00:00
}
impl<T: Copy + Pod> Instances<T> {
pub fn new(device: &wgpu::Device, len: usize) -> Self {
2020-08-21 19:10:56 +00:00
Self {
// TODO: examine if we have Intances that are not updated and if there would be any
// gains from separating those out
buf: DynamicBuffer::new(device, len, wgpu::BufferUsage::VERTEX),
2020-08-21 19:10:56 +00:00
}
2019-08-19 17:23:47 +00:00
}
// TODO: count vs len naming scheme??
pub fn count(&self) -> usize { self.buf.len() }
2019-08-19 21:54:16 +00:00
pub fn update(
&mut self,
device: &wgpu::Device,
queue: &wgpu::Queue,
vals: &[T],
offset: usize,
) {
2020-08-21 19:10:56 +00:00
self.buf.update(device, queue, vals, offset)
2019-08-19 17:23:47 +00:00
}
2020-08-21 19:10:56 +00:00
2020-09-26 15:43:59 +00:00
pub fn buf(&self) -> &wgpu::Buffer { &self.buf.buf }
2019-08-19 17:23:47 +00:00
}