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.
Name | Type | Description |
---|---|---|
renderer | PIXI.Renderer |
The renderer this works for. |
Summary
Properties from AbstractBatchRenderer
Array<PIXI.BatchDrawCall> |
|
Array<PIXI.BatchTextureArray> |
|
number |
|
number |
|
PIXI.State |
The WebGL state in which this renderer will work. |
Array<PIXI.ViewableBuffer> |
|
Array<PIXI.DisplayObject> |
|
Array<PIXI.BaseTexture> |
|
number |
Number of elements that are buffered and are waiting to be flushed. |
number |
|
Array<Uint16Array> |
|
number |
Total count of all indices used by the currently buffered objects. |
PIXI.Shader |
This shader is generated by |
number |
Total count of all vertices used by the currently buffered objects. |
object |
|
PIXI.BatchShaderGenerator |
|
number |
|
Methods from AbstractBatchRenderer
void |
|
void |
|
void |
Handles the |
void |
Destroys this |
void |
Renders the content now and empties the current batch. |
PIXI.ViewableBuffer |
|
Uint16Array |
|
void |
Makes sure that static and dynamic flush pooled objects have correct dimensions. |
void |
Handles the |
void |
|
void |
|
void |
Starts a new sprite batch. |
void |
Stops and flushes the current batch. |
Properties inherited from ObjectRenderer
PIXI.Renderer |
The renderer this manager works for. |
Public Properties
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.
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: number
Maximum number of textures that can be uploaded to
the GPU under the current context. It is initialized
properly in this.contextChange
.
size: number = settings.SPRITE_BATCH_SIZE * 4
The number of bufferable objects before a flush occurs automatically.
state: PIXI.State
The WebGL state in which this renderer will work.
Protected Properties
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.
protected _bufferedElements: Array<PIXI.DisplayObject>
Buffer of objects that are yet to be rendered.
protected _bufferedTextures: Array<PIXI.BaseTexture>
Data for texture batch builder, helps to save a bit of CPU on a pass.
protected _bufferSize: number
Number of elements that are buffered and are waiting to be flushed.
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.
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.
protected _indexCount: number
Total count of all indices used by the currently buffered objects.
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.
protected _vertexCount: number
Total count of all vertices used by the currently buffered objects.
protected geometryClass: object = PIXI.BatchGeometry
The class that represents the geometry of objects that are going to be batched with this.
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.
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(texArray: PIXI.BatchTextureArray) → {void}
Bind textures for current rendering
Name | Type | Description |
---|---|---|
texArray | PIXI.BatchTextureArray |
Type | Description |
---|---|
void |
buildDrawCalls(texArray: PIXI.BatchTextureArray, start: number, finish: number) → {void}
Populating drawcalls for rendering
Name | Type | Description |
---|---|---|
texArray | PIXI.BatchTextureArray | |
start | number | |
finish | number |
Type | Description |
---|---|
void |
contextChange() → {void}
Handles the contextChange
signal.
It calculates this.MAX_TEXTURES
and allocating the packed-geometry object pool.
Type | Description |
---|---|
void |
destroy() → {void}
Destroys this AbstractBatchRenderer
. It cannot be used again.
Type | Description |
---|---|
void |
flush() → {void}
Renders the content now and empties the current batch.
Type | Description |
---|---|
void |
getAttributeBuffer(size: number) → {PIXI.ViewableBuffer}
Fetches an attribute buffer from this._aBuffers
that can hold atleast size
floats.
Name | Type | Description |
---|---|---|
size | number |
minimum capacity required |
Type | Description |
---|---|
PIXI.ViewableBuffer |
|
getIndexBuffer(size: number) → {Uint16Array}
Fetches an index buffer from this._iBuffers
that can
have at least size
capacity.
Name | Type | Description |
---|---|---|
size | number |
minimum required capacity |
Type | Description |
---|---|
Uint16Array |
|
initFlushBuffers() → {void}
Makes sure that static and dynamic flush pooled objects have correct dimensions.
Type | Description |
---|---|
void |
onPrerender() → {void}
Handles the prerender
signal. It ensures that flushes start from the first geometry object again.
Type | Description |
---|---|
void |
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.
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 |
Type | Description |
---|---|
void |
render(element: PIXI.DisplayObject) → {void}
Buffers the "batchable" object. It need not be rendered immediately.
Name | Type | Description |
---|---|---|
element | PIXI.DisplayObject |
the element to render when using this renderer |
Type | Description |
---|---|
void |
start() → {void}
Starts a new sprite batch.
Type | Description |
---|---|
void |
stop() → {void}
Stops and flushes the current batch.
Type | Description |
---|---|
void |