Backed out changeset b462e7b742d8 (bug 1908261) for causing multiple reftest failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / extensions / ext-blend-minmax.html
blob445dcb92d46f1a2264e4514cc34d8d4597df5e51
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 EXT_blend_minmax Conformance Tests</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" style="width: 50px; height: 50px;"> </canvas>
19 <div id="console"></div>
20 <!-- Shaders to test output -->
21 <script id="outputVertexShader" type="x-shader/x-vertex">
22 attribute vec4 vPosition;
23 void main() {
24 gl_Position = vPosition;
26 </script>
27 <script id="outputFragmentShader" type="x-shader/x-fragment">
28 precision mediump float;
29 uniform vec4 uColor;
30 void main() {
31 gl_FragColor = uColor;
33 </script>
35 <script>
36 "use strict";
37 description("This test verifies the functionality of the EXT_blend_minmax extension, if it is available.");
39 debug("");
41 var wtu = WebGLTestUtils;
42 var canvas = document.getElementById("canvas");
43 var gl = wtu.create3DContext(canvas);
44 var ext = null;
46 // Use the constant directly when we don't have the extension
47 var MIN_EXT = 0x8007;
48 var MAX_EXT = 0x8008;
50 if (!gl) {
51 testFailed("WebGL context does not exist");
52 } else {
53 testPassed("WebGL context exists");
55 runBlendTestDisabled();
57 // Query the extension and store globally so shouldBe can access it
58 ext = wtu.getExtensionWithKnownPrefixes(gl, "EXT_blend_minmax");
59 if (!ext) {
60 testPassed("No EXT_blend_minmax support -- this is legal");
62 runSupportedTest(false);
63 } else {
64 debug("");
65 testPassed("Successfully enabled EXT_blend_minmax extension");
67 runSupportedTest(true);
69 runBlendTestEnabled();
70 runOutputTests();
71 runUniqueObjectTest();
75 function runSupportedTest(extensionEnabled) {
76 var supported = gl.getSupportedExtensions();
77 if (supported.indexOf("EXT_blend_minmax") >= 0) {
78 if (extensionEnabled) {
79 testPassed("EXT_blend_minmax listed as supported and getExtension succeeded");
80 } else {
81 testFailed("EXT_blend_minmax listed as supported but getExtension failed");
83 } else {
84 if (extensionEnabled) {
85 testFailed("EXT_blend_minmax not listed as supported but getExtension succeeded");
86 } else {
87 testPassed("EXT_blend_minmax not listed as supported and getExtension failed -- this is legal");
92 function runBlendTestDisabled() {
93 debug("");
94 debug("Testing blending enums with extension disabled");
96 // Set the blend equation to a known-good enum first
97 gl.blendEquation(gl.FUNC_ADD);
99 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MIN_EXT)");
100 shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
102 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MAX_EXT)");
103 shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
105 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(MIN_EXT, gl.FUNC_ADD)");
106 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
108 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(gl.FUNC_ADD, MIN_EXT)");
109 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
111 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(MAX_EXT, gl.FUNC_ADD)");
112 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
114 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(gl.FUNC_ADD, MAX_EXT)");
115 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
118 function runBlendTestEnabled() {
119 debug("");
120 debug("Testing blending enums with extension enabled");
122 shouldBe("ext.MIN_EXT", "0x8007");
123 shouldBe("ext.MAX_EXT", "0x8008");
125 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MIN_EXT)");
126 shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MIN_EXT");
128 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MAX_EXT)");
129 shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MAX_EXT");
131 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(ext.MIN_EXT, gl.FUNC_ADD)");
132 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "ext.MIN_EXT");
133 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
135 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(gl.FUNC_ADD, ext.MIN_EXT)");
136 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
137 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "ext.MIN_EXT");
139 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(ext.MAX_EXT, gl.FUNC_ADD)");
140 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "ext.MAX_EXT");
141 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
143 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(gl.FUNC_ADD, ext.MAX_EXT)");
144 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
145 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "ext.MAX_EXT");
148 function runOutputTests() {
149 var e = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
151 debug("");
152 debug("Testing various draws for valid blending behavior");
154 canvas.width = 50; canvas.height = 50;
155 gl.viewport(0, 0, canvas.width, canvas.height);
156 gl.enable(gl.BLEND);
157 gl.blendFunc(gl.ONE, gl.ONE);
159 var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition'], [0]);
160 var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
161 var colorUniform = gl.getUniformLocation(program, "uColor");
164 // Draw 1
165 gl.blendEquation(ext.MIN_EXT);
167 gl.clearColor(0.2, 0.4, 0.6, 0.8);
168 gl.clear(gl.COLOR_BUFFER_BIT);
170 gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
171 wtu.drawUnitQuad(gl);
173 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 51]);
175 // Draw 2:
176 gl.blendEquation(ext.MAX_EXT);
178 gl.clearColor(0.2, 0.4, 0.6, 0.8);
179 gl.clear(gl.COLOR_BUFFER_BIT);
181 gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
182 wtu.drawUnitQuad(gl);
184 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 204]);
186 // Draw 3
187 gl.blendEquationSeparate(ext.MIN_EXT, ext.MAX_EXT);
189 gl.clearColor(0.2, 0.4, 0.6, 0.8);
190 gl.clear(gl.COLOR_BUFFER_BIT);
192 gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
193 wtu.drawUnitQuad(gl);
195 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 204]);
197 // Draw 4
198 gl.blendEquationSeparate(ext.MAX_EXT, ext.MIN_EXT);
200 gl.clearColor(0.2, 0.4, 0.6, 0.8);
201 gl.clear(gl.COLOR_BUFFER_BIT);
203 gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
204 wtu.drawUnitQuad(gl);
206 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 51]);
209 function runUniqueObjectTest()
211 debug("");
212 debug("Testing that getExtension() returns the same object each time");
213 ext = null;
214 gl.getExtension("EXT_blend_minmax").myProperty = 2;
215 webglHarnessCollectGarbage();
216 shouldBe('gl.getExtension("EXT_blend_minmax").myProperty', '2');
219 debug("");
220 var successfullyParsed = true;
221 </script>
222 <script src="../../js/js-test-post.js"></script>
224 </body>
225 </html>