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
impl MeshBatch
Sourcepub fn new(mesh: Mesh) -> GameResult<MeshBatch>
pub fn new(mesh: Mesh) -> GameResult<MeshBatch>
Creates a new mesh batch.
Takes ownership of the Mesh.
Sourcepub fn clear(&mut self)
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.
Sourcepub fn get_instance_params(&self) -> &[DrawParam]
pub fn get_instance_params(&self) -> &[DrawParam]
Returns a reference to mesh instances
Sourcepub fn get_instance_params_mut(&mut self) -> &mut [DrawParam]
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.
Sourcepub fn add<P>(&mut self, param: P) -> MeshIdx
pub fn add<P>(&mut self, param: P) -> MeshIdx
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.
Sourcepub fn set<P>(&mut self, handle: MeshIdx, param: P) -> GameResult
pub fn set<P>(&mut self, handle: MeshIdx, param: P) -> GameResult
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.
Sourcepub fn set_range<P>(
&mut self,
first_handle: MeshIdx,
params: &[P],
) -> GameResult
pub fn set_range<P>( &mut self, first_handle: MeshIdx, params: &[P], ) -> GameResult
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.
Sourcepub fn flush_range(
&mut self,
_ctx: &mut Context,
quad_ctx: &mut GraphicsContext,
first_handle: MeshIdx,
count: usize,
) -> GameResult
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.
Sourcepub fn flush(
&mut self,
ctx: &mut Context,
quad_ctx: &mut GraphicsContext,
) -> GameResult
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.
Sourcepub fn draw(
&mut self,
ctx: &mut Context,
quad_ctx: &mut GraphicsContext,
param: DrawParam,
) -> GameResult
pub fn draw( &mut self, ctx: &mut Context, quad_ctx: &mut GraphicsContext, param: DrawParam, ) -> GameResult
Draws the drawable onto the rendering target.
Sourcepub fn dimensions(&self, ctx: &mut Context) -> Option<Rect>
pub fn dimensions(&self, ctx: &mut Context) -> Option<Rect>
Returns a bounding box in the form of a Rect.
Sourcepub fn set_blend_mode(&mut self, mode: Option<BlendMode>)
pub fn set_blend_mode(&mut self, mode: Option<BlendMode>)
Sets the blend mode to be used when drawing this drawable.
Sourcepub fn blend_mode(&self) -> Option<BlendMode>
pub fn blend_mode(&self) -> Option<BlendMode>
Gets the blend mode to be used when drawing this drawable.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for MeshBatch
impl RefUnwindSafe for MeshBatch
impl Send for MeshBatch
impl Sync for MeshBatch
impl Unpin for MeshBatch
impl UnwindSafe for MeshBatch
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<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
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