flush method
Flushes all batched drawing commands to the GPU.
This method sends all data to the renderer backend for drawing. It is called automatically when necessary (e.g., when changing blend modes, textures, or when the batch buffer is full), but can also be called manually to ensure all pending draw operations are executed.
The application loop in App typically calls this once per frame
after onRender.
Implementation
void flush() {
if (_vertexCount == 0) {
return;
}
if (_renderState.batchMode == null) {
die("State error: Batch started without a _BatchMode set!");
}
final batchMode = _renderState.batchMode!;
final texture = _renderState.currentTexture;
final textureHandle = texture?.handle;
if (batchMode == _BatchMode.quads) {
final numQuadsInBatch = _vertexCount ~/ 4;
if (_vertexCount % 4 != 0) {
die("Warning: Drawing QUAD batch with vertex count $_vertexCount not divisible by 4.");
return;
}
final numIndicesToDraw = numQuadsInBatch * 6;
_renderer.drawGeometry(
texture: textureHandle,
vertices: _batchedInterleavedData,
vertexCount: _vertexCount,
indices: _quadIndices,
indexCount: numIndicesToDraw,
primitiveType: PrimitiveType.triangles,
);
} else {
_renderer.drawGeometry(
texture: textureHandle,
vertices: _batchedInterleavedData,
vertexCount: _vertexCount,
indices: _emptyIndices,
indexCount: 0,
primitiveType: batchMode.toPrimitiveType(),
);
}
_vertexCount = 0;
}