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>GLSL: test that length() method called on a complex expression works
</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=
"fshaderLengthOfAssignment" type=
"x-shader/x-fragment">#version
300 es
22 precision mediump float;
24 out vec4 my_FragColor;
27 int a[
3] = int[
3](
1,
2,
3);
28 int b[
3] = int[
3](
4,
5,
6);
29 int c = (a = b).length();
30 if (c ==
3 && a[
0] ==
4 && a[
1] ==
5 && a[
2] ==
6) {
31 my_FragColor = vec4(
0,
1,
0,
1);
33 my_FragColor = vec4(
1,
0,
0,
1);
37 <script id=
"fshaderLengthOfFunctionCall" type=
"x-shader/x-fragment">#version
300 es
38 precision mediump float;
40 out vec4 my_FragColor;
42 int sideEffectCounter =
0;
51 int b = (func()).length();
52 if (sideEffectCounter ==
1 && b ==
2) {
53 my_FragColor = vec4(
0,
1,
0,
1);
55 my_FragColor = vec4(
1,
0,
0,
1);
59 <script id=
"fshaderLengthOfConstructor" type=
"x-shader/x-fragment">#version
300 es
60 precision mediump float;
62 out vec4 my_FragColor;
65 int a = (int[
1](
0)).length();
67 my_FragColor = vec4(
0,
1,
0,
1);
69 my_FragColor = vec4(
1,
0,
0,
1);
73 <script type=
"application/javascript">
76 debug('length() method is allowed to be called on arbitrary expressions returning arrays. ESSL
3.00 section
5.9 says that length is allowed on
"array names", but ESSL
3.20 has newer, clarified wording that says that it is allowed for
"arrays". This was always the intent of the spec.');
77 GLSLConformanceTester.runRenderTests([
79 fShaderId:
"fshaderLengthOfAssignment",
82 passMsg:
"Fragment shader which tries to evaluate the length of an assignment operation should succeed."
85 fShaderId:
"fshaderLengthOfFunctionCall",
88 passMsg:
"Fragment shader which tries to evaluate the length of a return value should succeed."
91 fShaderId:
"fshaderLengthOfConstructor",
94 passMsg:
"Fragment shader which tries to evaluate the length of a newly constructed array should succeed."