[−][src]Struct luminance::buffer::Buffer
A GPU buffer.
Parametricity
B
is the backend type. It must implementbackend::buffer::Buffer
. -T
is the type of stored items. No restriction are currently enforced on that type, besides the fact it must beSized
.
Implementations
impl<B: ?Sized, T> Buffer<B, T> where
B: BufferBackend<T>,
T: Copy,
[src]
B: BufferBackend<T>,
T: Copy,
pub fn new<C>(ctx: &mut C, len: usize) -> Result<Self, BufferError> where
C: GraphicsContext<Backend = B>,
T: Default,
[src]
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>>,
[src]
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>,
[src]
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
).
pub fn at(&self, i: usize) -> Option<T>
[src]
Get the item at the given index.
pub fn whole(&self) -> Vec<T>
[src]
Get the whole content of the buffer and store it inside a Vec
.
pub fn set(&mut self, i: usize, x: T) -> Result<(), BufferError>
[src]
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.
pub fn write_whole(&mut self, values: &[T]) -> Result<(), BufferError>
[src]
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.
pub fn clear(&mut self, x: T) -> Result<(), BufferError>
[src]
Clear the content of the buffer by copying the same value everywhere.
pub fn len(&self) -> usize
[src]
Return the length of the buffer (i.e. the number of elements).
pub fn is_empty(&self) -> bool
[src]
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.
impl<B: ?Sized, T> Buffer<B, T> where
B: BufferSliceBackend<T>,
T: Copy,
[src]
B: BufferSliceBackend<T>,
T: Copy,
pub fn slice(&mut self) -> Result<BufferSlice<'_, B, T>, BufferError>
[src]
Create a new BufferSlice
from a buffer, allowing to get &[T]
out of it.
Errors
That function might fail and return a BufferError::MapFailed
.
pub fn slice_mut(&mut self) -> Result<BufferSliceMut<'_, B, T>, BufferError>
[src]
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
impl<B: Debug + ?Sized, T: Debug> Debug for Buffer<B, T> where
B: BufferBackend<T>,
T: Copy,
B::BufferRepr: Debug,
[src]
B: BufferBackend<T>,
T: Copy,
B::BufferRepr: Debug,
Auto Trait Implementations
impl<B: ?Sized, T> RefUnwindSafe for Buffer<B, T> where
T: RefUnwindSafe,
<B as Buffer<T>>::BufferRepr: RefUnwindSafe,
[src]
T: RefUnwindSafe,
<B as Buffer<T>>::BufferRepr: RefUnwindSafe,
impl<B: ?Sized, T> Send for Buffer<B, T> where
T: Send,
<B as Buffer<T>>::BufferRepr: Send,
[src]
T: Send,
<B as Buffer<T>>::BufferRepr: Send,
impl<B: ?Sized, T> Sync for Buffer<B, T> where
T: Sync,
<B as Buffer<T>>::BufferRepr: Sync,
[src]
T: Sync,
<B as Buffer<T>>::BufferRepr: Sync,
impl<B: ?Sized, T> Unpin for Buffer<B, T> where
T: Unpin,
<B as Buffer<T>>::BufferRepr: Unpin,
[src]
T: Unpin,
<B as Buffer<T>>::BufferRepr: Unpin,
impl<B: ?Sized, T> UnwindSafe for Buffer<B, T> where
T: UnwindSafe,
<B as Buffer<T>>::BufferRepr: UnwindSafe,
[src]
T: UnwindSafe,
<B as Buffer<T>>::BufferRepr: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,