Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance / rendering / framebuffer-texture-clear.html
blobdc5d60def850a1ab194c8a29866b3b2fb87aa7ad
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 framebuffer clearColor with pure 0/1</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 <div id="console"></div>
19 <canvas id="canvas" width="2" height="2"> </canvas>
20 <script>
21 "use strict";
22 // This test verifies a Mac Intel HD 6000/6100 driver bug. See crbug.com/710443.
23 var wtu = WebGLTestUtils;
24 var gl = wtu.create3DContext("canvas");
26 function InitializeRGBAData(width, height)
28 var size = 4 * width * height;
29 var data = new Uint8Array(size);
30 for (var i = 0; i < size; i++) {
31 data[i] = 128;
33 return data;
36 function testFramebufferTextureClearWithPureZeroOrOne(clearColor, expectedColor) {
37 var width = 32;
38 var height = 32;
39 var texture0 = gl.createTexture();
40 gl.bindTexture(gl.TEXTURE_2D, texture0);
41 // It seems that if we add texParameteri here, all cases can pass no matter
42 // you use texParameteri or not in Line 85.
43 // gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
44 var texData = InitializeRGBAData(width, height);
45 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, texData);
47 var fbo0 = gl.createFramebuffer();
48 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo0);
49 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture0, 0);
50 gl.viewport(0, 0, width, height);
51 gl.clearColor(clearColor[0], clearColor[1], clearColor[2], clearColor[3]);
52 gl.clear(gl.COLOR_BUFFER_BIT);
54 var texture1 = gl.createTexture();
55 gl.bindTexture(gl.TEXTURE_2D, texture1);
56 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
57 var fbo1 = gl.createFramebuffer();
58 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo1);
59 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture1, 0);
61 wtu.setupTexturedQuad(gl);
63 gl.bindTexture(gl.TEXTURE_2D, texture0);
64 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST);
65 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo1);
66 gl.viewport(0, 0, width, height);
67 gl.drawArrays(gl.TRIANGLES, 0, 6);
69 wtu.checkCanvasRect(gl, 0, 0, 1, 1, expectedColor);
71 gl.deleteTexture(texture0);
72 gl.deleteFramebuffer(fbo0);
73 gl.deleteTexture(texture1);
74 gl.deleteFramebuffer(fbo1);
77 description("Test that if clear fbo texture color with pure 0/1 and sample this texture to draw to another fbo, the final render color should be consistent with the clear color.");
79 for(var index = 0; index < 16; index++)
81 var r = (index & 8) / 8;
82 var g = (index & 4) / 4;
83 var b = (index & 2) / 2;
84 var a = index & 1;
85 var clearColor = [r, g, b, a];
86 var expectedColor = [r * 255, g * 255, b * 255, a * 255];
87 testFramebufferTextureClearWithPureZeroOrOne(clearColor, expectedColor);
90 debug("");
91 var successfullyParsed = true;
93 </script>
94 <script src="../../js/js-test-post.js"></script>
96 </body>
97 </html>