Struct luminance::buffer::Buffer [−][src]
pub struct Buffer<B: ?Sized, T> where
B: BufferBackend<T>,
T: Copy, { /* fields omitted */ }
Expand description
A GPU buffer.
Parametricity
Bis the backend type. It must implementbackend::buffer::Buffer. -Tis the type of stored items. No restriction are currently enforced on that type, besides the fact it must beSized.
Implementations
pub fn new<C>(ctx: &mut C, len: usize) -> Result<Self, BufferError> where
C: GraphicsContext<Backend = B>,
T: Default,
pub fn new<C>(ctx: &mut C, len: usize) -> Result<Self, BufferError> where
C: GraphicsContext<Backend = B>,
T: Default, Create a new buffer with a given length
The buffer will be created on the GPU with a contiguous region large enough to fit len
items.
The stored item must be Default, as this function will initialize the whole buffer
with the default value.
Errors
That function can fail creating the buffer for various reasons, in which case it returns
Err(BufferError::_). Feel free to read the documentation of BufferError for further
information.
Notes
You might be interested in the GraphicsContext::new_buffer function instead, which
is the exact same function, but benefits from more type inference (based on &mut C).
pub fn from_vec<C, X>(ctx: &mut C, vec: X) -> Result<Self, BufferError> where
C: GraphicsContext<Backend = B>,
X: Into<Vec<T>>,
pub fn from_vec<C, X>(ctx: &mut C, vec: X) -> Result<Self, BufferError> where
C: GraphicsContext<Backend = B>,
X: Into<Vec<T>>, Create a new buffer from a slice of items.
The buffer will be created with a length equal to the length of the input size, and items will be copied from the slice inside the contiguous GPU region.
Errors
That function can fail creating the buffer for various reasons, in which case it returns
Err(BufferError::_). Feel free to read the documentation of BufferError for further
information.
Notes
You might be interested in the GraphicsContext::new_buffer_from_vec function instead,
which is the exact same function, but benefits from more type inference (based on &mut C).
pub fn repeat<C>(ctx: &mut C, len: usize, value: T) -> Result<Self, BufferError> where
C: GraphicsContext<Backend = B>,
pub fn repeat<C>(ctx: &mut C, len: usize, value: T) -> Result<Self, BufferError> where
C: GraphicsContext<Backend = B>, Create a new buffer by repeating len times a value.
The buffer will be comprised of len items, all equal to value.
Errors
That function can fail creating the buffer for various reasons, in which case it returns
Err(BufferError::_). Feel free to read the documentation of BufferError for further
information.
Notes
You might be interested in the GraphicsContext::new_buffer_repeating function instead,
which is the exact same function, but benefits from more type inference (based on &mut C).
Set a value x at index i in the buffer.
Errors
That function returns BufferError::Overflow if i is bigger than the length of the
buffer. Other errors are possible; please consider reading the documentation of
BufferError for further information.
Set the content of the buffer by using a slice that will be copied at the buffer’s memory location.
Errors
BufferError::TooFewValues is returned if the input slice has less items than the buffer.
BufferError::TooManyValues is returned if the input slice has more items than the buffer.
Clear the content of the buffer by copying the same value everywhere.
Check whether the buffer is empty (i.e. it has no elements).
Note
Since right now, it is not possible to grow vectors, it is highly recommended not to create empty buffers. That function is there only for convenience and demonstration; you shouldn’t really have to use it.
Create a new BufferSlice from a buffer, allowing to get &[T] out of it.
Errors
That function might fail and return a BufferError::MapFailed.
Create a new BufferSliceMut from a buffer, allowing to get &mut [T] out of it.
Errors
That function might fail and return a BufferError::MapFailed.
Trait Implementations
Auto Trait Implementations
impl<B: ?Sized, T> RefUnwindSafe for Buffer<B, T> where
T: RefUnwindSafe,
<B as Buffer<T>>::BufferRepr: RefUnwindSafe, impl<B: ?Sized, T> UnwindSafe for Buffer<B, T> where
T: UnwindSafe,
<B as Buffer<T>>::BufferRepr: UnwindSafe,