From 40e9973ff72d2aae2af5708b8bceca832feb0bdd Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Tue, 3 Sep 2024 13:55:07 +0100 Subject: [PATCH 1/5] Fixed Uniform Shader reset --- src/webgl/p5.Shader.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index e12430ae9d..cb61f552cd 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -139,6 +139,7 @@ p5.Shader = class { this.uniforms = {}; this._bound = false; this.samplers = []; + this.previousBindings = new Set();// Set to store previous bindings } /** @@ -554,7 +555,10 @@ p5.Shader = class { // so we supply a default texture instead. tex = this._renderer._getEmptyTexture(); } - gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex); + const textureUnit = gl.TEXTURE0 + uniform.samplerIndex; + gl.activeTexture(textureUnit); + const previousTexture = gl.getParameter(gl.TEXTURE_BINDING_2D); + this.previousBindings.add(textureUnit); tex.bindTexture(); tex.update(); gl.uniform1i(uniform.location, uniform.samplerIndex); @@ -572,7 +576,9 @@ p5.Shader = class { unbindTextures() { for (const uniform of this.samplers) { - this.setUniform(uniform.name, this._renderer._getEmptyTexture()); + if (this.previousBindings.has(textureUnit) === false){ + this.setUniform(uniform.name, this._renderer._getEmptyTexture()); + } } } From eb4b2301b16ce59094bca0df180ec5c1cf2a6182 Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Tue, 3 Sep 2024 14:03:51 +0100 Subject: [PATCH 2/5] Update p5.Shader.js --- src/webgl/p5.Shader.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index cb61f552cd..5686e54ffd 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -576,7 +576,7 @@ p5.Shader = class { unbindTextures() { for (const uniform of this.samplers) { - if (this.previousBindings.has(textureUnit) === false){ + if (!this.previousBindings.has(textureUnit)){ this.setUniform(uniform.name, this._renderer._getEmptyTexture()); } } From d610856cc5bc3610976deb18d24a207dc2f3747c Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Tue, 3 Sep 2024 14:13:39 +0100 Subject: [PATCH 3/5] fixed lint errors --- src/webgl/p5.Shader.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index 5686e54ffd..16fcf4bccc 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -557,7 +557,6 @@ p5.Shader = class { } const textureUnit = gl.TEXTURE0 + uniform.samplerIndex; gl.activeTexture(textureUnit); - const previousTexture = gl.getParameter(gl.TEXTURE_BINDING_2D); this.previousBindings.add(textureUnit); tex.bindTexture(); tex.update(); @@ -578,7 +577,7 @@ p5.Shader = class { for (const uniform of this.samplers) { if (!this.previousBindings.has(textureUnit)){ this.setUniform(uniform.name, this._renderer._getEmptyTexture()); - } + } } } From bd939ff8ef6e9235a9b7c958264dc0a760df8de5 Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Tue, 3 Sep 2024 14:31:33 +0100 Subject: [PATCH 4/5] fixed def errors --- src/webgl/p5.Shader.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index 16fcf4bccc..6e5fec82a4 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -575,6 +575,7 @@ p5.Shader = class { unbindTextures() { for (const uniform of this.samplers) { + const textureUnit = gl.TEXTURE0 + uniform.samplerIndex; if (!this.previousBindings.has(textureUnit)){ this.setUniform(uniform.name, this._renderer._getEmptyTexture()); } From e81764e765132286bd0ea5024dc8cff50ec21595 Mon Sep 17 00:00:00 2001 From: FORCHA PEARL Date: Tue, 3 Sep 2024 14:43:14 +0100 Subject: [PATCH 5/5] Initialized gl and cleared set after using --- src/webgl/p5.Shader.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index 6e5fec82a4..3d2ba158a5 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -574,12 +574,14 @@ p5.Shader = class { } unbindTextures() { + const gl = this._renderer.GL; for (const uniform of this.samplers) { const textureUnit = gl.TEXTURE0 + uniform.samplerIndex; if (!this.previousBindings.has(textureUnit)){ this.setUniform(uniform.name, this._renderer._getEmptyTexture()); } } + this.previousBindings.clear(); } _setMatrixUniforms() {