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>WebGL WEBGL_draw_buffers gl_FragData[gl_MaxDrawBuffers] Conformance Test
</title>
12 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
13 <script src=
"../../js/js-test-pre.js"></script>
14 <script src=
"../../js/webgl-test-utils.js"></script>
17 <div id=
"description"></div>
18 <canvas id=
"canvas" width=
"64" height=
"64"> </canvas>
19 <div id=
"console"></div>
20 <script id=
"vshader" type=
"x-shader/x-vertex">
21 attribute vec4 a_position;
23 gl_Position = a_position;
26 <script id=
"fshader" type=
"x-shader/x-fragment">
27 #extension GL_EXT_draw_buffers : require
28 precision mediump float;
30 gl_FragData[gl_MaxDrawBuffers] = vec4(
0.0);
33 <script id=
"fshaderConstantIndex" type=
"x-shader/x-fragment">
34 #extension GL_EXT_draw_buffers : require
35 precision mediump float;
37 gl_FragData[$(gl_MaxDrawBuffers)] = vec4(
0.0);
40 <script id=
"fshaderTestMaxDrawBuffersValue" type=
"x-shader/x-fragment">
41 #extension GL_EXT_draw_buffers : require
42 precision mediump float;
44 gl_FragColor = ($(gl_MaxDrawBuffers) == gl_MaxDrawBuffers) ? vec4(
0,
1,
0,
1) : vec4(
1,
0,
0,
1);
49 description("This test verifies that compiling the same shader using GL_EXT_draw_buffers twice will have similar results on both rounds.");
53 var wtu
= WebGLTestUtils
;
54 var canvas
= document
.getElementById("canvas");
55 var gl
= wtu
.create3DContext(canvas
);
60 testFailed("WebGL context does not exist");
62 testPassed("WebGL context exists");
64 ext
= gl
.getExtension("WEBGL_draw_buffers");
66 testPassed("No WEBGL_draw_buffers support -- this is legal");
69 testPassed("Successfully enabled WEBGL_draw_buffers extension");
70 maxDrawBuffers
= gl
.getParameter(ext
.MAX_DRAW_BUFFERS_WEBGL
);
76 function testValueOfMaxDrawBuffers() {
77 debug("Test the value of gl_MaxDrawBuffers in a shader");
78 var fshader
= wtu
.replaceParams(wtu
.getScript("fshaderTestMaxDrawBuffersValue"), {"gl_MaxDrawBuffers": maxDrawBuffers
});
79 var program
= wtu
.setupProgram(gl
, ["vshader", fshader
], ["a_position"], undefined, true);
80 expectTrue(program
!= null, "Test program should compile");
81 wtu
.setupUnitQuad(gl
);
82 wtu
.clearAndDrawUnitQuad(gl
);
83 wtu
.checkCanvas(gl
, [0, 255, 0, 255], "should be green to indicate that gl_MaxDrawBuffers had the right value");
84 gl
.deleteProgram(program
);
85 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "there should be no errors");
88 function runSingleTest(shaders
, indexMsg
) {
89 var program
= wtu
.setupProgram(gl
, shaders
, ["a_position"], undefined, true);
90 var programLinkedSuccessfully
= (program
!= null);
91 expectTrue(!programLinkedSuccessfully
, "Program where gl_FragData is indexed by " + indexMsg
+ " should fail compilation.");
92 gl
.deleteProgram(program
);
95 function runShadersTest() {
96 debug("MAX_DRAW_BUFFERS_WEBGL is: " + maxDrawBuffers
);
98 // For reference, use a constant out-of-range parameter to test:
99 debug("Test indexing gl_FragData with value of MAX_DRAW_BUFFERS_WEBGL");
100 var fshader
= wtu
.replaceParams(wtu
.getScript("fshaderConstantIndex"), {"gl_MaxDrawBuffers": maxDrawBuffers
});
101 runSingleTest(["vshader", fshader
], maxDrawBuffers
+ " (value of MAX_DRAW_BUFFERS_WEBGL)");
105 debug("Test indexing gl_FragData with gl_MaxDrawBuffers");
106 debug("Repeat this test twice as that has revealed a bug.");
107 for (var i
= 0; i
< 2; ++i
) {
108 runSingleTest(["vshader", "fshader"], "gl_MaxDrawBuffers");
110 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
, "there should be no errors");
114 testValueOfMaxDrawBuffers();