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.
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>
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;
26 gl_Position.x += world2x2[
0][
0];
27 gl_Position.x += world3x3[
0][
0];
28 gl_Position.x += world4x4[
0][
0];
32 <script id=
"fshader" type=
"x-shader/x-fragment">
36 <script id=
"vshader300" type=
"x-shader/x-vertex">
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;
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];
60 <script id=
"fshader300" type=
"x-shader/x-fragment">
67 description("This test ensures WebGL implementations handle uniformMatrix in a OpenGL ES 2.0 spec compliant way");
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"];
78 [2, 2, 'uniformMatrix2fv'],
79 [3, 3, 'uniformMatrix3fv'],
80 [4, 4, 'uniformMatrix4fv'],
83 if (contextVersion
>= 2) {
84 shaders
= ["vshader300", "fshader300"];
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
);
98 for (const [A
, B
, name
] of dims
) {
99 loc
= gl
.getUniformLocation(program
, `world${A}x${B}`);
100 if (!loc
) throw 'missing loc';
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
);
119 `new Float32Array(${mat.length})`,
120 `new Float32Array(new ArrayBuffer(4*${mat.length}))`,
122 if (window
.SharedArrayBuffer
) {
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");
137 gl
[name
](loc
, true, mat
);
138 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "can call " + name
+ "with transpose = true");
143 var successfullyParsed
= true;
146 <script src=
"../../js/js-test-post.js"></script>