Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / uniforms / gl-uniform-unused-array-elements-get-truncated.html
blobf8322cca01862184b7bf9192cdc0fec50445f9b3
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 uniform unused array elements get truncated Conformance Test</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>
20 <script id="vshader" type="x-shader/x-vertex">
21 attribute vec4 a_position;
22 void main()
24 gl_Position = a_position;
26 </script>
27 <script id="fshader-max" type="x-shader/x-fragment">
28 precision mediump float;
29 uniform vec4 colora[$(numUniformVectors)];
30 void main()
32 gl_FragColor = vec4(colora[$(usedUniformVector)]);
34 </script>
35 <script>
36 "use strict";
37 description();
38 debug("");
39 var wtu = WebGLTestUtils;
40 var gl = wtu.create3DContext("example");
41 var vSrc = wtu.getScript("vshader");
42 var uniforms;
43 // This test is to test drivers the have bugs related to optimizing
44 // an array of uniforms when only 1 of those uniforms is used.
45 debug("");
46 var maxUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
47 var tests = [
48 { desc: "using 5th element",
49 maxUniformVectors: maxUniformVectors,
50 numUniformVectors: maxUniformVectors * 2,
51 usedUniformVector: 5,
52 shader: "fshader-max",
53 color: [0, 1, 0, 1],
54 arrayName: "colora",
58 // According to the spec unused array elements must be truncated.
59 var requiredUniformLocationsExist;
60 function testUniformIssues(testIndex) {
61 var test = tests[testIndex];
62 debug("");
63 debug(test.desc);
64 var fSrc = test.source;
65 if (!fSrc) {
66 fSrc = wtu.replaceParams(wtu.getScript(test.shader), test);
69 var consoleElem = document.getElementById("console");
70 wtu.addShaderSource(
71 consoleElem, "vertex shader", vSrc);
72 wtu.addShaderSource(
73 consoleElem, "fragment shader", fSrc);
75 var program = wtu.loadProgram(gl, vSrc, fSrc);
76 gl.useProgram(program);
77 uniforms = wtu.getUniformMap(gl, program);
78 shouldBe('uniforms["' + test.arrayName + '[0]"].size', (test.usedUniformVector + 1).toString());
80 requiredUniformLocationsExist = true;
81 for (var ii = 0; ii <= test.usedUniformVector + 1; ++ii) {
82 var name = test.arrayName + "[" + ii + "]";
83 var colorLocation = gl.getUniformLocation(program, name);
84 if (ii <= test.usedUniformVector) {
85 if (!colorLocation) {
86 requiredUniformLocationsExist = false
88 } else {
89 if (colorLocation) {
90 testFailed("uniform array was not truncated as specified in OpenGL ES 2.0.25 section 2.10.4");
94 shouldBeTrue("requiredUniformLocationsExist");
97 var testIndex = 0;
98 function runNextTest() {
99 testUniformIssues(testIndex++);
100 if (testIndex < tests.length) {
101 setTimeout(runNextTest, 0);
102 } else {
103 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
104 debug("");
105 finishTest();
108 runNextTest();
110 var successfullyParsed = true;
112 </script>
113 </body>
114 </html>