UniformBuffer

Struct UniformBuffer 

Source
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,

Source

pub fn new() -> UniformBuffer<S>

Creates a new uniform buffer with an empty storage.

Source

pub fn with_storage(storage: S) -> UniformBuffer<S>

Creates a new uniform buffer with the given storage.

Source

pub fn clear(&mut self)

Clears the uniform buffer.

Source

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.

Source

pub fn is_empty(&self) -> bool

Checks if the buffer is empty or not.

Source

pub fn push_padding(&mut self, alignment: usize)

Pushes the given amount of padding bytes to the storage.

Source

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.

Source

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.

Source

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.

Source

pub fn push_slice_with_max_size<T>( &mut self, slice: &[T], max_len: usize, ) -> &mut UniformBuffer<S>
where T: Std140 + Default,

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.

Source

pub fn with_slice_with_max_size<T>( self, slice: &[T], max_len: usize, ) -> UniformBuffer<S>
where T: Std140 + Default,

Same as Self::push_slice_with_max_size, but allows changed calls with builder-like style.

Source

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.

Source

pub fn storage(&self) -> &S

Returns a reference to the internal bytes storage of the uniform buffer.

Source

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.

Source

pub fn next_write_aligned_position(&self, alignment: usize) -> usize

Calculates position for the next element including the given alignment.

Source

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,

Source§

fn default() -> UniformBuffer<S>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> AsyncTaskResult for T
where T: Any + Send + 'static,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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 T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts self reference as a reference to Any. Could be used to downcast a trait object to a particular type.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts self reference as a reference to Any. Could be used to downcast a trait object to a particular type.
Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> FieldValue for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Casts self to a &dyn Any
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V