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.