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 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>
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;
24 gl_Position = vPosition;
27 <script id=
"outputFragmentShader" type=
"x-shader/x-fragment">
28 precision mediump float;
31 gl_FragColor = uColor;
37 description("This test verifies the functionality of the EXT_blend_minmax extension, if it is available.");
41 var wtu
= WebGLTestUtils
;
42 var canvas
= document
.getElementById("canvas");
43 var gl
= wtu
.create3DContext(canvas
);
46 // Use the constant directly when we don't have the extension
51 testFailed("WebGL context does not exist");
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");
60 testPassed("No EXT_blend_minmax support -- this is legal");
62 runSupportedTest(false);
65 testPassed("Successfully enabled EXT_blend_minmax extension");
67 runSupportedTest(true);
69 runBlendTestEnabled();
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");
81 testFailed("EXT_blend_minmax listed as supported but getExtension failed");
84 if (extensionEnabled
) {
85 testFailed("EXT_blend_minmax not listed as supported but getExtension succeeded");
87 testPassed("EXT_blend_minmax not listed as supported and getExtension failed -- this is legal");
92 function runBlendTestDisabled() {
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() {
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
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
);
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");
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]);
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]);
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]);
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()
212 debug("Testing that getExtension() returns the same object each time");
214 gl
.getExtension("EXT_blend_minmax").myProperty
= 2;
215 webglHarnessCollectGarbage();
216 shouldBe('gl.getExtension("EXT_blend_minmax").myProperty', '2');
220 var successfullyParsed
= true;
222 <script src=
"../../js/js-test-post.js"></script>