Skip to content

Commit 630382e

Browse files
committed
Added Game Object type look ahead and state for custom batching.
1 parent 240b849 commit 630382e

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/renderer/webgl/WebGLRenderer.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,36 @@ var WebGLRenderer = new Class({
479479
*/
480480
this.glFuncMap = null;
481481

482+
/**
483+
* The `type` of the Game Object being currently rendered.
484+
* This can be used by advanced render functions for batching look-ahead.
485+
*
486+
* @name Phaser.Renderer.WebGL.WebGLRenderer#currentType
487+
* @type {string}
488+
* @since 3.19.0
489+
*/
490+
this.currentType = '';
491+
492+
/**
493+
* Is the `type` of the Game Object being currently rendered different than the
494+
* type of the object before it in the display list? I.e. it's a 'new' type.
495+
*
496+
* @name Phaser.Renderer.WebGL.WebGLRenderer#newType
497+
* @type {boolean}
498+
* @since 3.19.0
499+
*/
500+
this.newType = false;
501+
502+
/**
503+
* Does the `type` of the next Game Object in the display list match that
504+
* of the object being currently rendered?
505+
*
506+
* @name Phaser.Renderer.WebGL.WebGLRenderer#nextTypeMatch
507+
* @type {boolean}
508+
* @since 3.19.0
509+
*/
510+
this.nextTypeMatch = false;
511+
482512
this.init(this.config);
483513
},
484514

@@ -2007,6 +2037,20 @@ var WebGLRenderer = new Class({
20072037
// Apply scissor for cam region + render background color, if not transparent
20082038
this.preRenderCamera(camera);
20092039

2040+
// Nothing to render, so bail out
2041+
if (childCount === 0)
2042+
{
2043+
this.setBlendMode(CONST.BlendModes.NORMAL);
2044+
2045+
// Applies camera effects and pops the scissor, if set
2046+
this.postRenderCamera(camera);
2047+
2048+
return;
2049+
}
2050+
2051+
// Reset the current type
2052+
this.currentType = '';
2053+
20102054
var current = this.currentMask;
20112055

20122056
for (var i = 0; i < childCount; i++)
@@ -2038,7 +2082,19 @@ var WebGLRenderer = new Class({
20382082
mask.preRenderWebGL(this, child, camera);
20392083
}
20402084

2085+
var type = child.type;
2086+
2087+
if (type !== this.currentType)
2088+
{
2089+
this.newType = true;
2090+
this.currentType = type;
2091+
}
2092+
2093+
this.nextTypeMatch = (i < childCount - 1) ? (list[i + 1].type === this.currentType) : false;
2094+
20412095
child.renderWebGL(this, child, interpolationPercentage, camera);
2096+
2097+
this.newType = false;
20422098
}
20432099

20442100
current = this.currentMask;

0 commit comments

Comments
 (0)