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

source

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.

source

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.

source

pub fn set(&mut self, instances: impl IntoIterator<Item = DrawParam>)

Resets all the instance data to a set of DrawParam.

source

pub fn push(&mut self, instance: DrawParam)

Pushes a new instance onto the end.

source

pub fn update(&mut self, index: u32, instance: DrawParam)

Updates an existing instance at a given index, if it is valid.

source

pub fn clear(&mut self)

Clears all instance data.

source

pub fn is_dirty(&self) -> bool

Returns whether the instance data has been changed without being flushed (i.e., uploaded to the GPU).

source

pub fn instances(&self) -> &[DrawParam]

Returns an immutable slice of all the instance data in this InstanceArray.

source

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.

source

pub fn image(&self) -> Image

Returns this InstanceArray’s associated image.

source

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.

source

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().

Trait Implementations§

source§

impl Debug for InstanceArray

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Drawable for InstanceArray

source§

fn draw(&self, canvas: &mut Canvas, param: impl Into<DrawParam>)

Draws the drawable onto the canvas.
source§

fn dimensions(&self, gfx: &impl Has<GraphicsContext>) -> Option<Rect>

Returns a bounding box in the form of a Rect. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

source§

impl<T> Has<T> for T

source§

fn retrieve(&self) -> &T

Method to retrieve the context type.
source§

impl<T> HasMut<T> for T

source§

fn retrieve_mut(&mut self) -> &mut T

Method to retrieve the context type as mutable.
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<F, T> IntoSample<T> for Fwhere T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T, U> ToSample<U> for Twhere U: FromSample<T>,

§

fn to_sample_(self) -> U

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<S, T> Duplex<S> for Twhere T: FromSample<S> + ToSample<S>,