From c14db0041fde794231424c4456ed1c9b502ec0b8 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 27 Nov 2024 06:04:56 -0500 Subject: [PATCH 1/5] added ability to use setUniform for textures by texture slot rather than by p5.Texture --- src/webgl/p5.Shader.js | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index 5f0b38ce66..5d1c36adb1 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -1326,12 +1326,18 @@ p5.Shader = class { } break; case gl.SAMPLER_2D: - gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex); - uniform.texture = - data instanceof p5.Texture ? data : this._renderer.getTexture(data); - gl.uniform1i(location, uniform.samplerIndex); - if (uniform.texture.src.gifProperties) { - uniform.texture.src._animateGif(this._renderer._pInst); + if (typeof data == 'number') { + gl.activeTexture(gl.TEXTURE0 + data); + gl.uniform1i(location, data); + } + else { + gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex); + uniform.texture = + data instanceof p5.Texture ? data : this._renderer.getTexture(data); + gl.uniform1i(location, uniform.samplerIndex); + if (uniform.texture.src.gifProperties) { + uniform.texture.src._animateGif(this._renderer._pInst); + } } break; //@todo complete all types From f57b6254c36fbdc3ebbf77d06ca539c6e242b924 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 27 Nov 2024 16:28:15 -0500 Subject: [PATCH 2/5] instead of using texture slot # now uses WebGL constant and warns if a non-WebGL-constant number is used --- src/webgl/p5.Shader.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index 5d1c36adb1..b9e5cff232 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -1327,7 +1327,11 @@ p5.Shader = class { break; case gl.SAMPLER_2D: if (typeof data == 'number') { - gl.activeTexture(gl.TEXTURE0 + data); + if (data < gl.TEXTURE0 && data > gl.TEXTURE31 && data === Math.ceil(data)) { + console.log('🌸 p5.js says: You\'re trying to use a number as the data for a texture. Please use a texture.'); + return this; + } + gl.activeTexture(data); gl.uniform1i(location, data); } else { From c174c4c8c7240671035bd582b6bd18f70c6f7d37 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 27 Nov 2024 16:29:08 -0500 Subject: [PATCH 3/5] changed typo && to || --- 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 b9e5cff232..f5d72907d2 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -1327,7 +1327,7 @@ p5.Shader = class { break; case gl.SAMPLER_2D: if (typeof data == 'number') { - if (data < gl.TEXTURE0 && data > gl.TEXTURE31 && data === Math.ceil(data)) { + if (data < gl.TEXTURE0 || data > gl.TEXTURE31 || data === Math.ceil(data)) { console.log('🌸 p5.js says: You\'re trying to use a number as the data for a texture. Please use a texture.'); return this; } From 352a60cefe36a613f450a552762155830e7f06c0 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Wed, 27 Nov 2024 16:31:47 -0500 Subject: [PATCH 4/5] cut lines up to work with eslint --- src/webgl/p5.Shader.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/webgl/p5.Shader.js b/src/webgl/p5.Shader.js index f5d72907d2..6b2f21cd60 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -1327,8 +1327,16 @@ p5.Shader = class { break; case gl.SAMPLER_2D: if (typeof data == 'number') { - if (data < gl.TEXTURE0 || data > gl.TEXTURE31 || data === Math.ceil(data)) { - console.log('🌸 p5.js says: You\'re trying to use a number as the data for a texture. Please use a texture.'); + if ( + data < gl.TEXTURE0 || + data > gl.TEXTURE31 || + data === Math.ceil(data) + ) { + console.log( + '🌸 p5.js says: ' + + 'You\'re trying to use a number as the data for a texture.' + + 'Please use a texture.' + ); return this; } gl.activeTexture(data); From 7f863035fba12c5712c6cc4a892351066e73b5c2 Mon Sep 17 00:00:00 2001 From: RandomGamingDev Date: Sun, 1 Dec 2024 13:26:51 -0500 Subject: [PATCH 5/5] fixed typo --- 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 6b2f21cd60..daa13b3899 100644 --- a/src/webgl/p5.Shader.js +++ b/src/webgl/p5.Shader.js @@ -1330,7 +1330,7 @@ p5.Shader = class { if ( data < gl.TEXTURE0 || data > gl.TEXTURE31 || - data === Math.ceil(data) + data !== Math.ceil(data) ) { console.log( '🌸 p5.js says: ' +