pub struct TypedBuffer<T: Copy> { /* private fields */ }Expand description
A strongly-typed GPU Shader Storage Buffer Object.
T must be Copy so that we can safely transmute slices to byte slices
for upload/download. In a real engine, T would also be bytemuck::Pod.
This buffer holds the GL name, current element count, capacity, usage hint, and a reference to the shared memory tracker.
Implementations§
Source§impl<T: Copy> TypedBuffer<T>
impl<T: Copy> TypedBuffer<T>
Sourcepub fn create(
gl: &Context,
capacity: usize,
usage: BufferUsage,
binding_index: u32,
tracker: Arc<MemoryTracker>,
) -> Self
pub fn create( gl: &Context, capacity: usize, usage: BufferUsage, binding_index: u32, tracker: Arc<MemoryTracker>, ) -> Self
Create a new typed buffer with given capacity (number of T elements).
The gl parameter is the glow context. binding_index is the SSBO
binding point. The buffer is allocated but not filled.
Sourcepub fn upload(&mut self, gl: &Context, data: &[T])
pub fn upload(&mut self, gl: &Context, data: &[T])
Upload a slice of data into the buffer starting at element offset 0. The buffer is resized if necessary.
Sourcepub fn upload_range(&mut self, gl: &Context, offset: usize, data: &[T])
pub fn upload_range(&mut self, gl: &Context, offset: usize, data: &[T])
Upload data at a specific element offset (partial update).
Sourcepub fn download(&self, gl: &Context) -> Vec<T>
pub fn download(&self, gl: &Context) -> Vec<T>
Download the entire buffer contents back to the CPU.
Sourcepub fn download_range(
&self,
gl: &Context,
offset: usize,
count: usize,
) -> Vec<T>
pub fn download_range( &self, gl: &Context, offset: usize, count: usize, ) -> Vec<T>
Download a sub-range [offset..offset+count) of elements.
Sourcepub fn resize(&mut self, gl: &Context, new_capacity: usize)
pub fn resize(&mut self, gl: &Context, new_capacity: usize)
Resize the buffer to a new capacity. Existing data is lost.
Sourcepub fn resize_preserve(&mut self, gl: &Context, new_capacity: usize)
pub fn resize_preserve(&mut self, gl: &Context, new_capacity: usize)
Resize the buffer, preserving existing data up to min(old_len, new_capacity).
Sourcepub fn barrier(&self, gl: &Context, barrier_type: BufferBarrierType)
pub fn barrier(&self, gl: &Context, barrier_type: BufferBarrierType)
Issue a memory barrier for this buffer.
Sourcepub fn handle(&self) -> BufferHandle
pub fn handle(&self) -> BufferHandle
Raw buffer handle.
Auto Trait Implementations§
impl<T> Freeze for TypedBuffer<T>
impl<T> RefUnwindSafe for TypedBuffer<T>where
T: RefUnwindSafe,
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> UnsafeUnpin for TypedBuffer<T>
impl<T> UnwindSafe for TypedBuffer<T>where
T: UnwindSafe,
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
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.