summaryrefslogtreecommitdiffstats
path: root/dom/canvas/test/webgl-conf/checkout/conformance/glsl/misc/global-variable-init.html
blob: 99e7417f69cf1ad5796b916e720bb8c8b938199a (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<!--
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>Global variable initializer restrictions</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>
<script src="../../../js/glsl-conformance-test.js"></script>
</head>
<body>
<div id="description"></div>
<div id="console"></div>
<script id="constGlobalShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

const float c = 1.0;
float f = c;

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="globalShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

float c = 1.0;
float f = c;

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="uniformShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

uniform float u;
float f = u;

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="builtinFunctionShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

float c = 1.0;
float f = sin(c);

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="builtinTextureFunctionShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

uniform sampler2D s;
float f = texture2DLod(s, vec2(0.5, 0.5), 0.0).x;

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="attributeShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

float f = aPosition.x;

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="userDefinedFunctionShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

float foo() {
    return 1.0;
}
float f = foo();

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="varyingShader" type="x-shader/x-fragment">
precision mediump float;
varying float v;
float f = v;

void main() {
    gl_FragColor = vec4(f);
}
</script>
<script id="globalLValueShader" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

float c = 1.0;
float f = (c = 0.0);

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="globalLValueShader2" type="x-shader/x-vertex">
precision mediump float;
attribute vec4 aPosition;
varying float v;

float c = 1.0;
float f = (c++);

void main() {
    v = f;
    gl_Position = aPosition;
}
</script>
<script id="globalNonConstTernary" type="x-shader/x-fragment">
precision mediump float;
float green = 1.0;
float black = 0.0;
float f = true ? green : black;

void main() {
    gl_FragColor = vec4(0.0, f, 0.0, 1.0);
}
</script>
<script id="globalUniformTernary" type="x-shader/x-fragment">
precision mediump float;
uniform float u_zero;
float green = 1.0 + u_zero;
float f = true ? green : u_zero;

void main() {
    gl_FragColor = vec4(0.0, f, 0.0, 1.0);
}
</script>
<script id="globalUniformTernary2" type="x-shader/x-fragment">
precision mediump float;
uniform float u_zero;
float green = 1.0;
float f = (u_zero < 0.1) ? green : 0.0;

void main() {
    gl_FragColor = vec4(0.0, f, 0.0, 1.0);
}
</script>
<script id="globalUniformStruct" type="x-shader/x-fragment">
precision mediump float;
struct S {
    float zero;
    int one;
};
uniform S us;
S s = us;

void main() {
    float green = (s.one == 1) ? 1.0 : 0.0;
    gl_FragColor = vec4(0.0, green, 0.0, 1.0);
}
</script>
<script id="builtInConstant" type="x-shader/x-fragment">
precision mediump float;
int i = gl_MaxFragmentUniformVectors;

void main() {
    float green = (i > 0) ? 1.0 : 0.0;
    gl_FragColor = vec4(0.0, green, 0.0, 1.0);
}
</script>
<script id="builtInNonConstant" type="x-shader/x-fragment">
precision mediump float;
vec4 v = gl_FragCoord;

void main() {
    gl_FragColor = v;
}
</script>
<script type="application/javascript">
"use strict";
description();
GLSLConformanceTester.runTests([
  {
    vShaderId: "constGlobalShader",
    vShaderSuccess: true,
    linkSuccess: true,
    passMsg: "A const global in a global variable initializer should be accepted by WebGL."
  },
  {
    vShaderId: "globalShader",
    vShaderSuccess: true,
    linkSuccess: true,
    passMsg: "Another global in a global variable initializer should be accepted by WebGL."
  },
  {
    vShaderId: "uniformShader",
    vShaderSuccess: true,
    linkSuccess: true,
    passMsg: "A uniform in a global variable initializer should be accepted by WebGL."
  },
  {
    vShaderId: "builtinFunctionShader",
    vShaderSuccess: true,
    linkSuccess: true,
    passMsg: "A built-in math function in a global variable initializer should be accepted by WebGL."
  },
  {
    vShaderId: "builtinTextureFunctionShader",
    vShaderSuccess: false,
    linkSuccess: false,
    passMsg: "A texture lookup function in a global variable initializer should not be accepted by WebGL."
  },
  {
    vShaderId: "attributeShader",
    vShaderSuccess: false,
    linkSuccess: false,
    passMsg: "An attribute in a global variable initializer should not be accepted by WebGL."
  },
  {
    vShaderId: "userDefinedFunctionShader",
    vShaderSuccess: false,
    linkSuccess: false,
    passMsg: "A user-defined function call in a global variable initializer should not be accepted by WebGL."
  },
  {
    vShaderId: "constGlobalShader",
    vShaderSuccess: true,
    fShaderId: "varyingShader",
    fShaderSuccess: false,
    linkSuccess: false,
    passMsg: "A varying in a global variable initializer should not be accepted by WebGL."
  },
  {
    vShaderId: "globalLValueShader",
    vShaderSuccess: false,
    linkSuccess: false,
    passMsg: "Another global as an l-value in a global variable initializer should not be accepted by WebGL."
  },
  {
    vShaderId: "globalLValueShader2",
    vShaderSuccess: false,
    linkSuccess: false,
    passMsg: "Another global as an l-value (parameter of ++) in a global variable initializer should not be accepted by WebGL."
  },
  {
    fShaderId: "globalNonConstTernary",
    fShaderSuccess: true,
    linkSuccess: true,
    render: true,
    passMsg: "Non-const global variables as operands for a ternary operator in a global variable initializer should be accepted by WebGL."
  },
  {
    fShaderId: "globalUniformTernary",
    fShaderSuccess: true,
    linkSuccess: true,
    render: true,
    passMsg: "A uniform as the second operand for a ternary operator in a global variable initializer should be accepted by WebGL."
  },
  {
    fShaderId: "globalUniformTernary2",
    fShaderSuccess: true,
    linkSuccess: true,
    render: true,
    passMsg: "Referencing a uniform inside the first operand for a ternary operator in a global variable initializer should be accepted by WebGL."
  },
  {
    fShaderId: "globalUniformStruct",
    fShaderSuccess: true,
    linkSuccess: true,
    render: true,
    uniforms: [
        { name: 'us.one', functionName: 'uniform1i', value: 1 }
    ],
    passMsg: "A global struct initialized with a uniform struct should be accepted by WebGL."
  },
  {
    fShaderId: "builtInConstant",
    fShaderSuccess: true,
    linkSuccess: true,
    render: true,
    passMsg: "Referencing a built-in constant in a global variable initializer should be accepted by WebGL."
  },
  {
    fShaderId: "builtInNonConstant",
    fShaderSuccess: false,
    linkSuccess: false,
    passMsg: "Referencing a built-in non-constant in a global variable initializer should not be accepted by WebGL."
  }
]);
var successfullyParsed = true;
</script>
</body>
</html>