From 5e5b8c0938c159a9bb5c8f3c0c5ecceb4aacf19b Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Tue, 15 Sep 2020 11:54:12 +0100 Subject: [PATCH] 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. --- src/renderer/webgl/WebGLPipeline.js | 12 ++++++++++-- src/renderer/webgl/pipelines/MultiPipeline.js | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/renderer/webgl/WebGLPipeline.js b/src/renderer/webgl/WebGLPipeline.js index fa0f21ce4..bc979460c 100644 --- a/src/renderer/webgl/WebGLPipeline.js +++ b/src/renderer/webgl/WebGLPipeline.js @@ -343,14 +343,22 @@ var WebGLPipeline = new Class({ /** * Check if the current batch of vertices is full. * + * You can optionally provide an `amount` parameter. If given, it will check if the batch + * needs to flush _if_ the `amount` is added to it. This allows you to test if you should + * flush before populating the batch. + * * @method Phaser.Renderer.WebGL.WebGLPipeline#shouldFlush * @since 3.0.0 * + * @param {integer} [amount=0] - Will the batch need to flush if this many vertices are added to it? + * * @return {boolean} `true` if the current batch should be flushed, otherwise `false`. */ - shouldFlush: function () + shouldFlush: function (amount) { - return (this.vertexCount >= this.vertexCapacity); + if (amount === undefined) { amount = 0; } + + return (this.vertexCount + amount >= this.vertexCapacity); }, /** diff --git a/src/renderer/webgl/pipelines/MultiPipeline.js b/src/renderer/webgl/pipelines/MultiPipeline.js index 8c34b22e2..efe45025f 100644 --- a/src/renderer/webgl/pipelines/MultiPipeline.js +++ b/src/renderer/webgl/pipelines/MultiPipeline.js @@ -546,7 +546,7 @@ var MultiPipeline = new Class({ } // So batchQuad never assigns a unit to the glTexture, but to the textureSource instead - if (this.vertexCount + 6 > this.vertexCapacity) + if (this.shouldFlush(6)) { this.flush(); } @@ -606,7 +606,7 @@ var MultiPipeline = new Class({ var hasFlushed = false; - if (this.vertexCount + 6 > this.vertexCapacity) + if (this.shouldFlush(6)) { this.flush(); @@ -716,7 +716,7 @@ var MultiPipeline = new Class({ var hasFlushed = false; - if (this.vertexCount + 3 > this.vertexCapacity) + if (this.shouldFlush(3)) { this.flush();