Source code
Revision control
Copy as Markdown
Other Tools
<!--
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>GLSL: test that length() method called on a complex expression works</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="fshaderLengthOfAssignment" type="x-shader/x-fragment">#version 300 es
precision mediump float;
out vec4 my_FragColor;
void main() {
int a[3] = int[3](1, 2, 3);
int b[3] = int[3](4, 5, 6);
int c = (a = b).length();
if (c == 3 && a[0] == 4 && a[1] == 5 && a[2] == 6) {
my_FragColor = vec4(0, 1, 0, 1);
} else {
my_FragColor = vec4(1, 0, 0, 1);
}
}
</script>
<script id="fshaderLengthOfFunctionCall" type="x-shader/x-fragment">#version 300 es
precision mediump float;
out vec4 my_FragColor;
int sideEffectCounter = 0;
int[2] func() {
++sideEffectCounter;
int a[2];
return a;
}
void main() {
int b = (func()).length();
if (sideEffectCounter == 1 && b == 2) {
my_FragColor = vec4(0, 1, 0, 1);
} else {
my_FragColor = vec4(1, 0, 0, 1);
}
}
</script>
<script id="fshaderLengthOfConstructor" type="x-shader/x-fragment">#version 300 es
precision mediump float;
out vec4 my_FragColor;
void main() {
int a = (int[1](0)).length();
if (a == 1) {
my_FragColor = vec4(0, 1, 0, 1);
} else {
my_FragColor = vec4(1, 0, 0, 1);
}
}
</script>
<script type="application/javascript">
"use strict";
description();
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.');
GLSLConformanceTester.runRenderTests([
{
fShaderId: "fshaderLengthOfAssignment",
fShaderSuccess: true,
linkSuccess: true,
passMsg: "Fragment shader which tries to evaluate the length of an assignment operation should succeed."
},
{
fShaderId: "fshaderLengthOfFunctionCall",
fShaderSuccess: true,
linkSuccess: true,
passMsg: "Fragment shader which tries to evaluate the length of a return value should succeed."
},
{
fShaderId: "fshaderLengthOfConstructor",
fShaderSuccess: true,
linkSuccess: true,
passMsg: "Fragment shader which tries to evaluate the length of a newly constructed array should succeed."
}
], 2);
</script>
</body>
</html>