use super::{gfx_backend, RenderError}; use gfx::{ self, buffer::Role, memory::{Bind, Usage}, Factory, }; /// Represents a mesh that has been sent to the GPU. pub struct Instances { pub ibuf: gfx::handle::Buffer, } impl Instances { #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn new(factory: &mut gfx_backend::Factory, len: usize) -> Result { Ok(Self { ibuf: factory .create_buffer(len, Role::Vertex, Usage::Dynamic, Bind::TRANSFER_DST) .map_err(|err| RenderError::BufferCreationError(err))?, }) } pub fn count(&self) -> usize { self.ibuf.len() } #[allow(clippy::redundant_closure)] // TODO: Pending review in #587 pub fn update( &mut self, encoder: &mut gfx::Encoder, instances: &[T], ) -> Result<(), RenderError> { encoder .update_buffer(&self.ibuf, instances, 0) .map_err(|err| RenderError::UpdateError(err)) } }