pub struct MeshAllocator { /* private fields */ }Expand description
Manages the assignment of mesh data to GPU buffers.
The Bevy renderer tries to pack vertex and index data for multiple meshes together so that multiple meshes can be drawn back-to-back without any rebinding. This resource manages these buffers.
The MeshAllocatorSettings allows you to tune the behavior of the
allocator for better performance with your use case. Most applications won’t
need to change the settings from their default values.
Implementations§
Source§impl MeshAllocator
impl MeshAllocator
Sourcepub fn mesh_vertex_slice(
&self,
mesh_id: &AssetId<Mesh>,
) -> Option<MeshBufferSlice<'_>>
pub fn mesh_vertex_slice( &self, mesh_id: &AssetId<Mesh>, ) -> Option<MeshBufferSlice<'_>>
Returns the buffer and range within that buffer of the vertex data for the mesh with the given ID.
If the mesh wasn’t allocated, returns None.
Sourcepub fn mesh_index_slice(
&self,
mesh_id: &AssetId<Mesh>,
) -> Option<MeshBufferSlice<'_>>
pub fn mesh_index_slice( &self, mesh_id: &AssetId<Mesh>, ) -> Option<MeshBufferSlice<'_>>
Returns the buffer and range within that buffer of the index data for the mesh with the given ID.
If the mesh has no index data or wasn’t allocated, returns None.
Sourcepub fn mesh_slabs(&self, mesh_id: &AssetId<Mesh>) -> Option<MeshSlabs>
pub fn mesh_slabs(&self, mesh_id: &AssetId<Mesh>) -> Option<MeshSlabs>
Returns the IDs of the vertex buffer and index buffer respectively for the mesh with the given ID.
If the mesh wasn’t allocated, or has no index data in the case of the index buffer, the corresponding element in the returned tuple will be None.
Sourcepub fn index_allocation_count(&self) -> usize
pub fn index_allocation_count(&self) -> usize
Returns the number of index allocations that this mesh allocator manages.
Methods from Deref<Target = SlabAllocator<MeshSlabItem>>§
Sourcepub fn stage_allocation(&mut self) -> AllocationStage<'_, I>
pub fn stage_allocation(&mut self) -> AllocationStage<'_, I>
Creates an AllocationStage, enabling batched allocation of objects
in this slab.
Allocation of objects in the slab requires calling this function,
calling AllocationStage::allocate on the resulting
AllocationStage, and finally calling AllocationStage::commit.
Grouping allocations into a batch, preferably at most one per frame, is
the most efficient way to perform many allocations at once.
Sourcepub fn stage_deallocation(&mut self) -> DeallocationStage<'_, I>
pub fn stage_deallocation(&mut self) -> DeallocationStage<'_, I>
Creates a DeallocationStage, enabling batched deallocation.
Deallocation of objects in the slab requires calling this function,
calling DeallocationStage::free on the resulting
DeallocationStage, and finally calling
DeallocationStage::commit. Grouping deallocations into a batch,
preferably at most one per frame, is the most efficient way to perform
many deallocations at once.
Sourcepub fn buffer_for_slab(&self, slab_id: SlabId<I>) -> Option<&Buffer>
pub fn buffer_for_slab(&self, slab_id: SlabId<I>) -> Option<&Buffer>
Returns the GPU buffer corresponding to the slab with the given ID if that slab has been uploaded to the GPU.
Sourcepub fn slab_allocation_slice(
&self,
key: &I::Key,
slab_id: SlabId<I>,
) -> Option<SlabAllocationBufferSlice<'_, I>>
pub fn slab_allocation_slice( &self, key: &I::Key, slab_id: SlabId<I>, ) -> Option<SlabAllocationBufferSlice<'_, I>>
Given a slab and the key of data located with it, returns the buffer and range of that data within the slab.
Sourcepub fn slab_count(&self) -> usize
pub fn slab_count(&self) -> usize
Get the number of allocated slabs
Sourcepub fn slabs_size(&self) -> u64
pub fn slabs_size(&self) -> u64
Get the total size of all allocated slabs
Sourcepub fn copy_element_data(
&mut self,
key: &I::Key,
len: usize,
fill_data: impl Fn(WriteOnly<'_, [u8]>),
render_device: &RenderDevice,
render_queue: &RenderQueue,
)
pub fn copy_element_data( &mut self, key: &I::Key, len: usize, fill_data: impl Fn(WriteOnly<'_, [u8]>), render_device: &RenderDevice, render_queue: &RenderQueue, )
Copies data into an allocated slab.
len specifies the size of the data to be copied in bytes. The given
fill_data callback is expected to write the data into the given slice;
this callback approach avoids a copy.
Trait Implementations§
Source§impl Component for MeshAllocator
impl Component for MeshAllocator
Source§const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet
const STORAGE_TYPE: StorageType = bevy_ecs::component::StorageType::SparseSet
Source§type Mutability = Mutable
type Mutability = Mutable
Component<Mutability = Mutable>,
while immutable components will instead have Component<Mutability = Immutable>. Read moreSource§fn register_required_components(
_requiree: ComponentId,
required_components: &mut RequiredComponentsRegistrator<'_, '_>,
)
fn register_required_components( _requiree: ComponentId, required_components: &mut RequiredComponentsRegistrator<'_, '_>, )
Source§fn clone_behavior() -> ComponentCloneBehavior
fn clone_behavior() -> ComponentCloneBehavior
Source§fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
fn relationship_accessor() -> Option<ComponentRelationshipAccessor<Self>>
ComponentRelationshipAccessor required for working with relationships in dynamic contexts. Read moreSource§fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_add() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_insert() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_discard() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_remove() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
fn on_despawn() -> Option<for<'w> fn(DeferredWorld<'w>, HookContext)>
Source§fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
fn map_entities<E>(_this: &mut Self, _mapper: &mut E)where
E: EntityMapper,
EntityMapper. This is used to remap entities in contexts like scenes and entity cloning.
When deriving Component, this is populated by annotating fields containing entities with #[entities] Read moreSource§impl Deref for MeshAllocator
impl Deref for MeshAllocator
Source§type Target = SlabAllocator<MeshSlabItem>
type Target = SlabAllocator<MeshSlabItem>
Source§impl DerefMut for MeshAllocator
impl DerefMut for MeshAllocator
Source§impl FromWorld for MeshAllocator
impl FromWorld for MeshAllocator
Source§fn from_world(world: &mut World) -> Self
fn from_world(world: &mut World) -> Self
Self using data from the given World.impl Resource for MeshAllocator
Auto Trait Implementations§
impl Freeze for MeshAllocator
impl !RefUnwindSafe for MeshAllocator
impl Send for MeshAllocator
impl Sync for MeshAllocator
impl Unpin for MeshAllocator
impl UnsafeUnpin for MeshAllocator
impl !UnwindSafe for MeshAllocator
Blanket Implementations§
Source§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
Source§fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<GpuImage>) -> U
T ShaderType for self. When used in AsBindGroup
derives, it is safe to assume that all images in self exist.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<C> Bundle for Cwhere
C: Component,
impl<C> Bundle for Cwhere
C: Component,
fn component_ids( components: &mut ComponentsRegistrator<'_>, ) -> impl Iterator<Item = ComponentId> + use<C>
Source§fn get_component_ids(
components: &Components,
) -> impl Iterator<Item = Option<ComponentId>>
fn get_component_ids( components: &Components, ) -> impl Iterator<Item = Option<ComponentId>>
Source§impl<C> BundleFromComponents for Cwhere
C: Component,
impl<C> BundleFromComponents for Cwhere
C: Component,
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>, which can then be
downcast into Box<dyn 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>, which 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> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<C> DynamicBundle for Cwhere
C: Component,
impl<C> DynamicBundle for Cwhere
C: Component,
Source§unsafe fn get_components(
ptr: MovingPtr<'_, C>,
func: &mut impl FnMut(StorageType, OwningPtr<'_>),
) -> <C as DynamicBundle>::Effect
unsafe fn get_components( ptr: MovingPtr<'_, C>, func: &mut impl FnMut(StorageType, OwningPtr<'_>), ) -> <C as DynamicBundle>::Effect
Source§unsafe fn apply_effect(
_ptr: MovingPtr<'_, MaybeUninit<C>>,
_entity: &mut EntityWorldMut<'_>,
)
unsafe fn apply_effect( _ptr: MovingPtr<'_, MaybeUninit<C>>, _entity: &mut EntityWorldMut<'_>, )
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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