Bug 1945965 – remove new tab April Fools logo. r=home-newtab-reviewers,reemhamz
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / more / glsl / arrayOutOfBounds.html
blob195b224a9e6d81cfbe3b99e3a467b8e9e206d684
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <!--
6 Copyright (c) 2019 The Khronos Group Inc.
7 Use of this source code is governed by an MIT-style license that can be
8 found in the LICENSE.txt file.
9 -->
10 <link rel="stylesheet" type="text/css" href="../unit.css" />
11 <script type="application/javascript" src="../unit.js"></script>
12 <script type="application/javascript" src="../util.js"></script>
13 <script type="application/javascript">
15 Tests.startUnit = function () {
16 var canvas = document.getElementById('gl');
17 var gl = getGLContext(canvas);
18 return [gl];
21 Tests.testOk = function(gl) {
22 var sh = new Filter(gl, 'okvert', 'frag');
23 assertOk(function(){sh.apply();});
24 sh.destroy();
26 var sh = new Filter(gl, 'vert', 'okfrag');
27 assertOk(function(){sh.apply();});
28 sh.destroy();
30 var sh = new Filter(gl, 'vert', 'frag');
31 assertOk(function(){sh.apply();});
32 sh.destroy();
35 var arr = ['cr', 'cw', 'vr', 'vw'];
36 arr.forEach(function(e){
37 if (e == 'cr' || e == 'cw') {
38 Tests['test'+e+'vert'] = function(gl) {
39 var sh = new Filter(gl, e+'vert', 'frag');
40 assertFail(function(){sh.apply();});
41 sh.destroy();
44 Tests['test'+e+'frag'] = function(gl) {
45 var sh = new Filter(gl, 'vert', e+'frag');
46 assertFail(function(){sh.apply();});
47 sh.destroy();
49 });
52 </script>
53 <script id="okvert" type="x-shader/x-vertex">
56 attribute vec3 Vertex;
57 attribute vec2 Tex;
58 varying vec2 TexCoord;
59 void main()
61 TexCoord = Tex;
62 float x[3];
63 x[0] = 1.0;
64 x[1] = 2.0;
65 x[2] = 3.0;
66 gl_Position = vec4(Vertex, x[2]);
68 </script>
69 <script id="crvert" type="x-shader/x-vertex">
72 attribute vec3 Vertex;
73 attribute vec2 Tex;
74 varying vec2 TexCoord;
75 void main()
77 TexCoord = Tex;
78 float x[3];
79 x[0] = 1.0;
80 x[1] = 2.0;
81 x[2] = 3.0;
82 gl_Position = vec4(Vertex, x[4]);
84 </script>
85 <script id="cwvert" type="x-shader/x-vertex">
88 attribute vec3 Vertex;
89 attribute vec2 Tex;
90 varying vec2 TexCoord;
91 void main()
93 TexCoord = Tex;
94 float x[3];
95 x[0] = 1.0;
96 x[1] = 2.0;
97 x[2] = 3.0;
98 x[4] = Vertex.z;
99 gl_Position = vec4(Vertex, x[4]);
101 </script>
102 <!-- This one can't be required to fail compilation, because vertex shaders must support arbitrary array indexing -->
103 <script id="vrvert" type="x-shader/x-vertex">
106 attribute vec3 Vertex;
107 attribute vec2 Tex;
108 varying vec2 TexCoord;
109 void main()
111 TexCoord = Tex;
112 float x[3];
113 x[0] = 1.0;
114 x[1] = 2.0;
115 x[2] = 3.0;
116 int idx = 4 * int(max(1.0, Vertex.x*20.0));
117 gl_Position = vec4(Vertex, x[idx]);
119 </script>
120 <!-- This one can't be required to fail compilation, because vertex shaders must support arbitrary array indexing -->
121 <script id="vwvert" type="x-shader/x-vertex">
124 attribute vec3 Vertex;
125 attribute vec2 Tex;
126 varying vec2 TexCoord;
127 void main()
129 TexCoord = Tex;
130 float x[3];
131 x[0] = 1.0;
132 x[1] = 2.0;
133 x[2] = 3.0;
134 int idx = 4 * int(max(1.0, Vertex.x*20.0));
135 x[idx] = Vertex.z;
136 gl_Position = vec4(Vertex, x[idx]);
138 </script>
139 <script id="vert" type="x-shader/x-vertex">
142 attribute vec3 Vertex;
143 attribute vec2 Tex;
144 varying vec2 TexCoord;
145 void main()
147 TexCoord = Tex;
148 gl_Position = vec4(Vertex, 0.0);
150 </script>
152 <script id="okfrag" type="x-shader/x-fragment">
155 precision mediump float;
157 varying vec2 TexCoord;
159 void main()
161 float x[3];
162 x[0] = 1.0;
163 x[1] = 2.0;
164 x[2] = 3.0;
165 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[2]);
167 </script>
168 <script id="crfrag" type="x-shader/x-fragment">
171 precision mediump float;
173 varying vec2 TexCoord;
175 void main()
177 float x[3];
178 x[0] = 1.0;
179 x[1] = 2.0;
180 x[2] = 3.0;
181 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[4]);
183 </script>
184 <script id="cwfrag" type="x-shader/x-fragment">
187 precision mediump float;
189 varying vec2 TexCoord;
191 void main()
193 float x[3];
194 x[0] = 1.0;
195 x[1] = 2.0;
196 x[2] = 3.0;
198 x[4] = 6.0;
199 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[4]);
201 </script>
202 <!-- This one actually fails because of WebGL's restrictions on indexing expressions in fragment shaders -->
203 <script id="vrfrag" type="x-shader/x-fragment">
206 precision mediump float;
208 varying vec2 TexCoord;
210 void main()
212 float x[3];
213 x[0] = 1.0;
214 x[1] = 2.0;
215 x[2] = 3.0;
217 int idx = 4 * int(max(1.0, TexCoord.x*20.0));
218 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[idx]);
220 </script>
221 <!-- This one actually fails because of WebGL's restrictions on indexing expressions in fragment shaders -->
222 <script id="vwfrag" type="x-shader/x-fragment">
225 precision mediump float;
227 varying vec2 TexCoord;
229 void main()
231 float x[3];
232 x[0] = 1.0;
233 x[1] = 2.0;
234 x[2] = 3.0;
236 int idx = 4 * int(max(1.0, TexCoord.x*20.0));
237 x[idx] = 6.0;
238 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, x[idx]);
240 </script>
241 <script id="frag" type="x-shader/x-fragment">
244 precision mediump float;
246 varying vec2 TexCoord;
248 void main()
250 gl_FragColor = vec4(1.0, 0.0, TexCoord.s, 1.0);
252 </script>
255 <style>canvas{ position:absolute; }</style>
256 </head><body>
257 <canvas id="gl" width="16" height="16"></canvas>
258 </body></html>