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.

This commit is contained in:
Richard Davey 2020-09-15 11:54:12 +01:00
parent 36e675fa42
commit 5e5b8c0938
2 changed files with 13 additions and 5 deletions

View file

@ -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);
},
/**

View file

@ -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();