Skip to content

Commit cb7a998

Browse files
committed
Added onBatch support
1 parent 39b381d commit cb7a998

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/renderer/webgl/WebGLPipeline.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ var WebGLPipeline = new Class({
458458
/**
459459
* This method is called once when this pipeline has finished being set-up
460460
* at the end of the boot process. By the time this method is called, all
461-
* of the shaders are ready and configured.
461+
* of the shaders are ready and configured. It's also called if the renderer
462+
* changes size.
462463
*
463464
* @method Phaser.Renderer.WebGL.WebGLPipeline#onResize
464465
* @since 3.50.0
@@ -876,6 +877,24 @@ var WebGLPipeline = new Class({
876877
{
877878
},
878879

880+
/**
881+
* By default this is an empty method hook that you can override and use in your own custom pipelines.
882+
*
883+
* This method is called every time the `batchQuad` or `batchTri` methods are called. If this was
884+
* as a result of a Game Object, then the Game Object refernce is passed to this hook too.
885+
*
886+
* This hook is called _after_ the quad (or tri) has been added to the batch, so you can safely
887+
* call 'flush' from within this.
888+
*
889+
* @method Phaser.Renderer.WebGL.WebGLPipeline#onBatch
890+
* @since 3.50.0
891+
*
892+
* @param {Phaser.GameObjects.GameObject} [gameObject] - The Game Object that invoked this pipeline, if any.
893+
*/
894+
onBatch: function ()
895+
{
896+
},
897+
879898
/**
880899
* By default this is an empty method hook that you can override and use in your own custom pipelines.
881900
*
@@ -1045,6 +1064,7 @@ var WebGLPipeline = new Class({
10451064
* @method Phaser.Renderer.WebGL.WebGLPipeline#batchQuad
10461065
* @since 3.50.0
10471066
*
1067+
* @param {(Phaser.GameObjects.GameObject|null)} gameObject - The Game Object, if any, drawing this quad.
10481068
* @param {number} x0 - The top-left x position.
10491069
* @param {number} y0 - The top-left y position.
10501070
* @param {number} x1 - The bottom-left x position.
@@ -1067,7 +1087,7 @@ var WebGLPipeline = new Class({
10671087
*
10681088
* @return {boolean} `true` if this method caused the batch to flush, otherwise `false`.
10691089
*/
1070-
batchQuad: function (x0, y0, x1, y1, x2, y2, x3, y3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, unit)
1090+
batchQuad: function (gameObject, x0, y0, x1, y1, x2, y2, x3, y3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, unit)
10711091
{
10721092
if (unit === undefined) { unit = this.currentUnit; }
10731093

@@ -1089,6 +1109,8 @@ var WebGLPipeline = new Class({
10891109
this.batchVert(x2, y2, u1, v1, unit, tintEffect, tintBR);
10901110
this.batchVert(x3, y3, u1, v0, unit, tintEffect, tintTR);
10911111

1112+
this.onBatch(gameObject);
1113+
10921114
return hasFlushed;
10931115
},
10941116

@@ -1110,6 +1132,7 @@ var WebGLPipeline = new Class({
11101132
* @method Phaser.Renderer.WebGL.WebGLPipeline#batchTri
11111133
* @since 3.50.0
11121134
*
1135+
* @param {(Phaser.GameObjects.GameObject|null)} gameObject - The Game Object, if any, drawing this quad.
11131136
* @param {number} x1 - The bottom-left x position.
11141137
* @param {number} y1 - The bottom-left y position.
11151138
* @param {number} x2 - The bottom-right x position.
@@ -1129,7 +1152,7 @@ var WebGLPipeline = new Class({
11291152
*
11301153
* @return {boolean} `true` if this method caused the batch to flush, otherwise `false`.
11311154
*/
1132-
batchTri: function (x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintEffect, texture, unit)
1155+
batchTri: function (gameObject, x0, y0, x1, y1, x2, y2, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintEffect, texture, unit)
11331156
{
11341157
if (unit === undefined) { unit = this.currentUnit; }
11351158

@@ -1148,6 +1171,8 @@ var WebGLPipeline = new Class({
11481171
this.batchVert(x1, y1, u0, v1, unit, tintEffect, tintTR);
11491172
this.batchVert(x2, y2, u1, v1, unit, tintEffect, tintBL);
11501173

1174+
this.onBatch(gameObject);
1175+
11511176
return hasFlushed;
11521177
},
11531178

src/renderer/webgl/pipelines/MultiPipeline.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ var MultiPipeline = new Class({
334334

335335
this.manager.preBatch(sprite);
336336

337-
this.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, sprite.tintEffect, texture, unit);
337+
this.batchQuad(sprite, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, sprite.tintEffect, texture, unit);
338338

339339
this.manager.postBatch(sprite);
340340
},
@@ -524,7 +524,7 @@ var MultiPipeline = new Class({
524524
// TODO - parameter toggle?
525525
// this.manager.preBatch(gameObject);
526526

527-
this.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, textureUnit);
527+
this.batchQuad(gameObject, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, u0, v0, u1, v1, tintTL, tintTR, tintBL, tintBR, tintEffect, texture, textureUnit);
528528

529529
// this.manager.postBatch(gameObject);
530530
},
@@ -584,7 +584,7 @@ var MultiPipeline = new Class({
584584

585585
tint = Utils.getTintAppendFloatAlpha(tint, alpha);
586586

587-
this.batchQuad(tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, frame.u0, frame.v0, frame.u1, frame.v1, tint, tint, tint, tint, 0, frame.glTexture, unit);
587+
this.batchQuad(null, tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3, frame.u0, frame.v0, frame.u1, frame.v1, tint, tint, tint, tint, 0, frame.glTexture, unit);
588588
}
589589

590590
});

0 commit comments

Comments
 (0)