diff --git a/src/renderer/webgl/WebGLPipeline.js b/src/renderer/webgl/WebGLPipeline.js index dd463d2d6..3bb95f4fa 100644 --- a/src/renderer/webgl/WebGLPipeline.js +++ b/src/renderer/webgl/WebGLPipeline.js @@ -277,33 +277,12 @@ var WebGLPipeline = new Class({ */ boot: function () { - var gl = this.gl; - var vertexBuffer = this.vertexBuffer; - var attributes = this.attributes; - var program = this.program; var renderer = this.renderer; - var vertexSize = this.vertexSize; - renderer.setProgram(program); - renderer.setVertexBuffer(vertexBuffer); + renderer.setProgram(this.program); + renderer.setVertexBuffer(this.vertexBuffer); - for (var i = 0; i < attributes.length; i++) - { - var element = attributes[i]; - var location = gl.getAttribLocation(program, element.name); - - if (location >= 0) - { - gl.enableVertexAttribArray(location); - gl.vertexAttribPointer(location, element.size, element.type, element.normalized, vertexSize, element.offset); - element.enabled = true; - element.location = location; - } - else if (location !== -1) - { - gl.disableVertexAttribArray(location); - } - } + this.setAttribPointers(true); this.hasBooted = true; @@ -404,10 +383,14 @@ var WebGLPipeline = new Class({ * @method Phaser.Renderer.WebGL.WebGLPipeline#bind * @since 3.0.0 * + * @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear? + * * @return {this} This WebGLPipeline instance. */ - bind: function () + bind: function (reset) { + if (reset === undefined) { reset = false; } + var vertexBuffer = this.vertexBuffer; var program = this.program; var renderer = this.renderer; @@ -415,7 +398,7 @@ var WebGLPipeline = new Class({ renderer.setProgram(program); renderer.setVertexBuffer(vertexBuffer); - this.setAttribPointers(); + this.setAttribPointers(reset); return this; }, @@ -427,19 +410,40 @@ var WebGLPipeline = new Class({ * @method Phaser.Renderer.WebGL.WebGLPipeline#setAttribPointers * @since 3.50.0 * + * @param {boolean} [reset=false] - Reset the vertex attribute locations? + * * @return {this} This WebGLPipeline instance. */ - setAttribPointers: function () + setAttribPointers: function (reset) { + if (reset === undefined) { reset = false; } + var gl = this.gl; var attributes = this.attributes; var vertexSize = this.vertexSize; + var program = this.program; for (var i = 0; i < attributes.length; i++) { var element = attributes[i]; - if (element.enabled) + if (reset) + { + var location = gl.getAttribLocation(program, element.name); + + if (location >= 0) + { + gl.enableVertexAttribArray(location); + gl.vertexAttribPointer(location, element.size, element.type, element.normalized, vertexSize, element.offset); + element.enabled = true; + element.location = location; + } + else if (location !== -1) + { + gl.disableVertexAttribArray(location); + } + } + else if (element.enabled) { gl.vertexAttribPointer(element.location, element.size, element.type, element.normalized, vertexSize, element.offset); } diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index e88cc12a5..9f32eb5e3 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -1221,13 +1221,10 @@ var WebGLRenderer = new Class({ this.setBlendMode(0, true); - this.resetTextures(true); - - this.currentActiveTexture = 1; - this.startActiveTexture++; + this.resetTextures(); this.currentPipeline = pipelineInstance; - this.currentPipeline.bind(); + this.currentPipeline.bind(true); this.currentPipeline.onBind(); }, diff --git a/src/renderer/webgl/pipelines/BitmapMaskPipeline.js b/src/renderer/webgl/pipelines/BitmapMaskPipeline.js index 9296e20c8..40bdd63f6 100644 --- a/src/renderer/webgl/pipelines/BitmapMaskPipeline.js +++ b/src/renderer/webgl/pipelines/BitmapMaskPipeline.js @@ -110,11 +110,15 @@ var BitmapMaskPipeline = new Class({ * @method Phaser.Renderer.WebGL.Pipelines.BitmapMaskPipeline#bind * @since 3.50.0 * + * @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear? + * * @return {this} This WebGLPipeline instance. */ - bind: function () + bind: function (reset) { - WebGLPipeline.prototype.bind.call(this); + if (reset === undefined) { reset = false; } + + WebGLPipeline.prototype.bind.call(this, reset); var renderer = this.renderer; var program = this.program; diff --git a/src/renderer/webgl/pipelines/LightPipeline.js b/src/renderer/webgl/pipelines/LightPipeline.js index d46068882..4de2661a8 100644 --- a/src/renderer/webgl/pipelines/LightPipeline.js +++ b/src/renderer/webgl/pipelines/LightPipeline.js @@ -149,11 +149,15 @@ var LightPipeline = new Class({ * @method Phaser.Renderer.WebGL.Pipelines.LightPipeline#bind * @since 3.50.0 * + * @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear? + * * @return {this} This WebGLPipeline instance. */ - bind: function () + bind: function (reset) { - WebGLPipeline.prototype.bind.call(this); + if (reset === undefined) { reset = false; } + + WebGLPipeline.prototype.bind.call(this, reset); var renderer = this.renderer; var program = this.program; diff --git a/src/renderer/webgl/pipelines/MultiPipeline.js b/src/renderer/webgl/pipelines/MultiPipeline.js index 15074e101..4b509d460 100644 --- a/src/renderer/webgl/pipelines/MultiPipeline.js +++ b/src/renderer/webgl/pipelines/MultiPipeline.js @@ -298,11 +298,15 @@ var MultiPipeline = new Class({ * @method Phaser.Renderer.WebGL.Pipelines.MultiPipeline#bind * @since 3.50.0 * + * @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear? + * * @return {this} This WebGLPipeline instance. */ - bind: function () + bind: function (reset) { - WebGLPipeline.prototype.bind.call(this); + if (reset === undefined) { reset = false; } + + WebGLPipeline.prototype.bind.call(this, reset); this.renderer.setInt1iv(this.program, 'uMainSampler', this.renderer.textureIndexes); diff --git a/src/renderer/webgl/pipelines/SinglePipeline.js b/src/renderer/webgl/pipelines/SinglePipeline.js index 6174aa3c6..8ad5d396e 100644 --- a/src/renderer/webgl/pipelines/SinglePipeline.js +++ b/src/renderer/webgl/pipelines/SinglePipeline.js @@ -308,11 +308,15 @@ var SinglePipeline = new Class({ * @method Phaser.Renderer.WebGL.Pipelines.SinglePipeline#bind * @since 3.50.0 * + * @param {boolean} [reset=false] - Should the pipeline be fully re-bound after a renderer pipeline clear? + * * @return {this} This WebGLPipeline instance. */ - bind: function () + bind: function (reset) { - WebGLPipeline.prototype.bind.call(this); + if (reset === undefined) { reset = false; } + + WebGLPipeline.prototype.bind.call(this, reset); return this; }