From 8d976d6ed56de7149fc75a7cb7735fe2777b4469 Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Fri, 17 Jul 2020 16:36:18 +0100 Subject: [PATCH] `WebGLRenderer.textureFlush` is a new property that keeps track of the total texture flushes per frame. --- src/renderer/webgl/WebGLRenderer.js | 31 ++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index 3fce0d388..c9934efd8 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -604,6 +604,15 @@ var WebGLRenderer = new Class({ */ this.mipmapFilter = null; + /** + * The number of times the renderer had to flush this frame, due to running out of texture units. + * + * @name Phaser.Renderer.WebGL.WebGLRenderer#textureFlush + * @type {number} + * @since 3.25.0 + */ + this.textureFlush = 0; + this.init(this.config); }, @@ -1402,14 +1411,16 @@ var WebGLRenderer = new Class({ this.startActiveTexture++; + this.textureFlush++; + textureSource.glIndexCounter = this.startActiveTexture; - textureSource.glIndex = 0; + textureSource.glIndex = 1; - gl.activeTexture(gl.TEXTURE0); + gl.activeTexture(gl.TEXTURE1); gl.bindTexture(gl.TEXTURE_2D, textureSource.glTexture); - this.currentActiveTexture = 1; + this.currentActiveTexture = 2; } } @@ -1506,6 +1517,8 @@ var WebGLRenderer = new Class({ this.normalTexture = null; this.startActiveTexture++; this.currentActiveTexture = 1; + + this.textureFlush++; }, /** @@ -1534,6 +1547,8 @@ var WebGLRenderer = new Class({ this.currentActiveTexture = 1; this.startActiveTexture++; + + this.textureFlush++; }, /** @@ -1573,6 +1588,8 @@ var WebGLRenderer = new Class({ this.startActiveTexture++; + this.textureFlush++; + texture.glIndexCounter = this.startActiveTexture; texture.glIndex = 1; @@ -2308,6 +2325,8 @@ var WebGLRenderer = new Class({ this.currentCameraMask.mask = null; this.maskStack.length = 0; + this.textureFlush = 0; + this.setPipeline(this.pipelines.TextureTintPipeline); }, @@ -2448,6 +2467,12 @@ var WebGLRenderer = new Class({ { pipelines[key].onPostRender(); } + + if (this.textureFlush > 0) + { + this.startActiveTexture++; + this.currentActiveTexture = 1; + } }, /**