Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to use setUniform for textures by texture slot rather than by p5.Texture #7395

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions src/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1326,12 +1326,30 @@ 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') {
RandomGamingDev marked this conversation as resolved.
Show resolved Hide resolved
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 {
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
Expand Down