pub struct InstanceBuffer<K: BufferLayout> {
pub unprocessed: Vec<Vec<OrderedIndex>>,
pub buffers: Vec<Option<InstanceDetails>>,
pub clipped_buffers: Vec<Vec<ClippedInstanceDetails>>,
pub buffer: Buffer<K>,
pub layer_size: usize,
/* private fields */
}Expand description
Instance buffer holds all the Details to render with instances with a Static VBO. This stores and handles the orders of all rendered objects to try and reduce the amount of GPU uploads we make.
Fields§
§unprocessed: Vec<Vec<OrderedIndex>>Unprocessed Buffer Data.
buffers: Vec<Option<InstanceDetails>>Buffers ready to Render
clipped_buffers: Vec<Vec<ClippedInstanceDetails>>Clipped Buffers ready to Render.
buffer: Buffer<K>The main Buffer within GPU memory.
layer_size: usizeSize each Buffer Layer gets allocated to for Future buffers.
Implementations§
Source§impl<K: BufferLayout> InstanceBuffer<K>
impl<K: BufferLayout> InstanceBuffer<K>
Sourcepub fn create_buffer(
gpu_device: &GpuDevice,
data: &[u8],
layer_size: usize,
) -> Self
pub fn create_buffer( gpu_device: &GpuDevice, data: &[u8], layer_size: usize, ) -> Self
Used to create a InstanceBuffer.
Only use this for creating a reusable buffer.
§Arguments
- data: The contents to Create the Buffer with.
- layer_size: The capacity allocated for any future elements per new Buffer Layer.
Sourcepub fn add_buffer_store(
&mut self,
renderer: &GpuRenderer,
index: OrderedIndex,
buffer_layer: usize,
)
pub fn add_buffer_store( &mut self, renderer: &GpuRenderer, index: OrderedIndex, buffer_layer: usize, )
Adds the Buffer to the unprocessed list so it can be processed in InstanceBuffer::finalize
This must be called in order to Render the Object.
§Arguments
- index: The Order Index of the Object we want to render.
- buffer_layer: The Buffer Layer we want to add this Object too.
Sourcepub fn finalize(&mut self, renderer: &mut GpuRenderer)
pub fn finalize(&mut self, renderer: &mut GpuRenderer)
Processes all unprocessed listed buffers and uploads any changes to the gpu
This must be called after InstanceBuffer::add_buffer_store in order to Render the Objects.
Sourcepub fn new(gpu_device: &GpuDevice, layer_size: usize) -> Self
pub fn new(gpu_device: &GpuDevice, layer_size: usize) -> Self
Creates an InstanceBuffer with a default buffer size.
Buffer size is based on the initial crate::BufferLayout::default_buffer length.
§Arguments
- layer_size: The capacity allocated for any future elements per new Buffer Layer.
Sourcepub fn is_clipped(&self) -> bool
pub fn is_clipped(&self) -> bool
Returns if the buffer is clipped or not to deturmine if you should use buffers or clipped_buffers.
Sourcepub fn set_as_clipped(&mut self)
pub fn set_as_clipped(&mut self)
Sets the Buffer into Clipping mode. This will Produce a clipped_buffers instead of the buffers which will still be layered but a Vector of individual objects will Exist rather than a grouped object per layer. Will make it less Efficient but allows Bounds Clipping.
Sourcepub fn instances(&self, bounds: Option<Range<u64>>) -> BufferSlice<'_>
pub fn instances(&self, bounds: Option<Range<u64>>) -> BufferSlice<'_>
Returns wgpu::BufferSlice of vertices.
bounds is used to set a specific Range if needed.
If bounds is None then range is 0..vertex_count.
Sourcepub fn with_capacity(
gpu_device: &GpuDevice,
capacity: usize,
layer_size: usize,
) -> Self
pub fn with_capacity( gpu_device: &GpuDevice, capacity: usize, layer_size: usize, ) -> Self
Creates an InstanceBuffer with a buffer capacity.
Buffer size is based on the initial crate::BufferLayout::default_buffer length.
§Arguments
- capacity: The capacity of the Buffers instances for future allocation.
- layer_size: The capacity allocated for any future elements per new Buffer Layer.
Auto Trait Implementations§
impl<K> !Freeze for InstanceBuffer<K>
impl<K> !RefUnwindSafe for InstanceBuffer<K>
impl<K> Send for InstanceBuffer<K>where
K: Send,
impl<K> Sync for InstanceBuffer<K>where
K: Sync,
impl<K> Unpin for InstanceBuffer<K>where
K: Unpin,
impl<K> !UnwindSafe for InstanceBuffer<K>
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.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>
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 more