Skip to content

Commit

Permalink
Fixes issue in processing#5481
Browse files Browse the repository at this point in the history
Arrays were not being properly detected based on uniform type information.

Once fixing this, I also had to detect if arrays were being passed to `setUniform` and make a shallow copy there to make sure we update cached uniforms correctly.
  • Loading branch information
Adam Ferriss committed Nov 27, 2021
1 parent ddd80bd commit 50d8da7
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/webgl/p5.Shader.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,7 @@ p5.Shader.prototype._loadUniforms = function() {
samplerIndex++;
this.samplers.push(uniform);
}
uniform.isArray =
uniform.type === gl.FLOAT_MAT3 ||
uniform.type === gl.FLOAT_MAT4 ||
uniform.type === gl.FLOAT_VEC2 ||
uniform.type === gl.FLOAT_VEC3 ||
uniform.type === gl.FLOAT_VEC4 ||
uniform.type === gl.INT_VEC2 ||
uniform.type === gl.INT_VEC3 ||
uniform.type === gl.INT_VEC4;
uniform.isArray = uniformInfo.size > 1;

this.uniforms[uniformName] = uniform;
}
Expand Down Expand Up @@ -378,7 +370,11 @@ p5.Shader.prototype.setUniform = function(uniformName, data) {
} else if (uniform._cachedData && uniform._cachedData === data) {
return;
} else {
uniform._cachedData = data;
if (Array.isArray(data)) {
uniform._cachedData = data.slice(0);
} else {
uniform._cachedData = data;
}
}

const location = uniform.location;
Expand Down

0 comments on commit 50d8da7

Please sign in to comment.