2 Copyright (c) 2019 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <meta charset=
"utf-8">
11 <title>Global variable initializer restrictions
</title>
12 <link rel=
"stylesheet" href=
"../../../resources/js-test-style.css"/>
13 <link rel=
"stylesheet" href=
"../../../resources/glsl-feature-tests.css"/>
14 <script src=
"../../../js/js-test-pre.js"></script>
15 <script src=
"../../../js/webgl-test-utils.js"></script>
16 <script src=
"../../../js/glsl-conformance-test.js"></script>
19 <div id=
"description"></div>
20 <div id=
"console"></div>
21 <script id=
"constGlobalShader" type=
"x-shader/x-vertex">
22 precision mediump float;
23 attribute vec4 aPosition;
31 gl_Position = aPosition;
34 <script id=
"globalShader" type=
"x-shader/x-vertex">
35 precision mediump float;
36 attribute vec4 aPosition;
44 gl_Position = aPosition;
47 <script id=
"uniformShader" type=
"x-shader/x-vertex">
48 precision mediump float;
49 attribute vec4 aPosition;
57 gl_Position = aPosition;
60 <script id=
"builtinFunctionShader" type=
"x-shader/x-vertex">
61 precision mediump float;
62 attribute vec4 aPosition;
70 gl_Position = aPosition;
73 <script id=
"builtinTextureFunctionShader" type=
"x-shader/x-vertex">
74 precision mediump float;
75 attribute vec4 aPosition;
79 float f = texture2DLod(s, vec2(
0.5,
0.5),
0.0).x;
83 gl_Position = aPosition;
86 <script id=
"attributeShader" type=
"x-shader/x-vertex">
87 precision mediump float;
88 attribute vec4 aPosition;
91 float f = aPosition.x;
95 gl_Position = aPosition;
98 <script id=
"userDefinedFunctionShader" type=
"x-shader/x-vertex">
99 precision mediump float;
100 attribute vec4 aPosition;
110 gl_Position = aPosition;
113 <script id=
"varyingShader" type=
"x-shader/x-fragment">
114 precision mediump float;
119 gl_FragColor = vec4(f);
122 <script id=
"globalLValueShader" type=
"x-shader/x-vertex">
123 precision mediump float;
124 attribute vec4 aPosition;
132 gl_Position = aPosition;
135 <script id=
"globalLValueShader2" type=
"x-shader/x-vertex">
136 precision mediump float;
137 attribute vec4 aPosition;
145 gl_Position = aPosition;
148 <script id=
"globalNonConstTernary" type=
"x-shader/x-fragment">
149 precision mediump float;
152 float f = true ? green : black;
155 gl_FragColor = vec4(
0.0, f,
0.0,
1.0);
158 <script id=
"globalUniformTernary" type=
"x-shader/x-fragment">
159 precision mediump float;
160 uniform float u_zero;
161 float green =
1.0 + u_zero;
162 float f = true ? green : u_zero;
165 gl_FragColor = vec4(
0.0, f,
0.0,
1.0);
168 <script id=
"globalUniformTernary2" type=
"x-shader/x-fragment">
169 precision mediump float;
170 uniform float u_zero;
172 float f = (u_zero <
0.1) ? green :
0.0;
175 gl_FragColor = vec4(
0.0, f,
0.0,
1.0);
178 <script id=
"globalUniformStruct" type=
"x-shader/x-fragment">
179 precision mediump float;
188 float green = (s.one ==
1) ?
1.0 :
0.0;
189 gl_FragColor = vec4(
0.0, green,
0.0,
1.0);
192 <script id=
"builtInConstant" type=
"x-shader/x-fragment">
193 precision mediump float;
194 int i = gl_MaxFragmentUniformVectors;
197 float green = (i
> 0) ?
1.0 :
0.0;
198 gl_FragColor = vec4(
0.0, green,
0.0,
1.0);
201 <script id=
"builtInNonConstant" type=
"x-shader/x-fragment">
202 precision mediump float;
203 vec4 v = gl_FragCoord;
209 <script type=
"application/javascript">
212 GLSLConformanceTester.runTests([
214 vShaderId:
"constGlobalShader",
215 vShaderSuccess: true,
217 passMsg:
"A const global in a global variable initializer should be accepted by WebGL."
220 vShaderId:
"globalShader",
221 vShaderSuccess: true,
223 passMsg:
"Another global in a global variable initializer should be accepted by WebGL."
226 vShaderId:
"uniformShader",
227 vShaderSuccess: true,
229 passMsg:
"A uniform in a global variable initializer should be accepted by WebGL."
232 vShaderId:
"builtinFunctionShader",
233 vShaderSuccess: true,
235 passMsg:
"A built-in math function in a global variable initializer should be accepted by WebGL."
238 vShaderId:
"builtinTextureFunctionShader",
239 vShaderSuccess: false,
241 passMsg:
"A texture lookup function in a global variable initializer should not be accepted by WebGL."
244 vShaderId:
"attributeShader",
245 vShaderSuccess: false,
247 passMsg:
"An attribute in a global variable initializer should not be accepted by WebGL."
250 vShaderId:
"userDefinedFunctionShader",
251 vShaderSuccess: false,
253 passMsg:
"A user-defined function call in a global variable initializer should not be accepted by WebGL."
256 vShaderId:
"constGlobalShader",
257 vShaderSuccess: true,
258 fShaderId:
"varyingShader",
259 fShaderSuccess: false,
261 passMsg:
"A varying in a global variable initializer should not be accepted by WebGL."
264 vShaderId:
"globalLValueShader",
265 vShaderSuccess: false,
267 passMsg:
"Another global as an l-value in a global variable initializer should not be accepted by WebGL."
270 vShaderId:
"globalLValueShader2",
271 vShaderSuccess: false,
273 passMsg:
"Another global as an l-value (parameter of ++) in a global variable initializer should not be accepted by WebGL."
276 fShaderId:
"globalNonConstTernary",
277 fShaderSuccess: true,
280 passMsg:
"Non-const global variables as operands for a ternary operator in a global variable initializer should be accepted by WebGL."
283 fShaderId:
"globalUniformTernary",
284 fShaderSuccess: true,
287 passMsg:
"A uniform as the second operand for a ternary operator in a global variable initializer should be accepted by WebGL."
290 fShaderId:
"globalUniformTernary2",
291 fShaderSuccess: true,
294 passMsg:
"Referencing a uniform inside the first operand for a ternary operator in a global variable initializer should be accepted by WebGL."
297 fShaderId:
"globalUniformStruct",
298 fShaderSuccess: true,
302 { name: 'us.one', functionName: 'uniform1i', value:
1 }
304 passMsg:
"A global struct initialized with a uniform struct should be accepted by WebGL."
307 fShaderId:
"builtInConstant",
308 fShaderSuccess: true,
311 passMsg:
"Referencing a built-in constant in a global variable initializer should be accepted by WebGL."
314 fShaderId:
"builtInNonConstant",
315 fShaderSuccess: false,
317 passMsg:
"Referencing a built-in non-constant in a global variable initializer should not be accepted by WebGL."
320 var successfullyParsed = true;