MeshBatch

Struct MeshBatch 

Source
pub struct MeshBatch { /* private fields */ }
Expand description

Mesh that will be rendered with hardware instancing. Use this when you have a lot of similar geometry which does not move around often.

Implementations§

Source§

impl MeshBatch

Source

pub fn new(mesh: Mesh) -> GameResult<MeshBatch>

Creates a new mesh batch.

Takes ownership of the Mesh.

Source

pub fn clear(&mut self)

Removes all instances from the batch.

Calling this invalidates the entire buffer, however this will not automatically deallocate graphics card memory or flush the buffer.

Source

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

Returns a reference to mesh instances

Source

pub fn get_instance_params_mut(&mut self) -> &mut [DrawParam]

Returns a mutable reference to mesh instances.

Please note that manually altering items in this slice will not automatically invalidate the buffer, you will have to manually call flush() or flush_range() later.

Source

pub fn add<P>(&mut self, param: P) -> MeshIdx
where P: Into<DrawParam>,

Adds a new instance to the mesh batch

Returns a handle with which to modify the instance using set()

Calling this invalidates the entire buffer and will result in flusing it on the next graphics::draw() call.

Source

pub fn set<P>(&mut self, handle: MeshIdx, param: P) -> GameResult
where P: Into<DrawParam>,

Alters an instance in the batch to use the given draw params.

Calling this invalidates the entire buffer and will result in flusing it on the next graphics::draw() call.

This might cause performance issues with large batches, to avoid this consider using flush_range to explicitly invalidate required data slice.

Source

pub fn set_range<P>( &mut self, first_handle: MeshIdx, params: &[P], ) -> GameResult
where P: Into<DrawParam> + Copy,

Alters a range of instances in the batch to use the given draw params

Calling this invalidates the entire buffer and will result in flusing it on the next graphics::draw() call.

This might cause performance issues with large batches, to avoid this consider using flush_range to explicitly invalidate required data slice.

Source

pub fn flush_range( &mut self, _ctx: &mut Context, quad_ctx: &mut GraphicsContext, first_handle: MeshIdx, count: usize, ) -> GameResult

Immediately sends specified slice of data in the batch to the graphics card.

Calling this counts as a full buffer flush, but only flushes the data within the provided range, anything outside of this range will not be touched.

Use it for updating small portions of large batches.

Source

pub fn flush( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, ) -> GameResult

Immediately sends all data in the batch to the graphics card.

In general, graphics::draw() on the MeshBatch will do this automatically when buffer contents are updated.

Source

pub fn draw( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, param: DrawParam, ) -> GameResult

Draws the drawable onto the rendering target.

Source

pub fn dimensions(&self, ctx: &mut Context) -> Option<Rect>

Returns a bounding box in the form of a Rect.

Source

pub fn set_blend_mode(&mut self, mode: Option<BlendMode>)

Sets the blend mode to be used when drawing this drawable.

Source

pub fn blend_mode(&self) -> Option<BlendMode>

Gets the blend mode to be used when drawing this drawable.

Trait Implementations§

Source§

impl Debug for MeshBatch

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where 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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

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

Source§

fn to_sample_(self) -> U

Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

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