Class: BatchGeometryFactory

.brend~BatchGeometryFactory

Factory class that generates the geometry for a whole batch by feeding on the individual display-object geometries. This factory is reusable, i.e. you can build another geometry after a build call.

Optimizations: To speed up geometry generation, this compiles an optimized packing function that pushes attributes without looping through the attribute redirects.

Default Format: If you are not using a custom draw-call issuer, then the batch geometry must have an interleaved attribute data buffer and one index buffer.

Customization: If you want to customize the batch geometry, then you must also define your draw call issuer. This is not supported by pixi-batch-render but is work-in-progress.

inBatchID Support: If you specified an inBatchID attribute in the batch-renderer, then this will support it automatically. The aggregate-uniforms pipeline doesn't need a custom geometry factory.

new BatchGeometryFactory (renderer)

Name Type Description
renderer PIXI.brend.BatchRenderer

Implements

Members

_geometryPool PIXI.Geometry protected

Batch geometries that can be reused.

See:

This lazy getter returns the geometry-merger function. This function takes one argument - the display-object to be appended to the batch - and pushes its geometry to the batch geometry.

You can overwrite this property with a custom geometry-merger function if customizing PIXI.brend.BatchGeometryFactory.

Methods

append (targetObject, batch)

Append's the display-object geometry to this batch's geometry. You must override this you need to "modify" the geometry of the display-object before merging into the composite geometry (for example, adding an ID to a special uniform)

Name Type Description
targetObject PIXI.DisplayObject
batch number

build ()PIXI.Geometry

This should wrap up the batch geometry in a PIXI.Geometry object.

Returns:
Type Description
PIXI.Geometry the generated batch geometry
Example
build(): PIXI.Geometry
{
     // Make sure you're not allocating new geometries if _geometryPool has some
     // already. (Otherwise, a memory leak will result!)
     const geom: ExampleGeometry = (this._geometryPool.pop() || new ExampleGeometry(
         // ...your arguments... //)) as ExampleGeometry;

     // Put data into geometry's buffer

     return geom;
}

getAttributeBuffer (size) protected

Allocates an attribute buffer with sufficient capacity to hold size elements.

Name Type Description
size number

getIndexBuffer (size) protected

Allocates an index buffer (Uint16Array) with sufficient capacity to hold size indices.

Name Type Description
size

init (verticesBatched, indiciesBatched)

Ensures this factory has enough space to buffer the given number of vertices and indices. This should be called before feeding display-objects from the batch.

Name Type Description
verticesBatched number
indiciesBatched number

This is used to return a batch geometry so it can be pooled and reused in a future build() call.

Name Type Description
geom PIXI.Geometry

releases back the geometry to be reused. It is expected that it is not used externally again.