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
| name | type | optional | description |
|---|---|---|---|
| manager | Phaser.Renderer.WebGL.RenderNodes.RenderNodeManager | No | The manager that owns this RenderNode. |
| config | Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerConfig | Yes | The configuration object for this handler. |
Scope: static
Extends
Source: src/renderer/webgl/renderNodes/BatchHandlerQuad.js#L26
Since: 4.0.0
Inherited Members
From Phaser.Renderer.WebGL.RenderNodes.BatchHandler:
- batchEntries
- bytesPerIndexPerInstance
- bytesPerInstance
- currentBatchEntry
- floatsPerInstance
- indexBuffer
- indicesPerInstance
- instanceCount
- instancesPerBatch
- maxTexturesPerBatch
- programManager
- vertexBufferLayout
- verticesPerInstance
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:
| name | type | optional | description |
|---|---|---|---|
| currentContext | Phaser.Renderer.WebGL.DrawingContext | No | The current drawing context. |
| glTexture | Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper | No | The texture to render. |
| x0 | number | No | The x coordinate of the top-left corner. |
| y0 | number | No | The y coordinate of the top-left corner. |
| x1 | number | No | The x coordinate of the bottom-left corner. |
| y1 | number | No | The y coordinate of the bottom-left corner. |
| x2 | number | No | The x coordinate of the top-right corner. |
| y2 | number | No | The y coordinate of the top-right corner. |
| x3 | number | No | The x coordinate of the bottom-right corner. |
| y3 | number | No | The y coordinate of the bottom-right corner. |
| texX | number | No | The left u coordinate (0-1). |
| texY | number | No | The top v coordinate (0-1). |
| texWidth | number | No | The width of the texture (0-1). |
| texHeight | number | No | The height of the texture (0-1). |
| tintMode | number | No | The tint mode to use. |
| tintTL | number | No | The top-left tint color. |
| tintBL | number | No | The bottom-left tint color. |
| tintTR | number | No | The top-right tint color. |
| tintBR | number | No | The bottom-right tint color. |
| renderOptions | Phaser.Types.Renderer.WebGL.RenderNodes.BatchHandlerQuadRenderOptions | No | Optional render features. |
| args | * | Yes | Additional 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:
| name | type | optional | description |
|---|---|---|---|
| glTexture | Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper | No | The texture to render. |
| renderOptions | object | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| count | number | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| drawingContext | Phaser.Renderer.WebGL.DrawingContext | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| textures | Array.<Phaser.Renderer.WebGL.Wrappers.WebGLTextureWrapper> | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| drawingContext | Phaser.Renderer.WebGL.DrawingContext | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| renderOptions | object | No | The 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:
| name | type | optional | description |
|---|---|---|---|
| count | number | Yes | The 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