Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / uniforms / gl-uniformmatrix4fv.html
blobeb4977a6fdf70b4f151a4aaf1121d5d1abc7fba2
1 <!--
2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL uniformMatrix Conformance Tests</title>
12 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
13 <script src="../../js/js-test-pre.js"></script>
14 <script src="../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <div id="description"></div>
18 <div id="console"></div>
19 <canvas id="example" width="2" height="2"> </canvas>
21 <script id="vshader" type="x-shader/x-vertex">
22 uniform mat2 world2x2;
23 uniform mat3 world3x3;
24 uniform mat4 world4x4;
25 void main() {
26 gl_Position.x += world2x2[0][0];
27 gl_Position.x += world3x3[0][0];
28 gl_Position.x += world4x4[0][0];
30 </script>
32 <script id="fshader" type="x-shader/x-fragment">
33 void main() {}
34 </script>
36 <script id="vshader300" type="x-shader/x-vertex">
37 #version 300 es
38 uniform mat2 world2x2;
39 uniform mat2x3 world2x3;
40 uniform mat2x4 world2x4;
41 uniform mat3x2 world3x2;
42 uniform mat3 world3x3;
43 uniform mat3x4 world3x4;
44 uniform mat4x2 world4x2;
45 uniform mat4x3 world4x3;
46 uniform mat4 world4x4;
47 void main() {
48 gl_Position.x += world2x2[0][0];
49 gl_Position.x += world2x3[0][0];
50 gl_Position.x += world2x4[0][0];
51 gl_Position.x += world3x2[0][0];
52 gl_Position.x += world3x3[0][0];
53 gl_Position.x += world3x4[0][0];
54 gl_Position.x += world4x2[0][0];
55 gl_Position.x += world4x3[0][0];
56 gl_Position.x += world4x4[0][0];
58 </script>
60 <script id="fshader300" type="x-shader/x-fragment">
61 #version 300 es
62 void main() {}
63 </script>
65 <script>
66 "use strict";
67 description("This test ensures WebGL implementations handle uniformMatrix in a OpenGL ES 2.0 spec compliant way");
69 debug("");
70 debug("Checking gl.uniformMatrix.");
72 var wtu = WebGLTestUtils;
73 var gl = wtu.create3DContext("example");
74 var contextVersion = wtu.getDefault3DContextVersion();
76 let shaders = ["vshader", "fshader"];
77 const dims = [
78 [2, 2, 'uniformMatrix2fv'],
79 [3, 3, 'uniformMatrix3fv'],
80 [4, 4, 'uniformMatrix4fv'],
83 if (contextVersion >= 2) {
84 shaders = ["vshader300", "fshader300"];
85 dims.push(
86 [2, 3, 'uniformMatrix2x3fv'],
87 [2, 4, 'uniformMatrix2x4fv'],
88 [3, 2, 'uniformMatrix3x2fv'],
89 [3, 4, 'uniformMatrix3x4fv'],
90 [4, 2, 'uniformMatrix4x2fv'],
91 [4, 3, 'uniformMatrix4x3fv']
95 const program = wtu.setupProgram(gl, shaders);
96 let loc;
98 for (const [A, B, name] of dims) {
99 loc = gl.getUniformLocation(program, `world${A}x${B}`);
100 if (!loc) throw 'missing loc';
102 const mat = [];
103 for (let a = 0; a < A; ++a) {
104 for (let b = 0; b < B; ++b) {
105 mat.push((a == b) ? 1 : 0);
108 const matLess = mat.slice(0, mat.length-2);
109 const matMore = mat.concat([1]);
111 gl[name](loc, false, matLess);
112 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "should fail with insufficient array size for " + name);
113 gl[name](loc, false, mat);
114 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should succeed with correct array size for " + name);
115 gl[name](loc, false, matMore);
116 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "should fail with more than 1 array size for " + name);
118 const validDatas = [
119 `new Float32Array(${mat.length})`,
120 `new Float32Array(new ArrayBuffer(4*${mat.length}))`,
122 if (window.SharedArrayBuffer) {
123 validDatas.push(
124 `new Float32Array(new SharedArrayBuffer(4*${mat.length}))`
127 for (const x of validDatas) {
128 shouldNotThrow(`gl.${name}(loc, false, ${x});`);
131 gl[name](loc, false, mat);
132 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "can call " + name + "with transpose = false");
133 if (contextVersion <= 1) {
134 gl[name](loc, true, mat);
135 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, name + " should return INVALID_VALUE with transpose = true");
136 } else {
137 gl[name](loc, true, mat);
138 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "can call " + name + "with transpose = true");
142 debug("");
143 var successfullyParsed = true;
145 </script>
146 <script src="../../js/js-test-post.js"></script>
148 </body>
149 </html>