Skip to content

Commit 8d976d6

Browse files
committed
WebGLRenderer.textureFlush is a new property that keeps track of the total texture flushes per frame.
1 parent a310bd0 commit 8d976d6

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

src/renderer/webgl/WebGLRenderer.js

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,15 @@ var WebGLRenderer = new Class({
604604
*/
605605
this.mipmapFilter = null;
606606

607+
/**
608+
* The number of times the renderer had to flush this frame, due to running out of texture units.
609+
*
610+
* @name Phaser.Renderer.WebGL.WebGLRenderer#textureFlush
611+
* @type {number}
612+
* @since 3.25.0
613+
*/
614+
this.textureFlush = 0;
615+
607616
this.init(this.config);
608617
},
609618

@@ -1402,14 +1411,16 @@ var WebGLRenderer = new Class({
14021411

14031412
this.startActiveTexture++;
14041413

1414+
this.textureFlush++;
1415+
14051416
textureSource.glIndexCounter = this.startActiveTexture;
14061417

1407-
textureSource.glIndex = 0;
1418+
textureSource.glIndex = 1;
14081419

1409-
gl.activeTexture(gl.TEXTURE0);
1420+
gl.activeTexture(gl.TEXTURE1);
14101421
gl.bindTexture(gl.TEXTURE_2D, textureSource.glTexture);
14111422

1412-
this.currentActiveTexture = 1;
1423+
this.currentActiveTexture = 2;
14131424
}
14141425
}
14151426

@@ -1506,6 +1517,8 @@ var WebGLRenderer = new Class({
15061517
this.normalTexture = null;
15071518
this.startActiveTexture++;
15081519
this.currentActiveTexture = 1;
1520+
1521+
this.textureFlush++;
15091522
},
15101523

15111524
/**
@@ -1534,6 +1547,8 @@ var WebGLRenderer = new Class({
15341547

15351548
this.currentActiveTexture = 1;
15361549
this.startActiveTexture++;
1550+
1551+
this.textureFlush++;
15371552
},
15381553

15391554
/**
@@ -1573,6 +1588,8 @@ var WebGLRenderer = new Class({
15731588

15741589
this.startActiveTexture++;
15751590

1591+
this.textureFlush++;
1592+
15761593
texture.glIndexCounter = this.startActiveTexture;
15771594

15781595
texture.glIndex = 1;
@@ -2308,6 +2325,8 @@ var WebGLRenderer = new Class({
23082325
this.currentCameraMask.mask = null;
23092326
this.maskStack.length = 0;
23102327

2328+
this.textureFlush = 0;
2329+
23112330
this.setPipeline(this.pipelines.TextureTintPipeline);
23122331
},
23132332

@@ -2448,6 +2467,12 @@ var WebGLRenderer = new Class({
24482467
{
24492468
pipelines[key].onPostRender();
24502469
}
2470+
2471+
if (this.textureFlush > 0)
2472+
{
2473+
this.startActiveTexture++;
2474+
this.currentActiveTexture = 1;
2475+
}
24512476
},
24522477

24532478
/**

0 commit comments

Comments
 (0)