Skip to content

Commit 5e5b8c0

Browse files
committed
The WebGLPipeline.shouldFlush method now accepts an optional parameter amount. If given, it will return true if when the amount is added to the vertex count it will exceed the vertex capacity. The Multi Pipeline has been updated to now use this method instead of performing the comparison multiple times itself.
1 parent 36e675f commit 5e5b8c0

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/renderer/webgl/WebGLPipeline.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -343,14 +343,22 @@ var WebGLPipeline = new Class({
343343
/**
344344
* Check if the current batch of vertices is full.
345345
*
346+
* You can optionally provide an `amount` parameter. If given, it will check if the batch
347+
* needs to flush _if_ the `amount` is added to it. This allows you to test if you should
348+
* flush before populating the batch.
349+
*
346350
* @method Phaser.Renderer.WebGL.WebGLPipeline#shouldFlush
347351
* @since 3.0.0
348352
*
353+
* @param {integer} [amount=0] - Will the batch need to flush if this many vertices are added to it?
354+
*
349355
* @return {boolean} `true` if the current batch should be flushed, otherwise `false`.
350356
*/
351-
shouldFlush: function ()
357+
shouldFlush: function (amount)
352358
{
353-
return (this.vertexCount >= this.vertexCapacity);
359+
if (amount === undefined) { amount = 0; }
360+
361+
return (this.vertexCount + amount >= this.vertexCapacity);
354362
},
355363

356364
/**

src/renderer/webgl/pipelines/MultiPipeline.js

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

548548
// So batchQuad never assigns a unit to the glTexture, but to the textureSource instead
549-
if (this.vertexCount + 6 > this.vertexCapacity)
549+
if (this.shouldFlush(6))
550550
{
551551
this.flush();
552552
}
@@ -606,7 +606,7 @@ var MultiPipeline = new Class({
606606

607607
var hasFlushed = false;
608608

609-
if (this.vertexCount + 6 > this.vertexCapacity)
609+
if (this.shouldFlush(6))
610610
{
611611
this.flush();
612612

@@ -716,7 +716,7 @@ var MultiPipeline = new Class({
716716

717717
var hasFlushed = false;
718718

719-
if (this.vertexCount + 3 > this.vertexCapacity)
719+
if (this.shouldFlush(3))
720720
{
721721
this.flush();
722722

0 commit comments

Comments
 (0)