Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / extensions / webgl-draw-buffers-max-draw-buffers.html
blob8181a6a5870b482a6fc978cfe39efb457706ddb8
1 <!--
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.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
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>
15 </head>
16 <body>
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;
22 void main() {
23 gl_Position = a_position;
25 </script>
26 <script id="fshader" type="x-shader/x-fragment">
27 #extension GL_EXT_draw_buffers : require
28 precision mediump float;
29 void main() {
30 gl_FragData[gl_MaxDrawBuffers] = vec4(0.0);
32 </script>
33 <script id="fshaderConstantIndex" type="x-shader/x-fragment">
34 #extension GL_EXT_draw_buffers : require
35 precision mediump float;
36 void main() {
37 gl_FragData[$(gl_MaxDrawBuffers)] = vec4(0.0);
39 </script>
40 <script id="fshaderTestMaxDrawBuffersValue" type="x-shader/x-fragment">
41 #extension GL_EXT_draw_buffers : require
42 precision mediump float;
43 void main() {
44 gl_FragColor = ($(gl_MaxDrawBuffers) == gl_MaxDrawBuffers) ? vec4(0, 1, 0, 1) : vec4(1, 0, 0, 1);
46 </script>
47 <script>
48 "use strict";
49 description("This test verifies that compiling the same shader using GL_EXT_draw_buffers twice will have similar results on both rounds.");
51 debug("");
53 var wtu = WebGLTestUtils;
54 var canvas = document.getElementById("canvas");
55 var gl = wtu.create3DContext(canvas);
56 var ext = null;
57 var maxDrawBuffers;
59 if (!gl) {
60 testFailed("WebGL context does not exist");
61 } else {
62 testPassed("WebGL context exists");
64 ext = gl.getExtension("WEBGL_draw_buffers");
65 if (!ext) {
66 testPassed("No WEBGL_draw_buffers support -- this is legal");
67 finishTest();
68 } else {
69 testPassed("Successfully enabled WEBGL_draw_buffers extension");
70 maxDrawBuffers = gl.getParameter(ext.MAX_DRAW_BUFFERS_WEBGL);
71 runShadersTest();
72 finishTest();
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)");
103 debug("");
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");
112 debug("");
114 testValueOfMaxDrawBuffers();
116 </script>
117 </body>
118 </html>