diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index 621eb53e2..0925b8c26 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -897,6 +897,10 @@ var WebGLRenderer = new Class({ ArrayEach(_this.glProgramWrappers, wrapperCreateResource); ArrayEach(_this.glAttribLocationWrappers, wrapperCreateResource); ArrayEach(_this.glUniformLocationWrappers, wrapperCreateResource); + ArrayEach(_this.glVAOWrappers, wrapperCreateResource); + + // Restore texture unit assignment. + _this.glTextureUnits.bindUnits(_this.glTextureUnits.units, true); // TODO: Remove PipelineManager once the RenderNodes are fully implemented. // // Restore pipelines. diff --git a/src/renderer/webgl/renderNodes/BatchTexturedTintedRawQuads.js b/src/renderer/webgl/renderNodes/BatchTexturedTintedRawQuads.js index e3b382541..d389bf464 100644 --- a/src/renderer/webgl/renderNodes/BatchTexturedTintedRawQuads.js +++ b/src/renderer/webgl/renderNodes/BatchTexturedTintedRawQuads.js @@ -224,22 +224,17 @@ var BatchTexturedTintedRawQuads = new Class({ */ this.floatsPerQuad = this.quadBufferLayout.layout.stride / Float32Array.BYTES_PER_ELEMENT; - // TODO: Allow uniforms to update, with resize or context loss or drawing context settings. + // Set the dimension-related uniforms and listen for resize events. + this.resize(renderer.width, renderer.height); + this.renderer.on(Phaser.Renderer.Events.RESIZE, this.resize, this); // Main sampler will never change after initialization, // because it addresses texture units, not textures. this.program.setUniform('uMainSampler[0]', this.getTextureUnitIndices()); - this.program.setUniform('uProjectionMatrix', renderer.projectionMatrix.val); - this.program.setUniform('uResolution', [ renderer.width, renderer.height ]); - // Populate the instance buffer with the base quad. - this.instanceBufferLayout.viewFloat32.set([ - 0, 0, 0, - 0, 1, 1, - 1, 0, 2, - 1, 1, 3 - ]); - this.instanceBufferLayout.buffer.update(this.instanceBufferLayout.data); + // Initialize the instance buffer, and listen for context loss and restore. + this.populateInstanceBuffer(); + this.renderer.on(Phaser.Renderer.Events.RESTORE_WEBGL, this.populateInstanceBuffer, this); }, /** @@ -391,6 +386,40 @@ var BatchTexturedTintedRawQuads = new Class({ indices.push(i); } return indices; + }, + + /** + * Populate the instance buffer with the base quad. + * + * This is called automatically when the renderer is initialized, + * or when the context is lost and restored. + * + * @method Phaser.Renderer.WebGL.RenderNodes.BatchTexturedTintedRawQuads#populateInstanceBuffer + * @since 3.90.0 + */ + populateInstanceBuffer: function () + { + this.instanceBufferLayout.viewFloat32.set([ + 0, 0, 0, + 0, 1, 1, + 1, 0, 2, + 1, 1, 3 + ]); + this.instanceBufferLayout.buffer.update(this.instanceBufferLayout.data); + }, + + /** + * Set new dimensions for the renderer. This is called automatically when the renderer is resized. + * + * @method Phaser.Renderer.WebGL.RenderNodes.BatchTexturedTintedRawQuads#resize + * @since 3.90.0 + * @param {number} width - The new width of the renderer. + * @param {number} height - The new height of the renderer. + */ + resize: function (width, height) + { + this.program.setUniform('uResolution', [ width, height ]); + this.program.setUniform('uProjectionMatrix', this.renderer.projectionMatrix.val); } }); diff --git a/src/renderer/webgl/wrappers/WebGLProgramWrapper.js b/src/renderer/webgl/wrappers/WebGLProgramWrapper.js index ebcf60a46..e4a223c14 100644 --- a/src/renderer/webgl/wrappers/WebGLProgramWrapper.js +++ b/src/renderer/webgl/wrappers/WebGLProgramWrapper.js @@ -162,6 +162,7 @@ var WebGLProgramWrapper = new Class({ */ createResource: function () { + var _this = this; var renderer = this.renderer; var gl = renderer.gl; @@ -244,9 +245,9 @@ var WebGLProgramWrapper = new Class({ // so they are recreated with the new program. this.glUniforms.each(function (name, uniform) { - if (!this.uniformRequests.has(name)) + if (!_this.uniformRequests.has(name)) { - this.uniformRequests.set(name, uniform.value); + _this.uniformRequests.set(name, uniform.value); } });