PIXI.AbstractBatchRenderer

class AbstractBatchRenderer extends PIXI.ObjectRenderer

Renderer dedicated to drawing and batching sprites.

This is the default batch renderer. It buffers objects with texture-based geometries and renders them in batches. It uploads multiple textures to the GPU to reduce to the number of draw calls.

Constructor


new PIXI.AbstractBatchRenderer(renderer: PIXI.Renderer) → {}

This will hook onto the renderer's contextChange and prerender signals.

Parameters:
Name Type Description
renderer PIXI.Renderer

The renderer this works for.

Summary


Properties from AbstractBatchRenderer

Array<PIXI.BatchDrawCall>
static _drawCallPool
Array<PIXI.BatchTextureArray>
static _textureArrayPool
number
MAX_TEXTURES
number
size = settings.SPRITE_BATCH_SIZE * 4
PIXI.State
state

The WebGL state in which this renderer will work.

Array<PIXI.ViewableBuffer>
protected _aBuffers
Array<PIXI.DisplayObject>
protected _bufferedElements
Array<PIXI.BaseTexture>
protected _bufferedTextures
number
protected _bufferSize

Number of elements that are buffered and are waiting to be flushed.

number
protected _flushId
Array<Uint16Array>
protected _iBuffers
number
protected _indexCount

Total count of all indices used by the currently buffered objects.

PIXI.Shader
protected _shader

This shader is generated by this.shaderGenerator.

number
protected _vertexCount

Total count of all vertices used by the currently buffered objects.

object
protected geometryClass = PIXI.BatchGeometry
PIXI.BatchShaderGenerator
protected shaderGenerator
number
protected vertexSize

Methods from AbstractBatchRenderer

void
bindAndClearTexArray(texArray: PIXI.BatchTextureArray)
void
buildDrawCalls(texArray: PIXI.BatchTextureArray, start: number, finish: number)
void
contextChange()

Handles the contextChange signal.

void
destroy()

Destroys this AbstractBatchRenderer. It cannot be used again.

void
flush()

Renders the content now and empties the current batch.

PIXI.ViewableBuffer
getAttributeBuffer(size: number)
Uint16Array
getIndexBuffer(size: number)
void
initFlushBuffers()

Makes sure that static and dynamic flush pooled objects have correct dimensions.

void
onPrerender()

Handles the prerender signal. It ensures that flushes start from the first geometry object again.

void
packInterleavedGeometry(element: PIXI.DisplayObject, attributeBuffer: PIXI.ViewableBuffer, indexBuffer: Uint16Array, aIndex: number, iIndex: number)
void
render(element: PIXI.DisplayObject)
void
start()

Starts a new sprite batch.

void
stop()

Stops and flushes the current batch.

Properties inherited from ObjectRenderer

PIXI.Renderer
protected renderer

The renderer this manager works for.

Public Properties


_drawCallPool AbstractBatchRenderer.ts:700
static _drawCallPool: Array<PIXI.BatchDrawCall>

Pool of BatchDrawCall objects that flush used to create "batches" of the objects being rendered.

These are never re-allocated again. Shared between all batch renderers because it can be only one "flush" working at the moment.

_textureArrayPool AbstractBatchRenderer.ts:710
static _textureArrayPool: Array<PIXI.BatchTextureArray>

Pool of BatchDrawCall objects that flush used to create "batches" of the objects being rendered.

These are never re-allocated again. Shared between all batch renderers because it can be only one "flush" working at the moment.

MAX_TEXTURES AbstractBatchRenderer.ts:57
MAX_TEXTURES: number

Maximum number of textures that can be uploaded to the GPU under the current context. It is initialized properly in this.contextChange.

See: PIXI.AbstractBatchRenderer#contextChange
size AbstractBatchRenderer.ts:50
size: number = settings.SPRITE_BATCH_SIZE * 4

The number of bufferable objects before a flush occurs automatically.

state AbstractBatchRenderer.ts:47
state: PIXI.State

The WebGL state in which this renderer will work.

Protected Properties


_aBuffers AbstractBatchRenderer.ts:142
protected _aBuffers: Array<PIXI.ViewableBuffer>

Pool of ViewableBuffer objects that are sorted in order of increasing size. The flush method uses the buffer with the least size above the amount it requires. These are used for passing attributes.

The first buffer has a size of 8; each subsequent buffer has double capacity of its previous.

See: PIXI.AbstractBatchRenderer#getAttributeBuffer
_bufferedElements AbstractBatchRenderer.ts:107
protected _bufferedElements: Array<PIXI.DisplayObject>

Buffer of objects that are yet to be rendered.

_bufferedTextures AbstractBatchRenderer.ts:113
protected _bufferedTextures: Array<PIXI.BaseTexture>

Data for texture batch builder, helps to save a bit of CPU on a pass.

_bufferSize AbstractBatchRenderer.ts:119
protected _bufferSize: number

Number of elements that are buffered and are waiting to be flushed.

_flushId AbstractBatchRenderer.ts:130
protected _flushId: number

A flush may occur multiple times in a single frame. On iOS devices or when settings.CAN_UPLOAD_SAME_BUFFER is false, the batch renderer does not upload data to the same WebGLBuffer for performance reasons.

This is the index into packedGeometries that points to geometry holding the most recent buffers.

_iBuffers AbstractBatchRenderer.ts:155
protected _iBuffers: Array<Uint16Array>

Pool of Uint16Array objects that are sorted in order of increasing size. The flush method uses the buffer with the least size above the amount it requires. These are used for passing indices.

The first buffer has a size of 12; each subsequent buffer has double capacity of its previous.

See: PIXI.AbstractBatchRenderer#getIndexBuffer
_indexCount AbstractBatchRenderer.ts:104
protected _indexCount: number

Total count of all indices used by the currently buffered objects.

_shader AbstractBatchRenderer.ts:122
protected _shader: PIXI.Shader

This shader is generated by this.shaderGenerator.

It is generated specifically to handle the required number of textures being batched together.

_vertexCount AbstractBatchRenderer.ts:101
protected _vertexCount: number

Total count of all vertices used by the currently buffered objects.

geometryClass AbstractBatchRenderer.ts:79
protected geometryClass: object = PIXI.BatchGeometry

The class that represents the geometry of objects that are going to be batched with this.

shaderGenerator AbstractBatchRenderer.ts:66
protected shaderGenerator: PIXI.BatchShaderGenerator

This is used to generate a shader that can color each vertex based on a aTextureId attribute that points to an texture in uSampler.

This enables the objects with different textures to be drawn in the same draw call.

You can customize your shader by creating your custom shader generator.

vertexSize AbstractBatchRenderer.ts:87
protected vertexSize: number

Size of data being buffered per vertex in the attribute buffers (in floats). By default, the batch-renderer plugin uses 6:

aVertexPosition 2
aTextureCoords 2
aColor 1
aTextureId 1

Public Methods


bindAndClearTexArray AbstractBatchRenderer.ts:446
bindAndClearTexArray(texArray: PIXI.BatchTextureArray) → {void}

Bind textures for current rendering

Parameters:
Name Type Description
texArray PIXI.BatchTextureArray
Returns:
Type Description
void
buildDrawCalls AbstractBatchRenderer.ts:385
buildDrawCalls(texArray: PIXI.BatchTextureArray, start: number, finish: number) → {void}

Populating drawcalls for rendering

Parameters:
Name Type Description
texArray PIXI.BatchTextureArray
start number
finish number
Returns:
Type Description
void
contextChange AbstractBatchRenderer.ts:233
contextChange() → {void}

Handles the contextChange signal.

It calculates this.MAX_TEXTURES and allocating the packed-geometry object pool.

Returns:
Type Description
void
destroy AbstractBatchRenderer.ts:567
destroy() → {void}

Destroys this AbstractBatchRenderer. It cannot be used again.

Returns:
Type Description
void
flush AbstractBatchRenderer.ts:521
flush() → {void}

Renders the content now and empties the current batch.

Returns:
Type Description
void
getAttributeBuffer AbstractBatchRenderer.ts:595
getAttributeBuffer(size: number) → {PIXI.ViewableBuffer}

Fetches an attribute buffer from this._aBuffers that can hold atleast size floats.

Parameters:
Name Type Description
size number

minimum capacity required

Returns:
Type Description
PIXI.ViewableBuffer
  • buffer than can hold atleast size floats
getIndexBuffer AbstractBatchRenderer.ts:622
getIndexBuffer(size: number) → {Uint16Array}

Fetches an index buffer from this._iBuffers that can have at least size capacity.

Parameters:
Name Type Description
size number

minimum required capacity

Returns:
Type Description
Uint16Array
  • buffer that can fit size indices.
initFlushBuffers AbstractBatchRenderer.ts:271
initFlushBuffers() → {void}

Makes sure that static and dynamic flush pooled objects have correct dimensions.

Returns:
Type Description
void
onPrerender AbstractBatchRenderer.ts:297
onPrerender() → {void}

Handles the prerender signal. It ensures that flushes start from the first geometry object again.

Returns:
Type Description
void
packInterleavedGeometry AbstractBatchRenderer.ts:650
packInterleavedGeometry(element: PIXI.DisplayObject, attributeBuffer: PIXI.ViewableBuffer, indexBuffer: Uint16Array, aIndex: number, iIndex: number) → {void}

Takes the four batching parameters of element, interleaves and pushes them into the batching attribute/index buffers given.

It uses these properties: vertexData uvs, textureId and indicies. It also uses the "tint" of the base-texture, if present.

Parameters:
Name Type Description
element PIXI.DisplayObject

element being rendered

attributeBuffer PIXI.ViewableBuffer

attribute buffer.

indexBuffer Uint16Array

index buffer

aIndex number

number of floats already in the attribute buffer

iIndex number

number of indices already in indexBuffer

Returns:
Type Description
void
render AbstractBatchRenderer.ts:303
render(element: PIXI.DisplayObject) → {void}

Buffers the "batchable" object. It need not be rendered immediately.

Parameters:
Name Type Description
element PIXI.DisplayObject

the element to render when using this renderer

Returns:
Type Description
void
start AbstractBatchRenderer.ts:545
start() → {void}

Starts a new sprite batch.

Returns:
Type Description
void
stop AbstractBatchRenderer.ts:561
stop() → {void}

Stops and flushes the current batch.

Returns:
Type Description
void

Powered by webdoc!