Skip to content

Commit 47a8225

Browse files
authored
Merge pull request #7395 from RandomGamingDev/setUniform-texture-slot-addition
Added ability to use setUniform for textures by texture slot rather than by p5.Texture
2 parents 1ed240c + 7f86303 commit 47a8225

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

src/webgl/p5.Shader.js

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,30 @@ p5.Shader = class {
13261326
}
13271327
break;
13281328
case gl.SAMPLER_2D:
1329-
gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex);
1330-
uniform.texture =
1331-
data instanceof p5.Texture ? data : this._renderer.getTexture(data);
1332-
gl.uniform1i(location, uniform.samplerIndex);
1333-
if (uniform.texture.src.gifProperties) {
1334-
uniform.texture.src._animateGif(this._renderer._pInst);
1329+
if (typeof data == 'number') {
1330+
if (
1331+
data < gl.TEXTURE0 ||
1332+
data > gl.TEXTURE31 ||
1333+
data !== Math.ceil(data)
1334+
) {
1335+
console.log(
1336+
'🌸 p5.js says: ' +
1337+
'You\'re trying to use a number as the data for a texture.' +
1338+
'Please use a texture.'
1339+
);
1340+
return this;
1341+
}
1342+
gl.activeTexture(data);
1343+
gl.uniform1i(location, data);
1344+
}
1345+
else {
1346+
gl.activeTexture(gl.TEXTURE0 + uniform.samplerIndex);
1347+
uniform.texture =
1348+
data instanceof p5.Texture ? data : this._renderer.getTexture(data);
1349+
gl.uniform1i(location, uniform.samplerIndex);
1350+
if (uniform.texture.src.gifProperties) {
1351+
uniform.texture.src._animateGif(this._renderer._pInst);
1352+
}
13351353
}
13361354
break;
13371355
//@todo complete all types

0 commit comments

Comments
 (0)