summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance2/glsl3/uninitialized-local-global-variables.html
blob: 0d5be3da220975be1c3b746b3e977ab7a519ff66 (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
<!--
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>Uninitialized local/global variables should be initialized (ESSL 3.00 cases)</title>
<link rel="stylesheet" href="../../resources/js-test-style.css"/>
<link rel="stylesheet" href="../../resources/glsl-feature-tests.css"/>
<script src="../../js/js-test-pre.js"></script>
<script src="../../js/webgl-test-utils.js"> </script>

<!--
This test covers cases that can't be tested with ESSL 1.00 due to Appendix A limitations.
The ESSL 1.00 cases are covered in conformance/glsl/misc/uninitialized-local-global-variables.html
-->

<script id="vs_uninit_in_frag" type="x-shader/x-vertex">#version 300 es
precision highp float;
in vec4 a_position;
void main() {
    gl_Position = a_position;
}
</script>

<!-- Uninitialized variables in a for loop initializer in fragment shader -->
<script id="fs_uninit_variables_in_loop_in_frag" type="x-shader/x-fragment">#version 300 es
precision highp float;
out vec4 my_FragColor;
void main() {
    int i = 0;
    for (vec4 uninit, uninit2[2] = vec4[2](uninit, uninit); i < 1; ++i) {
        my_FragColor = uninit2[0];
    }
}
</script>

<!-- Uninitialized nameless struct in a for loop initializer in fragment shader -->
<script id="fs_uninit_nameless_struct_in_loop_in_frag" type="x-shader/x-fragment">#version 300 es
precision highp float;
out vec4 my_FragColor;
void main() {
    int i = 0;
    for (struct { vec4 v; } uninit; i < 1; ++i) {
        my_FragColor = uninit.v;
    }
}
</script>

</head>
<body>
<canvas id="canvas" width="50" height="50"></canvas>
<div id="description"></div>
<div id="console"></div>
<script>
"use strict";
description('Uninitialized local/global variables should be initialized: http://anglebug.com/1966');

var wtu = WebGLTestUtils;
var gl = wtu.create3DContext("canvas", undefined, 2);
wtu.setupUnitQuad(gl);

var cases = [
  {
    name: "Uninitialized variables in a for loop initializer in fragment shader",
    prog: ["vs_uninit_in_frag", "fs_uninit_variables_in_loop_in_frag"],
  },
  {
    name: "Uninitialized nameless struct in a for loop initializer in fragment shader",
    prog: ["vs_uninit_in_frag", "fs_uninit_nameless_struct_in_loop_in_frag"],
  }
];

function runTest() {
  for (var i = 0; i < cases.length; ++i) {
    debug("");
    debug(cases[i].name);
    var program = wtu.setupProgram(gl, cases[i].prog, ["a_position"], undefined, true);
    gl.clearColor(1.0, 0.0, 0.0, 1.0);
    wtu.clearAndDrawUnitQuad(gl);
    wtu.checkCanvas(gl, [0, 0, 0, 0]);
  }

  debug("");
  wtu.glErrorShouldBe(gl, gl.NO_ERROR, "there should be no errors");
}

runTest();

var successfullyParsed = true;
</script>
<script src="../../js/js-test-post.js"></script>
</body>
</html>