Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions src/webgl/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ export function setWebGLUniformValue(shader, uniform, data, getTexture, gl) {
gl.uniform1f(location, data);
}
break;
case gl.FLOAT_MAT2:
gl.uniformMatrix2fv(location, false, data);
break;
case gl.FLOAT_MAT3:
gl.uniformMatrix3fv(location, false, data);
break;
Expand Down Expand Up @@ -360,6 +363,7 @@ export function getWebGLUniformMetadata(shader, gl) {

uniform.isArray =
uniformInfo.size > 1 ||
uniform.type === gl.FLOAT_MAT2 ||
uniform.type === gl.FLOAT_MAT3 ||
uniform.type === gl.FLOAT_MAT4 ||
uniform.type === gl.FLOAT_VEC2 ||
Expand Down
18 changes: 18 additions & 0 deletions test/unit/visual/cases/webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1521,6 +1521,24 @@ visualTest('randomGaussian() in a fragment loop averages to the mean', (p5, scre
});
});

visualSuite('setUniform', () => {
visualTest('mat2 uniforms are uploaded', (p5, screenshot) => {
p5.createCanvas(50, 50, p5.WEBGL);
const myShader = p5.createFilterShader(`
precision highp float;
uniform mat2 uMatrix;
void main() {
// Diagonal drives red & green: expect (1.0, 0.5, 0.0)
gl_FragColor = vec4(uMatrix[0][0], uMatrix[1][1], 0.0, 1.0);
}
`);
p5.background(200);
myShader.setUniform('uMatrix', [1.0, 0.0, 0.0, 0.5]);
p5.filter(myShader);
screenshot();
});
});

visualSuite('background()', function () {
visualTest('background(image) works in WEBGL', function (p5, screenshot) {
p5.createCanvas(50, 50, p5.WEBGL);
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"numScreenshots": 1
}
Loading