From d8fcde46c3c3dd25d48722f8f004f2f963be908e Mon Sep 17 00:00:00 2001 From: Richard Davey Date: Thu, 27 Sep 2018 14:16:22 +0100 Subject: [PATCH] When using `CanvasTexture.refresh` or `Graphics.generateTexture` it would throw WebGL warnings like 'bindTexture: Attempt to bind a deleted texture'. This was due to the Frames losing sync with the glTexture reference used by their TextureSource. Fix #4050 --- CHANGELOG.md | 3 +++ src/gameobjects/graphics/Graphics.js | 4 ++-- src/renderer/webgl/WebGLRenderer.js | 14 ++++++++------ src/textures/TextureSource.js | 11 +++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e02b9780..c364f86c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ * `TextureTintPipeline.batchTexture` has a new optional argument `skipFlip` which allows you to control the internal render texture flip Y check. * The Device.OS check for `node` will now do a `typeof` first to avoid issues with rollup packaged builds needing to shim the variable out. Fix #4058 (thanks @hollowdoor) * Arcade Physics Bodies will now sync the display origin of the parent Game Object to the body properties as part of the `updateBounds` call. This means if you change the origin of an AP enabled Game Object, after creation of the body, it will be reflected in the body position. This may or may not be a breaking change for your game. Previously it was expected that the origin should always be 0.5 and you adjust the body using `setOffset`, but this change makes a bit more sense logically. If you find that your bodies are offset after upgrading to this version then this is likely why. Close #4052 (thanks @SolarOmni) +* The `Texture.getFramesFromTextureSource` method has a new boolean argument `includeBase`, which defaults to `false` and allows you to set if the base frame should be returned into the array or not. ### Bug Fixes @@ -60,6 +61,8 @@ * The `Shape.Line` object was missing a `lineWidth` property unless you called the `setLineWidth` method, causing the line to not render in Canvas only. Fix #4068 (thanks @netgfx) * All parts of Matter Body now have the `gameObject` property set correctly. Previously only the first part of the Body did. * When using `MatterGameObject` and `fromVerts` as the shape type it wouldn't pass the values to `Bodies.fromVertices` because of a previous conditional. It now passes them over correctly and the body is only set if the result is valid. +* The `Texture.getFramesFromTextureSource` method was returning an array of Frame names by mistake, instead of Frame references. It now returns the Frames themselves. +* When using `CanvasTexture.refresh` or `Graphics.generateTexture` it would throw WebGL warnings like 'bindTexture: Attempt to bind a deleted texture'. This was due to the Frames losing sync with the glTexture reference used by their TextureSource. Fix #4050 (thanks @kanthi0802) ### Examples, Documentation and TypeScript diff --git a/src/gameobjects/graphics/Graphics.js b/src/gameobjects/graphics/Graphics.js index 4c7ce3c7b..f617a521b 100644 --- a/src/gameobjects/graphics/Graphics.js +++ b/src/gameobjects/graphics/Graphics.js @@ -1493,9 +1493,9 @@ var Graphics = new Class({ // var GraphicsCanvasRenderer = function (renderer, src, interpolationPercentage, camera, parentMatrix, renderTargetCtx, allowClip) this.renderCanvas(renderer, this, 0, Graphics.TargetCamera, null, ctx, false); - if (renderer.gl && texture) + if (texture) { - texture.source[0].glTexture = renderer.canvasToTexture(ctx.canvas, texture.source[0].glTexture); + texture.refresh(); } } diff --git a/src/renderer/webgl/WebGLRenderer.js b/src/renderer/webgl/WebGLRenderer.js index a107a9627..49865b51f 100644 --- a/src/renderer/webgl/WebGLRenderer.js +++ b/src/renderer/webgl/WebGLRenderer.js @@ -1817,11 +1817,6 @@ var WebGLRenderer = new Class({ { var gl = this.gl; - if (dstTexture) - { - this.deleteTexture(dstTexture); - } - var wrapping = gl.CLAMP_TO_EDGE; if (IsSizePowerOfTwo(srcCanvas.width, srcCanvas.height)) @@ -1829,7 +1824,14 @@ var WebGLRenderer = new Class({ wrapping = gl.REPEAT; } - return this.createTexture2D(0, gl.NEAREST, gl.NEAREST, wrapping, wrapping, gl.RGBA, srcCanvas, srcCanvas.width, srcCanvas.height, true); + var newTexture = this.createTexture2D(0, gl.NEAREST, gl.NEAREST, wrapping, wrapping, gl.RGBA, srcCanvas, srcCanvas.width, srcCanvas.height, true); + + if (newTexture && dstTexture) + { + this.deleteTexture(dstTexture); + } + + return newTexture; }, /** diff --git a/src/textures/TextureSource.js b/src/textures/TextureSource.js index 61699b412..e1fe61fb6 100644 --- a/src/textures/TextureSource.js +++ b/src/textures/TextureSource.js @@ -235,6 +235,17 @@ var TextureSource = new Class({ if (this.renderer.gl && this.isCanvas) { this.glTexture = this.renderer.canvasToTexture(this.image, this.glTexture); + + // Update all the Frames using this TextureSource + + var index = this.texture.getTextureSourceIndex(this); + + var frames = this.texture.getFramesFromTextureSource(index, true); + + for (var i = 0; i < frames.length; i++) + { + frames[i].glTexture = this.glTexture; + } } },