use super::{gfx_backend, RenderError}; use gfx::{self, traits::FactoryExt}; /// A handle to a series of constants sitting on the GPU. This is used to hold /// information used in the rendering process that does not change throughout a /// single render pass. #[derive(Clone)] pub struct Consts { pub buf: gfx::handle::Buffer, } impl Consts { /// Create a new `Const`. pub fn new(factory: &mut gfx_backend::Factory, len: usize) -> Self { Self { buf: factory.create_constant_buffer(len), } } /// Update the GPU-side value represented by this constant handle. pub fn update( &mut self, encoder: &mut gfx::Encoder, vals: &[T], ) -> Result<(), RenderError> { encoder .update_buffer(&self.buf, vals, 0) .map_err(|err| RenderError::UpdateError(err)) } }