4 ** Copyright (c) 2014 The Khronos Group Inc.
6 ** Permission is hereby granted, free of charge, to any person obtaining a
7 ** copy of this software and/or associated documentation files (the
8 ** "Materials"), to deal in the Materials without restriction, including
9 ** without limitation the rights to use, copy, modify, merge, publish,
10 ** distribute, sublicense, and/or sell copies of the Materials, and to
11 ** permit persons to whom the Materials are furnished to do so, subject to
12 ** the following conditions:
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
17 ** THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 ** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 ** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 ** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 ** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 ** TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 ** MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
31 <meta charset="utf-8">
32 <title>WebGL EXT_blend_minmax Conformance Tests</title>
33 <link rel="stylesheet" href="../../resources/js-test-style.css"/>
34 <script src="../../resources/js-test-pre.js"></script>
35 <script src="../resources/webgl-test-utils.js"></script>
38 <div id="description"></div>
39 <canvas id="canvas" style="width: 50px; height: 50px;"> </canvas>
40 <div id="console"></div>
41 <!-- Shaders to test output -->
42 <script id="outputVertexShader" type="x-shader/x-vertex">
43 attribute vec4 vPosition;
45 gl_Position = vPosition;
48 <script id="outputFragmentShader" type="x-shader/x-fragment">
49 precision mediump float;
52 gl_FragColor = uColor;
58 description("This test verifies the functionality of the EXT_blend_minmax extension, if it is available.");
62 var wtu = WebGLTestUtils;
63 var canvas = document.getElementById("canvas");
64 var gl = wtu.create3DContext(canvas);
67 // Use the constant directly when we don't have the extension
72 testFailed("WebGL context does not exist");
74 testPassed("WebGL context exists");
76 runBlendTestDisabled();
78 // Query the extension and store globally so shouldBe can access it
79 ext = wtu.getExtensionWithKnownPrefixes(gl, "EXT_blend_minmax");
81 testPassed("No EXT_blend_minmax support -- this is legal");
83 runSupportedTest(false);
86 testPassed("Successfully enabled EXT_blend_minmax extension");
88 runSupportedTest(true);
90 runBlendTestEnabled();
92 runUniqueObjectTest();
96 function runSupportedTest(extensionEnabled) {
97 var supported = gl.getSupportedExtensions();
98 if (supported.indexOf("EXT_blend_minmax") >= 0) {
99 if (extensionEnabled) {
100 testPassed("EXT_blend_minmax listed as supported and getExtension succeeded");
102 testFailed("EXT_blend_minmax listed as supported but getExtension failed");
105 if (extensionEnabled) {
106 testFailed("EXT_blend_minmax not listed as supported but getExtension succeeded");
108 testPassed("EXT_blend_minmax not listed as supported and getExtension failed -- this is legal");
113 function runBlendTestDisabled() {
115 debug("Testing blending enums with extension disabled");
117 // Set the blend equation to a known-good enum first
118 gl.blendEquation(gl.FUNC_ADD);
120 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MIN_EXT)");
121 shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
123 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MAX_EXT)");
124 shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
126 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(MIN_EXT, gl.FUNC_ADD)");
127 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
129 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(gl.FUNC_ADD, MIN_EXT)");
130 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
132 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(MAX_EXT, gl.FUNC_ADD)");
133 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
135 wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquationSeparate(gl.FUNC_ADD, MAX_EXT)");
136 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
139 function runBlendTestEnabled() {
141 debug("Testing blending enums with extension enabled");
143 shouldBe("ext.MIN_EXT", "0x8007");
144 shouldBe("ext.MAX_EXT", "0x8008");
146 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MIN_EXT)");
147 shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MIN_EXT");
149 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MAX_EXT)");
150 shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MAX_EXT");
152 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(ext.MIN_EXT, gl.FUNC_ADD)");
153 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "ext.MIN_EXT");
154 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
156 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(gl.FUNC_ADD, ext.MIN_EXT)");
157 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
158 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "ext.MIN_EXT");
160 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(ext.MAX_EXT, gl.FUNC_ADD)");
161 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "ext.MAX_EXT");
162 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "gl.FUNC_ADD");
164 wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquationSeparate(gl.FUNC_ADD, ext.MAX_EXT)");
165 shouldBe("gl.getParameter(gl.BLEND_EQUATION_RGB)", "gl.FUNC_ADD");
166 shouldBe("gl.getParameter(gl.BLEND_EQUATION_ALPHA)", "ext.MAX_EXT");
169 function runOutputTests() {
170 var e = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
173 debug("Testing various draws for valid blending behavior");
175 canvas.width = 50; canvas.height = 50;
176 gl.viewport(0, 0, canvas.width, canvas.height);
178 gl.blendFunc(gl.ONE, gl.ONE);
180 var program = wtu.setupProgram(gl, ["outputVertexShader", "outputFragmentShader"], ['vPosition'], [0]);
181 var quadParameters = wtu.setupUnitQuad(gl, 0, 1);
182 var colorUniform = gl.getUniformLocation(program, "uColor");
186 gl.blendEquation(ext.MIN_EXT);
188 gl.clearColor(0.2, 0.4, 0.6, 0.8);
189 gl.clear(gl.COLOR_BUFFER_BIT);
191 gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
192 wtu.drawUnitQuad(gl);
194 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 51]);
197 gl.blendEquation(ext.MAX_EXT);
199 gl.clearColor(0.2, 0.4, 0.6, 0.8);
200 gl.clear(gl.COLOR_BUFFER_BIT);
202 gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
203 wtu.drawUnitQuad(gl);
205 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 204]);
208 gl.blendEquationSeparate(ext.MIN_EXT, ext.MAX_EXT);
210 gl.clearColor(0.2, 0.4, 0.6, 0.8);
211 gl.clear(gl.COLOR_BUFFER_BIT);
213 gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
214 wtu.drawUnitQuad(gl);
216 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 204]);
219 gl.blendEquationSeparate(ext.MAX_EXT, ext.MIN_EXT);
221 gl.clearColor(0.2, 0.4, 0.6, 0.8);
222 gl.clear(gl.COLOR_BUFFER_BIT);
224 gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
225 wtu.drawUnitQuad(gl);
227 wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 51]);
230 function runUniqueObjectTest()
233 debug("Testing that getExtension() returns the same object each time");
234 gl.getExtension("EXT_blend_minmax").myProperty = 2;
236 shouldBe('gl.getExtension("EXT_blend_minmax").myProperty', '2');
240 var successfullyParsed = true;
242 <script src="../../resources/js-test-post.js"></script>