Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / webgl / src / sdk / tests / conformance / extensions / ext-blend-minmax.html
1 <!--
2
3 /*
4 ** Copyright (c) 2014 The Khronos Group Inc.
5 **
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:
13 **
14 ** The above copyright notice and this permission notice shall be included
15 ** in all copies or substantial portions of the Materials.
16 **
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.
24 */
25
26 -->
27
28 <!DOCTYPE html>
29 <html>
30 <head>
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>
36 </head>
37 <body>
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;
44 void main() {
45     gl_Position = vPosition;
46 }
47 </script>
48 <script id="outputFragmentShader" type="x-shader/x-fragment">
49 precision mediump float;
50 uniform vec4 uColor;
51 void main() {
52     gl_FragColor = uColor;
53 }
54 </script>
55
56 <script>
57 "use strict";
58 description("This test verifies the functionality of the EXT_blend_minmax extension, if it is available.");
59
60 debug("");
61
62 var wtu = WebGLTestUtils;
63 var canvas = document.getElementById("canvas");
64 var gl = wtu.create3DContext(canvas);
65 var ext = null;
66
67 // Use the constant directly when we don't have the extension
68 var MIN_EXT = 0x8007;
69 var MAX_EXT = 0x8008;
70
71 if (!gl) {
72     testFailed("WebGL context does not exist");
73 } else {
74     testPassed("WebGL context exists");
75
76     runBlendTestDisabled();
77
78     // Query the extension and store globally so shouldBe can access it
79     ext = wtu.getExtensionWithKnownPrefixes(gl, "EXT_blend_minmax");
80     if (!ext) {
81         testPassed("No EXT_blend_minmax support -- this is legal");
82
83         runSupportedTest(false);
84     } else {
85         debug("");
86         testPassed("Successfully enabled EXT_blend_minmax extension");
87
88         runSupportedTest(true);
89
90         runBlendTestEnabled();
91         runOutputTests();
92         runUniqueObjectTest();
93     }
94 }
95
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");
101         } else {
102             testFailed("EXT_blend_minmax listed as supported but getExtension failed");
103         }
104     } else {
105         if (extensionEnabled) {
106             testFailed("EXT_blend_minmax not listed as supported but getExtension succeeded");
107         } else {
108             testPassed("EXT_blend_minmax not listed as supported and getExtension failed -- this is legal");
109         }
110     }
111 }
112
113 function runBlendTestDisabled() {
114     debug("");
115     debug("Testing blending enums with extension disabled");
116
117     // Set the blend equation to a known-good enum first
118     gl.blendEquation(gl.FUNC_ADD);
119
120     wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MIN_EXT)");
121     shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
122
123     wtu.shouldGenerateGLError(gl, gl.INVALID_ENUM, "gl.blendEquation(MAX_EXT)");
124     shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "gl.FUNC_ADD");
125
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");
128
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");
131
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");
134
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");
137 }
138
139 function runBlendTestEnabled() {
140     debug("");
141     debug("Testing blending enums with extension enabled");
142
143     shouldBe("ext.MIN_EXT", "0x8007");
144     shouldBe("ext.MAX_EXT", "0x8008");
145
146     wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MIN_EXT)");
147     shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MIN_EXT");
148
149     wtu.shouldGenerateGLError(gl, gl.NO_ERROR, "gl.blendEquation(ext.MAX_EXT)");
150     shouldBe("gl.getParameter(gl.BLEND_EQUATION)", "ext.MAX_EXT");
151
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");
155
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");
159
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");
163
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");
167 }
168
169 function runOutputTests() {
170     var e = 2; // Amount of variance to allow in result pixels - may need to be tweaked higher
171
172     debug("");
173     debug("Testing various draws for valid blending behavior");
174
175     canvas.width = 50; canvas.height = 50;
176     gl.viewport(0, 0, canvas.width, canvas.height);
177     gl.enable(gl.BLEND);
178     gl.blendFunc(gl.ONE, gl.ONE);
179
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");
183
184
185     // Draw 1
186     gl.blendEquation(ext.MIN_EXT);
187
188     gl.clearColor(0.2, 0.4, 0.6, 0.8);
189     gl.clear(gl.COLOR_BUFFER_BIT);
190
191     gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
192     wtu.drawUnitQuad(gl);
193
194     wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 51]);
195
196     // Draw 2:
197     gl.blendEquation(ext.MAX_EXT);
198
199     gl.clearColor(0.2, 0.4, 0.6, 0.8);
200     gl.clear(gl.COLOR_BUFFER_BIT);
201
202     gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
203     wtu.drawUnitQuad(gl);
204
205     wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 204]);
206
207     // Draw 3
208     gl.blendEquationSeparate(ext.MIN_EXT, ext.MAX_EXT);
209
210     gl.clearColor(0.2, 0.4, 0.6, 0.8);
211     gl.clear(gl.COLOR_BUFFER_BIT);
212
213     gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
214     wtu.drawUnitQuad(gl);
215
216     wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [51, 102, 102, 204]);
217
218     // Draw 4
219     gl.blendEquationSeparate(ext.MAX_EXT, ext.MIN_EXT);
220
221     gl.clearColor(0.2, 0.4, 0.6, 0.8);
222     gl.clear(gl.COLOR_BUFFER_BIT);
223
224     gl.uniform4f(colorUniform, 0.8, 0.6, 0.4, 0.2);
225     wtu.drawUnitQuad(gl);
226
227     wtu.checkCanvasRect(gl, 0, 0, canvas.width, canvas.height, [204, 153, 153, 51]);
228 }
229
230 function runUniqueObjectTest()
231 {
232     debug("");
233     debug("Testing that getExtension() returns the same object each time");
234     gl.getExtension("EXT_blend_minmax").myProperty = 2;
235     gc();
236     shouldBe('gl.getExtension("EXT_blend_minmax").myProperty', '2');
237 }
238
239 debug("");
240 var successfullyParsed = true;
241 </script>
242 <script src="../../resources/js-test-post.js"></script>
243
244 </body>
245 </html>