diff --git a/src/webgl/utils.js b/src/webgl/utils.js index a5742c3f50..2d79b14578 100644 --- a/src/webgl/utils.js +++ b/src/webgl/utils.js @@ -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; @@ -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 || diff --git a/test/unit/visual/cases/webgl.js b/test/unit/visual/cases/webgl.js index 618078bc81..8edf5523d0 100644 --- a/test/unit/visual/cases/webgl.js +++ b/test/unit/visual/cases/webgl.js @@ -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); diff --git a/test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/000.png b/test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/000.png new file mode 100644 index 0000000000..e0b8651442 Binary files /dev/null and b/test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/000.png differ diff --git a/test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/metadata.json b/test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/metadata.json new file mode 100644 index 0000000000..2d4bfe30da --- /dev/null +++ b/test/unit/visual/screenshots/WebGL/setUniform/mat2 uniforms are uploaded/metadata.json @@ -0,0 +1,3 @@ +{ + "numScreenshots": 1 +} \ No newline at end of file