veloren/voxygen/src/render/instances.rs

31 lines
743 B
Rust
Raw Normal View History

2020-08-21 19:10:56 +00:00
use super::{buffer::Buffer, RenderError};
use bytemuck::Pod;
2019-08-19 17:23:47 +00:00
/// Represents a mesh that has been sent to the GPU.
2020-08-21 19:10:56 +00:00
#[derive(Clone)]
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
}
impl<T: Copy + Pod> Instances<T> {
2020-08-21 19:10:56 +00:00
pub fn new(device: &mut wgpu::Device, len: usize) -> Self {
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
2019-08-19 17:23:47 +00:00
pub fn update(
&mut self,
2020-08-21 19:10:56 +00:00
device: &wgpu::Device,
queue: &wgpu::Queue,
vals: &[T],
offset: usize,
2019-08-19 17:23:47 +00:00
) -> Result<(), RenderError> {
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
pub fn buf(&self) -> &wgpu::Buffer { self.buf.buf }
2019-08-19 17:23:47 +00:00
}