2020-09-26 15:43:59 +00:00
|
|
|
use super::buffer::Buffer;
|
2020-09-13 17:26:23 +00:00
|
|
|
use bytemuck::Pod;
|
2019-08-19 17:23:47 +00:00
|
|
|
|
|
|
|
/// Represents a mesh that has been sent to the GPU.
|
2020-09-13 17:26:23 +00:00
|
|
|
pub struct Instances<T: Copy + Pod> {
|
2020-08-21 19:10:56 +00:00
|
|
|
buf: Buffer<T>,
|
2019-08-19 17:23:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 17:26:23 +00:00
|
|
|
impl<T: Copy + Pod> Instances<T> {
|
2020-09-26 15:43:59 +00:00
|
|
|
pub fn new(device: &wgpu::Device, len: u64) -> Self {
|
2020-08-21 19:10:56 +00:00
|
|
|
Self {
|
|
|
|
buf: Buffer::new(device, len, wgpu::BufferUsage::VERTEX),
|
|
|
|
}
|
2019-08-19 17:23:47 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 19:10:56 +00:00
|
|
|
pub fn count(&self) -> usize { self.buf.count() }
|
2019-08-19 21:54:16 +00:00
|
|
|
|
2020-09-26 15:43:59 +00:00
|
|
|
pub fn update(&mut self, device: &wgpu::Device, queue: &wgpu::Queue, vals: &[T], offset: u64) {
|
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
|
|
|
}
|