Skip to main content
Version: Phaser v4.0.0

BatchHandlerQuad

The primary batch rendering node in Phaser's WebGL pipeline. It draws textured quads (used by Image, Sprite, BitmapText, TileSprite, and other Game Objects) in large batches for performance. Supports multi-texturing, normal-map-based lighting, and smooth pixel art rendering. Game Objects are accumulated into a vertex buffer and flushed to the GPU in a single draw call whenever possible.

Constructor

new BatchHandlerQuad(manager, [config])

Parameters

nametypeoptionaldescription
managerPhaser.Renderer.WebGL.RenderNodes.RenderNodeManagerNoThe manager that owns this RenderNode.
configPhaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfigYesThe configuration object for this handler.

Scope: static

Extends

Phaser.Renderer.WebGL.RenderNodes.BatchHandler

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L26
Since: 4.0.0

Inherited Members

From Phaser.Renderer.WebGL.RenderNodes.BatchHandler:

From Phaser.Renderer.WebGL.RenderNodes.RenderNode:


Public Members

defaultConfig

defaultConfig: Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig

Description:

The default configuration object for this handler. This is merged with the config object passed in the constructor.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L106
Since: 4.0.0


nextRenderOptions

nextRenderOptions: object

Description:

The render options currently being built.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L76
Since: 4.0.0


renderOptions

renderOptions: object

Description:

The current render options to which the batch is built. These help define the shader.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L49
Since: 4.0.0


Inherited Methods

From Phaser.Renderer.WebGL.RenderNodes.BatchHandler:

From Phaser.Renderer.WebGL.RenderNodes.RenderNode:


Public Methods

batch

<instance> batch(currentContext, glTexture, x0, y0, x1, y1, x2, y2, x3, y3, texX, texY, texWidth, texHeight, tintMode, tintTL, tintBL, tintTR, tintBR, renderOptions, [args])

Description:

Add a quad to the batch.

For compatibility with TRIANGLE_STRIP rendering, the vertices are written into the buffer in the order:

  • Bottom-left

  • Top-left

  • Bottom-right

  • Top-right

Parameters:

nametypeoptionaldescription
currentContextPhaser.Renderer.WebGL.DrawingContextNoThe current drawing context.
glTexturePhaser.Renderer.WebGL.Wrappers.WebGLTextureWrapperNoThe texture to render.
x0numberNoThe x coordinate of the top-left corner.
y0numberNoThe y coordinate of the top-left corner.
x1numberNoThe x coordinate of the bottom-left corner.
y1numberNoThe y coordinate of the bottom-left corner.
x2numberNoThe x coordinate of the top-right corner.
y2numberNoThe y coordinate of the top-right corner.
x3numberNoThe x coordinate of the bottom-right corner.
y3numberNoThe y coordinate of the bottom-right corner.
texXnumberNoThe left u coordinate (0-1).
texYnumberNoThe top v coordinate (0-1).
texWidthnumberNoThe width of the texture (0-1).
texHeightnumberNoThe height of the texture (0-1).
tintModenumberNoThe tint mode to use.
tintTLnumberNoThe top-left tint color.
tintBLnumberNoThe bottom-left tint color.
tintTRnumberNoThe top-right tint color.
tintBRnumberNoThe bottom-right tint color.
renderOptionsPhaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerQuadRenderOptionsNoOptional render features.
args*YesAdditional arguments for subclasses.

Overrides: Phaser.Renderer.WebGL.RenderNodes.BatchHandler#batch

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L623
Since: 4.0.0


batchTextures

<instance> batchTextures(glTexture, renderOptions)

Description:

Process textures for batching. This method is called automatically by the batch method. It returns a piece of data used for various texture tasks, depending on the render options.

The texture datum may be used for texture ID or normal map rotation.

Parameters:

nametypeoptionaldescription
glTexturePhaser.Renderer.WebGL.Wrappers.WebGLTextureWrapperNoThe texture to render.
renderOptionsobjectNoThe current render options.

Returns: number - The texture datum.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L744
Since: 4.0.0


finalizeTextureCount

<instance> finalizeTextureCount(count)

Description:

Finalize the texture count for the current sub-batch. This is called automatically when the render is run. It requests a shader program with the necessary number of textures, if that is less than the maximum allowed. This reduces the number of textures the GPU must handle, which can improve performance.

Parameters:

nametypeoptionaldescription
countnumberNoThe total number of textures in the batch.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L342


pushCurrentBatchEntry

<instance> pushCurrentBatchEntry()

Description:

Push the current batch entry to the batch entry list, and create a new batch entry for future use.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L832
Since: 4.0.0


run

<instance> run(drawingContext)

Description:

Draw then empty the current batch.

This method is called automatically, by either this node or the manager, when the batch is full, or when something else needs to be rendered.

Parameters:

nametypeoptionaldescription
drawingContextPhaser.Renderer.WebGL.DrawingContextNoThe current drawing context.

Overrides: Phaser.Renderer.WebGL.RenderNodes.BatchHandler#run

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L550
Since: 4.0.0


setupTextureUniforms

<instance> setupTextureUniforms(textures)

Description:

Set the texture resolution uniforms for the current shader program. Specifically, this sets the uMainResolution uniform with the pixel dimensions of each bound texture. This information is required by shader features such as smooth pixel art rendering.

This method is called automatically when the batch is run and the texRes render option is enabled.

Parameters:

nametypeoptionaldescription
texturesArray.<Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper>NoThe textures to render.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L300
Since: 4.0.0


setupUniforms

<instance> setupUniforms(drawingContext)

Description:

Update the uniforms for the current shader program.

This method is called automatically when the batch is run.

Parameters:

nametypeoptionaldescription
drawingContextPhaser.Renderer.WebGL.DrawingContextNoThe current drawing context.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L258
Since: 4.0.0


updateRenderOptions

<instance> updateRenderOptions(renderOptions)

Description:

Compare the incoming render options against the currently active options and stage any differences into nextRenderOptions. Sets _renderOptionsChanged to true if any option has changed, signalling that the current batch should be flushed and the shader rebuilt via updateShaderConfig before the next draw.

Parameters:

nametypeoptionaldescription
renderOptionsobjectNoThe new render options.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L384
Since: 4.0.0


updateShaderConfig

<instance> updateShaderConfig()

Description:

Update the shader configuration based on render options. This is called automatically when the render options change.

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L447
Since: 4.0.0


updateTextureCount

<instance> updateTextureCount([count])

Description:

Update the maximum number of textures per batch. This rebuilds the shader program with the new texture count. The minimum number of textures is 1, and the maximum is the number of texture units defined in the renderer. Rebuilding the shader may be expensive, so use this sparingly.

If this runs during a batch, and the new count is less than the number of textures in the current batch entry, the batch will be flushed before the shader program is rebuilt, so none of the textures are skipped.

This is usually called automatically by a listener for the Phaser.Renderer.Events.SET_PARALLEL_TEXTURE_UNITS event, triggered by the RenderNodeManager.

Parameters:

nametypeoptionaldescription
countnumberYesThe new maximum number of textures per batch. If undefined, the maximum number of texture units is used.

Overrides: Phaser.Renderer.WebGL.RenderNodes.BatchHandler#updateTextureCount

Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L195
Since: 4.0.0