Struct ggez::graphics::InstanceArray
source · pub struct InstanceArray { /* private fields */ }
Expand description
Array of instances for fast rendering of many meshes.
Traditionally known as a “batch”.
Implementations§
source§impl InstanceArray
impl InstanceArray
sourcepub fn new(
gfx: &impl Has<GraphicsContext>,
image: impl Into<Option<Image>>
) -> Self
pub fn new( gfx: &impl Has<GraphicsContext>, image: impl Into<Option<Image>> ) -> Self
Creates a new InstanceArray
capable of storing up to n-capacity
instances
(this can be changed and is resized automatically when needed).
If image
is None
, a 1x1 white image will be used which can be used to draw solid rectangles.
This constructor is unordered
meaning instances will be drawn by their push/index order. Use InstanceArray::new_ordered
to order by z-value.
sourcepub fn new_ordered(
gfx: &impl Has<GraphicsContext>,
image: impl Into<Option<Image>>
) -> Self
pub fn new_ordered( gfx: &impl Has<GraphicsContext>, image: impl Into<Option<Image>> ) -> Self
See InstanceArray::new
for details.
This constructor is ordered
meaning instances will be drawn by their z-value at a slight performance cost. Use InstanceArray::new
to order by index.
sourcepub fn set(&mut self, instances: impl IntoIterator<Item = DrawParam>)
pub fn set(&mut self, instances: impl IntoIterator<Item = DrawParam>)
Resets all the instance data to a set of DrawParam
.
sourcepub fn update(&mut self, index: u32, instance: DrawParam)
pub fn update(&mut self, index: u32, instance: DrawParam)
Updates an existing instance at a given index, if it is valid.
sourcepub fn is_dirty(&self) -> bool
pub fn is_dirty(&self) -> bool
Returns whether the instance data has been changed without being flushed (i.e., uploaded to the GPU).
sourcepub fn instances(&self) -> &[DrawParam]
pub fn instances(&self) -> &[DrawParam]
Returns an immutable slice of all the instance data in this InstanceArray
.
sourcepub fn resize(&mut self, gfx: &impl Has<GraphicsContext>, new_capacity: usize)
pub fn resize(&mut self, gfx: &impl Has<GraphicsContext>, new_capacity: usize)
Changes the capacity of this InstanceArray
while preserving instances.
If new_capacity
is less than the len
, the instances will be truncated.
Panics
Panics if new_capacity
is 0.
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of instances this InstanceArray
is capable of holding.
This number was specified when creating the InstanceArray
, or if the InstanceArray
was automatically resized, the greatest length of instances.
sourcepub fn dimensions_meshed(
&self,
gfx: &impl Has<GraphicsContext>,
mesh: &Mesh
) -> Option<Rect>
pub fn dimensions_meshed( &self, gfx: &impl Has<GraphicsContext>, mesh: &Mesh ) -> Option<Rect>
This is equivalent to <InstanceArray as Drawable>::dimensions()
(see Drawable::dimensions()
), but with a mesh taken into account.
Essentially, consider <InstanceArray as Drawable>::dimensions()
to be the bounds when the InstanceArray
is drawn with canvas.draw()
,
and consider InstanceArray::dimensions_meshed()
to be the bounds when the InstanceArray
is drawn with canvas.draw_instanced_mesh()
.