BBMOD_DynamicBatch

A constructor defined in BBMOD_DynamicBatch.gml

Implements BBMOD_IDestructible

new BBMOD_DynamicBatch([_model[, _size[, _slotsPerInstance]]])

Description

A dynamic batch is a structure that allows you to render multiple instances of a single model at once, each with its own position, scale and rotation. Compared to BBMOD_Model.submit, this drastically reduces draw calls and increases performance, but requires more memory. Number of model instances per batch is also affected by maximum number of uniforms that a vertex shader can accept.

Arguments

Name Type Description
_model Struct.BBMOD_Model The model to create a dynamic batch of.
_size Real Number of model instances in the batch. Default value is 32.
_slotsPerInstance Real Number of slots that each instance takes in the data array. Default value is 12.

Properties

Name Description
Batch The batched model.
BatchLength Total length of batch data array for a single draw call.
DataWriter A function that writes instance data into the batch data array. It must take the instance, array and starting index as arguments! Defaults to BBMOD_DynamicBatch.default_fn.
InstanceCount Number of instances currently added to the dynamic batch.
Model A model that is being batched.
Size Number of model instances in the batch.
SlotsPerInstance Number of slots that each instance takes in the data array.

Methods

Name Description
add_instance Adds an instance to the dynamic batch.
default_fn The default data writer function. Uses instance's variables x, y, z for position, image_xscale for uniform scale and image_angle for rotation around the z axis.
destroy Frees memory used by the struct.
freeze Freezes the dynamic batch. This makes it render faster.
remove_instance Removes an instance from the dynamic batch.
render Enqueues the dynamic batch for rendering.
render_object Enqueues all instances of an object for rendering in batches of BBMOD_DynamicBatch.size.
submit Immediately submits the dynamic batch for rendering.
submit_object Immediately submits all instances of an object for rendering in batches of BBMOD_DynamicBatch.size.
update_instance Updates batch data for given instance.

Example

Following code renders all instances of a car object in batches of 64.

/// @desc Create event
modCar = new BBMOD_Model("Car.bbmod");
matCar = new BBMOD_DefaultMaterial(BBMOD_ShDefaultBatched,
    sprite_get_texture(SprCar, 0));
carBatch = new BBMOD_DynamicBatch(modCar, 64);

/// @desc Draw event
carBatch.render_object(OCar, matCar);

See also

BBMOD_StaticBatch

Do you find this page helpful?

Copyright © 2024, BlueBurn. Built on January 21, 2024 using GMDoc.