Skip to content

Commit 33c618d

Browse files
committed
Fixed issue where changing blend mode didn't correctly reset the batch.
1 parent 2b850ad commit 33c618d

1 file changed

Lines changed: 16 additions & 31 deletions

File tree

src/renderer/webgl/BatchManager.js

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -386,23 +386,20 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
386386
this.dirty = true;
387387
},
388388

389-
setCurrentTexture: function (textureSource)
389+
setCurrentTexture: function (source)
390390
{
391-
if (this.renderer.textureArray[textureSource.glTextureIndex] !== textureSource)
392-
{
393-
if (this.currentBatchSize > 0)
394-
{
395-
this.flush();
396-
}
391+
var gl = this.gl;
397392

398-
var gl = this.gl;
393+
if (this.currentBatchSize > 0)
394+
{
395+
this.flush();
396+
}
399397

400-
gl.activeTexture(gl.TEXTURE0 + textureSource.glTextureIndex);
398+
gl.activeTexture(gl.TEXTURE0 + source.glTextureIndex);
401399

402-
gl.bindTexture(gl.TEXTURE_2D, textureSource.glTexture);
400+
gl.bindTexture(gl.TEXTURE_2D, source.glTexture);
403401

404-
this.renderer.textureArray[textureSource.glTextureIndex] = textureSource;
405-
}
402+
this.renderer.textureArray[source.glTextureIndex] = source;
406403
},
407404

408405
add: function (gameObject, verts, uvs, textureIndex, alpha, tintColors, bgColors)
@@ -422,30 +419,13 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
422419
// Does this Game Objects texture need updating?
423420
if (source.glDirty)
424421
{
425-
// Check Batch Size and flush if needed
426-
if (this.currentBatchSize > 0)
427-
{
428-
this.flush();
429-
}
430-
431422
this.renderer.updateTexture(source);
432423
}
433424

434-
// Set the current texture (not if this sprite has its own shader?)
425+
// Does the batch need to activate a new texture?
435426
if (this.renderer.textureArray[source.glTextureIndex] !== source)
436427
{
437-
var gl = this.gl;
438-
439-
if (this.currentBatchSize > 0)
440-
{
441-
this.flush();
442-
}
443-
444-
gl.activeTexture(gl.TEXTURE0 + source.glTextureIndex);
445-
446-
gl.bindTexture(gl.TEXTURE_2D, source.glTexture);
447-
448-
this.renderer.textureArray[source.glTextureIndex] = source;
428+
this.setCurrentTexture(source);
449429
}
450430

451431
// These are TypedArray Views into the vertices ArrayBuffer
@@ -580,6 +560,10 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
580560
{
581561
gl.drawElements(gl.TRIANGLES, currentSize * 6, gl.UNSIGNED_SHORT, start * 6 * 2);
582562
this.renderer.drawCount++;
563+
564+
// Reset the batch
565+
start = i;
566+
currentSize = 0;
583567
}
584568

585569
this.renderer.setBlendMode(sprite.blendMode);
@@ -601,6 +585,7 @@ Phaser.Renderer.WebGL.BatchManager.prototype = {
601585
// Reset the batch
602586
this.currentBatchSize = 0;
603587
this._i = 0;
588+
604589
},
605590

606591
destroy: function ()

0 commit comments

Comments
 (0)