pub struct UniformBuffer<S>where
S: ByteStorage,{ /* private fields */ }
Expand description
Uniform buffer is a special byte storage that ensures correct data alignment suitable for GPU.
Current implementation supports std140
data layout scheme.
§Examples
let bytes = StaticUniformBuffer::<256>::new()
.with(&Matrix4::identity())
.with(&Color::WHITE)
.with(&Vector3::new(0.0, 1.0, 0.0))
.finish();
Implementations§
Source§impl<S> UniformBuffer<S>where
S: ByteStorage + Default,
impl<S> UniformBuffer<S>where
S: ByteStorage + Default,
Sourcepub fn new() -> UniformBuffer<S>
pub fn new() -> UniformBuffer<S>
Creates a new uniform buffer with an empty storage.
Sourcepub fn with_storage(storage: S) -> UniformBuffer<S>
pub fn with_storage(storage: S) -> UniformBuffer<S>
Creates a new uniform buffer with the given storage.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns total number of bytes stored in the uniform buffer. Keep in mind, that the number in the vast majority of cases won’t match the sum of all pushed elements due to alignment requirements.
Sourcepub fn push_padding(&mut self, alignment: usize)
pub fn push_padding(&mut self, alignment: usize)
Pushes the given amount of padding bytes to the storage.
Sourcepub fn push<T>(&mut self, value: &T) -> &mut UniformBuffer<S>where
T: Std140,
pub fn push<T>(&mut self, value: &T) -> &mut UniformBuffer<S>where
T: Std140,
Pushes a value to the storage. This method ensures that the correct alignment for the pushed value is preserved.
Sourcepub fn with<T>(self, value: &T) -> UniformBuffer<S>where
T: Std140,
pub fn with<T>(self, value: &T) -> UniformBuffer<S>where
T: Std140,
The same as Self::push
, but allows chained calls in a builder manner.
Sourcepub fn push_slice<T>(&mut self, slice: &[T]) -> &mut UniformBuffer<S>where
T: Std140,
pub fn push_slice<T>(&mut self, slice: &[T]) -> &mut UniformBuffer<S>where
T: Std140,
Pushes a slice of given values. Keep in mind, that this method is not the same as pushing
individual slice elements one by one. Instead, this method preserves alignment requirements
for arrays as std140
rule set requires.
Sourcepub fn push_slice_with_max_size<T>(
&mut self,
slice: &[T],
max_len: usize,
) -> &mut UniformBuffer<S>
pub fn push_slice_with_max_size<T>( &mut self, slice: &[T], max_len: usize, ) -> &mut UniformBuffer<S>
Pushes the given slice into the uniform buffer and pads the rest of the space
(max_len - slice_len
) with the default value of the underlying type.
Sourcepub fn with_slice_with_max_size<T>(
self,
slice: &[T],
max_len: usize,
) -> UniformBuffer<S>
pub fn with_slice_with_max_size<T>( self, slice: &[T], max_len: usize, ) -> UniformBuffer<S>
Same as Self::push_slice_with_max_size
, but allows changed calls with builder-like style.
Sourcepub fn with_slice<T>(self, slice: &[T]) -> UniformBuffer<S>where
T: Std140,
pub fn with_slice<T>(self, slice: &[T]) -> UniformBuffer<S>where
T: Std140,
The same as Self::push_slice
, but allows chained calls in a builder manner.
Sourcepub fn storage(&self) -> &S
pub fn storage(&self) -> &S
Returns a reference to the internal bytes storage of the uniform buffer.
Sourcepub fn finish(self) -> S
pub fn finish(self) -> S
Finishes buffer filling process and returns the backing storage by consuming the buffer. This method must be called before sending the data GPU, otherwise the buffer may contain misaligned data.
Sourcepub fn next_write_aligned_position(&self, alignment: usize) -> usize
pub fn next_write_aligned_position(&self, alignment: usize) -> usize
Calculates position for the next element including the given alignment.
Sourcepub fn write_bytes_with_alignment(
&mut self,
bytes: &[u8],
alignment: usize,
) -> usize
pub fn write_bytes_with_alignment( &mut self, bytes: &[u8], alignment: usize, ) -> usize
Writes bytes directly to the buffer with the given alignment. Important: this method could
be dangerous if misused, the alignment argument must be correct and comply with std140
data layout rules.
Trait Implementations§
Source§impl<S> Default for UniformBuffer<S>where
S: Default + ByteStorage,
impl<S> Default for UniformBuffer<S>where
S: Default + ByteStorage,
Source§fn default() -> UniformBuffer<S>
fn default() -> UniformBuffer<S>
Auto Trait Implementations§
impl<S> Freeze for UniformBuffer<S>where
S: Freeze,
impl<S> RefUnwindSafe for UniformBuffer<S>where
S: RefUnwindSafe,
impl<S> Send for UniformBuffer<S>where
S: Send,
impl<S> Sync for UniformBuffer<S>where
S: Sync,
impl<S> Unpin for UniformBuffer<S>where
S: Unpin,
impl<S> UnwindSafe for UniformBuffer<S>where
S: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsyncTaskResult for T
impl<T> AsyncTaskResult for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Any
. Could be used to downcast a trait object
to a particular type.fn into_any(self: Box<T>) -> Box<dyn Any>
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> FieldValue for Twhere
T: 'static,
impl<T> FieldValue for Twhere
T: 'static,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian()
.Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self
is actually part of its subset T
(and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset
but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self
to the equivalent element of its superset.