2 Copyright (c) 2021 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>WebGL Conformance Tests: Verify getFragDataLocation
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/desktop-gl-constants.js"></script>
14 <script src=
"../../js/js-test-pre.js"></script>
15 <script src=
"../../js/webgl-test-utils.js"></script>
18 <div id=
"description"></div>
19 <canvas id=
"canvas" style=
"width: 4px; height: 4px;"> </canvas>
20 <div id=
"console"></div>
21 <script id=
"vs" type=
"x-shader/x-vertex">#version
300 es
23 gl_Position = vec4(
0,
0,
0,
1);
27 <script id=
"fs" type=
"x-shader/x-fragment">#version
300 es
28 precision mediump float;
29 layout(location =
2) out vec4 fragColor0;
30 layout(location =
0) out vec4 fragColor1;
32 fragColor0 = vec4(
0,
1,
0,
1);
33 fragColor1 = vec4(
1,
0,
0,
1);
37 <script id=
"fs-array" type=
"x-shader/x-fragment">#version
300 es
38 precision mediump float;
39 out vec4 fragColor[
2];
41 fragColor[
0] = vec4(
0,
1,
0,
1);
42 fragColor[
1] = vec4(
1,
0,
0,
1);
46 <script id=
"vs-es2" type=
"x-shader/x-vertex">
48 gl_Position = vec4(
0,
0,
0,
1);
51 <script id=
"fs-es2" type=
"x-shader/x-fragment">
52 precision mediump float;
54 gl_FragColor = vec4(
0,
1,
0,
1);
60 description("This test verifies getFragDataLocation behaviors.");
64 var wtu
= WebGLTestUtils
;
65 var canvas
= document
.getElementById("canvas");
66 var gl
= wtu
.create3DContext(canvas
, null, 2);
69 testFailed("WebGL context does not exist");
71 testPassed("WebGL context exists");
76 window
.program
= wtu
.setupProgram(gl
, ["vs", "fs"]);
77 window
.programArray
= wtu
.setupProgram(gl
, ["vs", "fs-array"]);
78 window
.programEs2
= wtu
.setupProgram(gl
, ["vs-es2", "fs-es2"]);
79 if (!program
|| !programArray
|| !programEs2
) {
80 testFailed("Set up program failed");
83 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "No GL error from set up");
85 shouldBe("gl.getFragDataLocation(program, 'gl_FragColor')", "-1");
86 shouldBe("gl.getFragDataLocation(programArray, 'gl_FragColor')", "-1");
87 shouldBe("gl.getFragDataLocation(programEs2, 'gl_FragColor')", "-1");
88 shouldBe("gl.getFragDataLocation(program, 'gl_FragData')", "-1");
89 shouldBe("gl.getFragDataLocation(programArray, 'gl_FragData')", "-1");
90 shouldBe("gl.getFragDataLocation(programEs2, 'gl_FragData')", "-1");
91 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "No GL error from gl_* queries");
93 var loc0
= gl
.getFragDataLocation(program
, "fragColor0");
94 var loc1
= gl
.getFragDataLocation(program
, "fragColor1");
95 if (loc0
!= 2 || loc1
!= 0) {
96 testFailed("Fail to query scalar output variable locations, " +
97 "expected: fragColor0->2, fragColor1->0, " +
98 "got: fragColor0->" + loc0
+ ", fragColor1->" + loc1
);
100 testPassed("getFragDataLocation on scalar variables works fine");
103 var loc
= gl
.getFragDataLocation(programArray
, "fragColor");
104 loc0
= gl
.getFragDataLocation(programArray
, "fragColor[0]");
105 loc1
= gl
.getFragDataLocation(programArray
, "fragColor[1]");
106 if (loc
< 0 || loc0
< 0 || loc1
< 0 || loc
!= loc0
|| loc0
+ 1 != loc1
) {
107 testFailed("Fail to query scalar output variable locations, " +
108 "expected: fragColor->0, fragColor[0]->0, fragColor[1]->1, " +
109 "got: fragColor->" + loc
+ ", fragColor[0]->" + loc0
+ ", fragColor[1]->" + loc1
);
111 testPassed("getFragDataLocation on variable arrays works fine");
113 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "No GL error from testing");
116 var successfullyParsed
= true;
118 <script src=
"../../js/js-test-post.js"></script>