From 8fe71bbbff95eb96f91ab8b046ffa09a6dbdb9cb Mon Sep 17 00:00:00 2001 From: John Leonard Date: Fri, 14 Feb 2020 11:39:54 +0000 Subject: [PATCH] perf: only do expensive reload when texture changes --- src/ol/webgl/Helper.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ol/webgl/Helper.js b/src/ol/webgl/Helper.js index cf2ceeab3a..ce97b33a01 100644 --- a/src/ol/webgl/Helper.js +++ b/src/ol/webgl/Helper.js @@ -558,6 +558,7 @@ class WebGLHelper extends Disposable { if (value instanceof HTMLCanvasElement || value instanceof HTMLImageElement || value instanceof ImageData) { // create a texture & put data if (!uniform.texture) { + uniform.prevValue = undefined; uniform.texture = gl.createTexture(); } gl.activeTexture(gl[`TEXTURE${textureSlot}`]); @@ -567,7 +568,8 @@ class WebGLHelper extends Disposable { gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); const imageReady = !(value instanceof HTMLImageElement) || /** @type {HTMLImageElement} */(value).complete; - if (imageReady) { + if (imageReady && uniform.prevValue !== value) { + uniform.prevValue = value; gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, value); }