4 ** Copyright (c) 2012 The Khronos Group Inc.
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 <meta charset="utf-8">
32 <title>WebGL uniform unused array elements get truncated Conformance Test</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../resources/webgl-test-utils.js"></script>
38 <div id="description"></div>
39 <div id="console"></div>
40 <canvas id="example" width="2" height="2"> </canvas>
41 <script id="vshader" type="x-shader/x-vertex">
42 attribute vec4 a_position;
45 gl_Position = a_position;
48 <script id="fshader-max" type="x-shader/x-fragment">
49 precision mediump float;
50 uniform vec4 colora[$(numUniformVectors)];
53 gl_FragColor = vec4(colora[$(usedUniformVector)]);
60 var wtu = WebGLTestUtils;
61 var gl = wtu.create3DContext("example");
62 var vSrc = wtu.getScript("vshader");
64 // This test is to test drivers the have bugs related to optimizing
65 // an array of uniforms when only 1 of those uniforms is used.
67 var maxUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
69 { desc: "using 5th element",
70 maxUniformVectors: maxUniformVectors,
71 numUniformVectors: maxUniformVectors * 2,
73 shader: "fshader-max",
79 // According to the spec unused array elements must be truncated.
80 var requiredUniformLocationsExist;
81 function testUniformIssues(testIndex) {
82 var test = tests[testIndex];
85 var fSrc = test.source;
87 fSrc = wtu.replaceParams(wtu.getScript(test.shader), test);
90 var consoleElem = document.getElementById("console");
92 consoleElem, "vertex shader", vSrc);
94 consoleElem, "fragment shader", fSrc);
96 var program = wtu.loadProgram(gl, vSrc, fSrc);
97 gl.useProgram(program);
98 uniforms = wtu.getUniformMap(gl, program);
99 shouldBe('uniforms["' + test.arrayName + '[0]"].size', (test.usedUniformVector + 1).toString());
101 requiredUniformLocationsExist = true;
102 for (var ii = 0; ii <= test.usedUniformVector + 1; ++ii) {
103 var name = test.arrayName + "[" + ii + "]";
104 var colorLocation = gl.getUniformLocation(program, name);
105 if (ii <= test.usedUniformVector) {
106 if (!colorLocation) {
107 requiredUniformLocationsExist = false
111 testFailed("uniform array was not truncated as specified in OpenGL ES 2.0.25 section 2.10.4");
115 shouldBeTrue("requiredUniformLocationsExist");
119 function runNextTest() {
120 testUniformIssues(testIndex++);
121 if (testIndex < tests.length) {
122 setTimeout(runNextTest, 0);
124 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
131 var successfullyParsed = true;