BatchHandlerTriFlat
A render node that draws flat-shaded triangles with per-vertex color in batches, using the WebGL renderer. Unlike texture-based batch handlers, this node requires no texture data — each vertex carries only a position and a packed RGBA tint color. It is used to render untextured geometry such as Graphics objects and other filled or stroked shapes.
Triangles are submitted via the batch method as a set of vertex positions, per-vertex colors, and an index array that groups vertices into triangles. The node accumulates these into a dynamic vertex buffer and index buffer, flushing automatically when the batch is full or when render state changes.
Optionally supports dynamic lighting: when a lighting configuration is provided, the node switches to a lighting-enabled shader variant and uploads the necessary light uniforms each frame.
Constructor
new BatchHandlerTriFlat(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/BatchHandlerTriFlat.js#L17
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
nextRenderOptions
nextRenderOptions: object
Description:
The render options currently being built.
Source: src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js#L92
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/BatchHandlerTriFlat.js#L80
Since: 4.0.0
vertexCount
vertexCount: number
Description:
The number of vertices currently in the batch.
Source: src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js#L61
Since: 4.0.0
Inherited Methods
From Phaser.Renderer.WebGL.RenderNodes.BatchHandler:
From Phaser.Renderer.WebGL.RenderNodes.RenderNode:
Public Methods
batch
<instance> batch(currentContext, indexes, vertices, colors, [lighting])
Description:
Add data to the batch.
The data is composed of vertices and indexed triangles. Each triangle is defined by three indices into the vertices array.
Parameters:
| name | type | optional | default | description |
|---|---|---|---|---|
| currentContext | Phaser.Renderer.WebGL.DrawingContext | No | The current drawing context. | |
| indexes | Array.<number> | No | The index data. Each triangle is defined by three indices into the vertices array, so the length of this should be a multiple of 3. | |
| vertices | Array.<number> | No | The vertices data. Each vertex is defined by an x-coordinate and a y-coordinate. | |
| colors | Array.<number> | No | The color data. Each vertex has a color as a Uint32 value. | |
| lighting | boolean | Yes | false | Should this batch use lighting? |
Overrides: Phaser.Renderer.WebGL.RenderNodes.BatchHandler#batch
Source: src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js#L326
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/BatchHandlerTriFlat.js#L264
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/BatchHandlerTriFlat.js#L159
Since: 4.0.0
updateRenderOptions
<instance> updateRenderOptions(lighting)
Description:
Compare the incoming render options against the current batch's render options and record whether they have changed. If the lighting value differs from the one used to build the current batch, the change is staged in nextRenderOptions and _renderOptionsChanged is set to true, signalling that the batch must be flushed and the shader reconfigured before new geometry is added.
Parameters:
| name | type | optional | description |
|---|---|---|---|
| lighting | object | false | No | The lighting configuration for the next draw call, or false if lighting is disabled. |
Source: src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js#L196
Since: 4.0.0
updateShaderConfig
<instance> updateShaderConfig()
Description:
Apply any pending render option changes to the shader program. This method is called after the current batch has been flushed, when _renderOptionsChanged is true. It synchronises renderOptions with nextRenderOptions and enables or disables the lighting shader additions accordingly. When lighting is enabled it also updates the LIGHT_COUNT preprocessor define to match the renderer's configured maximum number of lights.
Source: src/renderer/webgl/renderNodes/BatchHandlerTriFlat.js#L223
Since: 4.0.0