pub struct TypedBuffer<T: Pod> { /* private fields */ }Expand description
A GPU buffer with type-safe element tracking.
This wrapper adds:
- Type safety via generics
- Automatic length tracking
- Convenient write operations
The underlying buffer is directly accessible via the AsWgpu trait.
Implementations§
Source§impl<T: Pod> TypedBuffer<T>
impl<T: Pod> TypedBuffer<T>
Sourcepub fn new(
device: &Device,
label: Option<&str>,
data: &[T],
usage: BufferUsages,
) -> Self
pub fn new( device: &Device, label: Option<&str>, data: &[T], usage: BufferUsages, ) -> Self
Create a new typed buffer with initial data.
§Arguments
device- The wgpu device to create the buffer onlabel- Optional debug label for the bufferdata- Initial data to populate the buffer withusage- Buffer usage flags
Sourcepub fn with_capacity(
device: &Device,
label: Option<&str>,
capacity: u32,
usage: BufferUsages,
) -> Self
pub fn with_capacity( device: &Device, label: Option<&str>, capacity: u32, usage: BufferUsages, ) -> Self
Create an empty typed buffer with a given capacity.
§Arguments
device- The wgpu device to create the buffer onlabel- Optional debug label for the buffercapacity- Number of elements the buffer can holdusage- Buffer usage flags
Sourcepub fn capacity_bytes(&self) -> u64
pub fn capacity_bytes(&self) -> u64
Get the capacity of the buffer in bytes.
Sourcepub fn usage(&self) -> BufferUsages
pub fn usage(&self) -> BufferUsages
Get the buffer usage flags.
Sourcepub fn slice(&self) -> BufferSlice<'_>
pub fn slice(&self) -> BufferSlice<'_>
Get a slice of the entire buffer.
Sourcepub fn slice_range(&self, range: Range<u32>) -> BufferSlice<'_>
pub fn slice_range(&self, range: Range<u32>) -> BufferSlice<'_>
Get a slice of a portion of the buffer.
Sourcepub fn write(&self, queue: &Queue, data: &[T])
pub fn write(&self, queue: &Queue, data: &[T])
Write data to the buffer.
The buffer must have been created with COPY_DST usage.
Sourcepub fn write_at(&self, queue: &Queue, offset: u32, data: &[T])
pub fn write_at(&self, queue: &Queue, offset: u32, data: &[T])
Write data to the buffer at an offset.
The buffer must have been created with COPY_DST usage.
Sourcepub fn as_binding(&self) -> BindingResource<'_>
pub fn as_binding(&self) -> BindingResource<'_>
Get the buffer as a binding resource (for bind groups).
Source§impl<T: Pod> TypedBuffer<T>
impl<T: Pod> TypedBuffer<T>
Sourcepub fn new_uniform(device: &Device, label: Option<&str>, data: &T) -> Self
pub fn new_uniform(device: &Device, label: Option<&str>, data: &T) -> Self
Create a new uniform buffer.
Sourcepub fn write_uniform(&self, queue: &Queue, data: &T)
pub fn write_uniform(&self, queue: &Queue, data: &T)
Write a single uniform value to the buffer.
Trait Implementations§
Source§impl<T: Pod> AsWgpu for TypedBuffer<T>
impl<T: Pod> AsWgpu for TypedBuffer<T>
Auto Trait Implementations§
impl<T> Freeze for TypedBuffer<T>
impl<T> !RefUnwindSafe for TypedBuffer<T>
impl<T> Send for TypedBuffer<T>where
T: Send,
impl<T> Sync for TypedBuffer<T>where
T: Sync,
impl<T> Unpin for TypedBuffer<T>where
T: Unpin,
impl<T> !UnwindSafe for TypedBuffer<T>
Blanket Implementations§
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
Mutably borrows from an owned value. Read more
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>
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>
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)
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)
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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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>
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 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>
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