summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/uniforms/gl-uniform-unused-array-elements-get-truncated.html
blob: f8322cca01862184b7bf9192cdc0fec50445f9b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!--
Copyright (c) 2019 The Khronos Group Inc.
Use of this source code is governed by an MIT-style license that can be
found in the LICENSE.txt file.
-->

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>WebGL uniform unused array elements get truncated Conformance Test</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<canvas id="example" width="2" height="2"> </canvas>
<script id="vshader" type="x-shader/x-vertex">
    attribute vec4 a_position;
    void main()
    {
        gl_Position = a_position;
    }
</script>
<script id="fshader-max" type="x-shader/x-fragment">
    precision mediump float;
    uniform vec4 colora[$(numUniformVectors)];
    void main()
    {
        gl_FragColor = vec4(colora[$(usedUniformVector)]);
    }
</script>
<script>
"use strict";
description();
debug("");
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("example");
var vSrc = wtu.getScript("vshader");
var uniforms;
// This test is to test drivers the have bugs related to optimizing
// an array of uniforms when only 1 of those uniforms is used.
debug("");
var maxUniformVectors = gl.getParameter(gl.MAX_FRAGMENT_UNIFORM_VECTORS);
var tests = [
 { desc: "using 5th element",
   maxUniformVectors: maxUniformVectors,
   numUniformVectors: maxUniformVectors * 2,
   usedUniformVector: 5,
   shader: "fshader-max",
   color: [0, 1, 0, 1],
   arrayName: "colora",
 },
];

// According to the spec unused array elements must be truncated.
var requiredUniformLocationsExist;
function testUniformIssues(testIndex) {
  var test = tests[testIndex];
  debug("");
  debug(test.desc);
  var fSrc = test.source;
  if (!fSrc) {
    fSrc = wtu.replaceParams(wtu.getScript(test.shader), test);
  }

  var consoleElem = document.getElementById("console");
  wtu.addShaderSource(
      consoleElem, "vertex shader", vSrc);
  wtu.addShaderSource(
      consoleElem, "fragment shader", fSrc);

  var program = wtu.loadProgram(gl, vSrc, fSrc);
  gl.useProgram(program);
  uniforms = wtu.getUniformMap(gl, program);
  shouldBe('uniforms["' + test.arrayName + '[0]"].size', (test.usedUniformVector + 1).toString());

  requiredUniformLocationsExist = true;
  for (var ii = 0; ii <= test.usedUniformVector + 1; ++ii) {
    var name = test.arrayName + "[" + ii + "]";
    var colorLocation = gl.getUniformLocation(program, name);
    if (ii <= test.usedUniformVector) {
      if (!colorLocation) {
        requiredUniformLocationsExist = false
      }
    } else {
      if (colorLocation) {
        testFailed("uniform array was not truncated as specified in OpenGL ES 2.0.25 section 2.10.4");
      }
    }
  }
  shouldBeTrue("requiredUniformLocationsExist");
}

var testIndex = 0;
function runNextTest() {
  testUniformIssues(testIndex++);
  if (testIndex < tests.length) {
    setTimeout(runNextTest, 0);
  } else {
    wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
    debug("");
    finishTest();
  }
}
runNextTest();

var successfullyParsed = true;

</script>
</body>
</html>