Skip to content

Commit fe61cfe

Browse files
committed
You can now set the WebGL batch size in the Game Config via the property batchSize. The default is 2000 before the batch will flush, which is a happy average between desktop and mobile. If targeting desktop specifically, you may wish to increase this value to reduce draw calls.
1 parent 1941d8a commit fe61cfe

4 files changed

Lines changed: 22 additions & 17 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ There is a third game config property called `pixelArt`. If set to `true` it's t
5353
* `ScenePlugin.wake` (and the corresponding methods in Scene Systems and the Scene Manager) now has a new optional `data` argument, which is passed to the target Scene and emitted in its 'wake' event.
5454
* `ScenePlugin.setActive` now has a new optional `data` argument, which is passed to the target Scene and emitted in its 'pause' or 'resume' events.
5555
* `TileSprite.tileScaleX` and `tileScaleY` are two new properties that allow you to control the scale of the texture within the Tile Sprite. This impacts the way the repeating texture is scaled, and is independent to scaling the Tile Sprite itself. It works in both Canvas and WebGL mode.
56+
* You can now set the WebGL batch size in the Game Config via the property `batchSize`. The default is 2000 before the batch will flush, which is a happy average between desktop and mobile. If targeting desktop specifically, you may wish to increase this value to reduce draw calls.
5657

5758
### Updates
5859

src/boot/Config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ var ValueToColor = require('../display/color/ValueToColor');
9494
* @property {boolean} [render.preserveDrawingBuffer=false] - [description]
9595
* @property {boolean} [render.failIfMajorPerformanceCaveat=false] - [description]
9696
* @property {string} [render.powerPreference='default'] - "high-performance", "low-power" or "default"
97+
* @property {integer} [render.batchSize=2000] - The default WebGL batch size.
9798
* @property {(string|number)} [backgroundColor=0x000000] - [description]
9899
* @property {object} [callbacks] - [description]
99100
* @property {BootCallback} [callbacks.preBoot=NOOP] - [description]
@@ -355,7 +356,7 @@ var Config = new Class({
355356
this.transparent = GetValue(renderConfig, 'transparent', false);
356357

357358
/**
358-
* @const {boolean} Phaser.Boot.Config#zoclearBeforeRenderom - [description]
359+
* @const {boolean} Phaser.Boot.Config#clearBeforeRender - [description]
359360
*/
360361
this.clearBeforeRender = GetValue(renderConfig, 'clearBeforeRender', true);
361362

@@ -379,6 +380,11 @@ var Config = new Class({
379380
*/
380381
this.powerPreference = GetValue(renderConfig, 'powerPreference', 'default');
381382

383+
/**
384+
* @const {integer} Phaser.Boot.Config#batchSize - The default WebGL Batch size.
385+
*/
386+
this.batchSize = GetValue(renderConfig, 'batchSize', 2000);
387+
382388
var bgc = GetValue(config, 'backgroundColor', 0);
383389

384390
/**

src/renderer/webgl/WebGLRenderer.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var TextureTintPipeline = require('./pipelines/TextureTintPipeline');
3939
* any context change that happens for WebGL rendering inside of Phaser. This means
4040
* if raw webgl functions are called outside the WebGLRenderer of the Phaser WebGL
4141
* rendering ecosystem they might pollute the current WebGLRenderingContext state producing
42-
* unexpected behaviour. It's recommended that WebGL interaction is done through
42+
* unexpected behavior. It's recommended that WebGL interaction is done through
4343
* WebGLRenderer and/or WebGLPipeline.
4444
*
4545
* @class WebGLRenderer
@@ -87,7 +87,8 @@ var WebGLRenderer = new Class({
8787
autoResize: gameConfig.autoResize,
8888
roundPixels: gameConfig.roundPixels,
8989
maxTextures: gameConfig.maxTextures,
90-
maxTextureSize: gameConfig.maxTextureSize
90+
maxTextureSize: gameConfig.maxTextureSize,
91+
batchSize: gameConfig.batchSize
9192
};
9293

9394
/**
@@ -442,7 +443,7 @@ var WebGLRenderer = new Class({
442443

443444
this.gl = gl;
444445

445-
// Set it back into the Game, so devs can access it from there too
446+
// Set it back into the Game, so developers can access it from there too
446447
this.game.context = gl;
447448

448449
for (var i = 0; i <= 16; i++)

src/renderer/webgl/pipelines/TextureTintPipeline.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,19 @@ var TextureTintPipeline = new Class({
4646

4747
function TextureTintPipeline (config)
4848
{
49+
var rendererConfig = config.renderer.config;
50+
51+
// Vertex Size = attribute size added together (2 + 2 + 1 + 4)
52+
4953
WebGLPipeline.call(this, {
5054
game: config.game,
5155
renderer: config.renderer,
5256
gl: config.renderer.gl,
53-
topology: (config.topology ? config.topology : config.renderer.gl.TRIANGLES),
54-
vertShader: (config.vertShader ? config.vertShader : ShaderSourceVS),
55-
fragShader: (config.fragShader ? config.fragShader : ShaderSourceFS),
56-
vertexCapacity: (config.vertexCapacity ? config.vertexCapacity : 6 * 2000),
57-
58-
vertexSize: (config.vertexSize ? config.vertexSize :
59-
Float32Array.BYTES_PER_ELEMENT * 2 +
60-
Float32Array.BYTES_PER_ELEMENT * 2 +
61-
Float32Array.BYTES_PER_ELEMENT * 1 +
62-
Uint8Array.BYTES_PER_ELEMENT * 4
63-
),
57+
topology: config.renderer.gl.TRIANGLES,
58+
vertShader: ShaderSourceVS,
59+
fragShader: ShaderSourceFS,
60+
vertexCapacity: 6 * rendererConfig.batchSize,
61+
vertexSize: Float32Array.BYTES_PER_ELEMENT * 5 + Uint8Array.BYTES_PER_ELEMENT * 4,
6462

6563
attributes: [
6664
{
@@ -117,10 +115,9 @@ var TextureTintPipeline = new Class({
117115
*
118116
* @name Phaser.Renderer.WebGL.Pipelines.TextureTintPipeline#maxQuads
119117
* @type {integer}
120-
* @default 2000
121118
* @since 3.0.0
122119
*/
123-
this.maxQuads = 2000;
120+
this.maxQuads = rendererConfig.batchSize;
124121

125122
/**
126123
* Collection of batch information

0 commit comments

Comments
 (0)