2020-11-28 05:44:23 +00:00
|
|
|
use super::buffer::DynamicBuffer;
|
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-11-28 05:44:23 +00:00
|
|
|
buf: DynamicBuffer<T>,
|
2019-08-19 17:23:47 +00:00
|
|
|
}
|
|
|
|
|
2020-09-13 17:26:23 +00:00
|
|
|
impl<T: Copy + Pod> Instances<T> {
|
2020-11-28 05:44:23 +00:00
|
|
|
pub fn new(device: &wgpu::Device, len: usize) -> Self {
|
2020-08-21 19:10:56 +00:00
|
|
|
Self {
|
2021-05-13 03:59:51 +00:00
|
|
|
// TODO: examine if we have Instances that are not updated (e.g. sprites) and if there
|
2021-04-27 02:43:24 +00:00
|
|
|
// would be any gains from separating those out
|
2020-11-28 05:44:23 +00:00
|
|
|
buf: DynamicBuffer::new(device, len, wgpu::BufferUsage::VERTEX),
|
2020-08-21 19:10:56 +00:00
|
|
|
}
|
2019-08-19 17:23:47 +00:00
|
|
|
}
|
|
|
|
|
2020-11-28 05:44:23 +00:00
|
|
|
// TODO: count vs len naming scheme??
|
|
|
|
pub fn count(&self) -> usize { self.buf.len() }
|
2019-08-19 21:54:16 +00:00
|
|
|
|
2021-04-26 03:19:23 +00:00
|
|
|
pub fn update(&mut self, queue: &wgpu::Queue, vals: &[T], offset: usize) {
|
|
|
|
self.buf.update(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
|
|
|
}
|