Webgl helper / skip binding texture if underlying image is not ready

This commit is contained in:
Olivier Guyot
2019-08-30 10:56:05 +02:00
parent 5c1191dd5c
commit 29d07ada54

View File

@@ -539,7 +539,6 @@ class WebGLHelper extends Disposable {
let textureSlot = 0; let textureSlot = 0;
this.uniforms_.forEach(function(uniform) { this.uniforms_.forEach(function(uniform) {
value = typeof uniform.value === 'function' ? uniform.value(frameState) : uniform.value; value = typeof uniform.value === 'function' ? uniform.value(frameState) : uniform.value;
// apply value based on type // apply value based on type
if (value instanceof HTMLCanvasElement || value instanceof HTMLImageElement || value instanceof ImageData) { if (value instanceof HTMLCanvasElement || value instanceof HTMLImageElement || value instanceof ImageData) {
// create a texture & put data // create a texture & put data
@@ -551,7 +550,11 @@ class WebGLHelper extends Disposable {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
const imageReady = !(value instanceof HTMLImageElement) || /** @type {HTMLImageElement} */(value).complete;
if (imageReady) {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, value); gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, value);
}
// fill texture slots by increasing index // fill texture slots by increasing index
gl.uniform1i(this.getUniformLocation(uniform.name), textureSlot++); gl.uniform1i(this.getUniformLocation(uniform.name), textureSlot++);