Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / rendering / blitframebuffer-r11f-g11f-b10f.html
blob636e76ac29f766852701c8110de9678f92aace8c
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 R11F_G11F_B10F BlitFramebuffer 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 <div id="console"></div>
19 <script>
20 "use strict";
22 var wtu = WebGLTestUtils;
23 description("This tests multisample blitting with the R11F_G11F_B10F format.");
25 var width = 8;
26 var height = 8;
28 function runWithContextCreationArguments(args) {
29 debug('');
30 debug('Running test with arguments: ' + JSON.stringify(args));
32 var canvas = document.createElement('canvas');
33 canvas.width = width;
34 canvas.height = height;
36 var gl = wtu.create3DContext(canvas, args, 2);
37 if (!gl) {
38 testFailed("WebGL 2.0 context does not exist");
39 return;
42 var ext = gl.getExtension("EXT_color_buffer_float");
43 if (!ext) {
44 testPassed("EXT_color_buffer_float extension not supported");
45 return;
48 var samples = gl.getInternalformatParameter(gl.RENDERBUFFER, gl.R11F_G11F_B10F, gl.SAMPLES);
50 // Set up source framebuffer.
51 var rb = gl.createRenderbuffer();
52 gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
53 gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples[0], gl.R11F_G11F_B10F, width, height);
54 var readfb = gl.createFramebuffer();
55 gl.bindFramebuffer(gl.FRAMEBUFFER, readfb);
56 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
57 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after multisampled R11F_G11F_B10F FBO setup");
58 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
59 testFailed("Source framebuffer incomplete.");
60 return;
63 // Draw something to that framebuffer.
64 gl.clearColor(0.0, 1.0, 0.0, 1.0);
65 gl.clear(gl.COLOR_BUFFER_BIT);
66 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after clearing R11F_G11F_B10F framebuffer");
68 // Set up destination framebuffer for resolving MSAA.
69 var tex = gl.createTexture();
70 gl.bindTexture(gl.TEXTURE_2D, tex);
71 gl.texImage2D(gl.TEXTURE_2D, 0, gl.R11F_G11F_B10F, width, height, 0, gl.RGB, gl.UNSIGNED_INT_10F_11F_11F_REV, null);
72 var drawfb = gl.createFramebuffer();
73 gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, drawfb);
74 gl.framebufferTexture2D(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
75 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after destination R11F_G11F_B10F FBO setup");
76 if (gl.checkFramebufferStatus(gl.DRAW_FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
77 testFailed("Framebuffer incomplete.");
78 return;
81 // Attempt a blit.
82 gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.LINEAR);
83 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after blitFramebuffer for multisample resolve");
85 // Try a readback.
86 gl.bindFramebuffer(gl.READ_FRAMEBUFFER, drawfb);
87 var readBackBuf = new Float32Array(width * height * 4);
88 wtu.checkCanvasRect(gl, 0, 0, width, height, [0.0, 1.0, 0.0], "should be green", undefined, readBackBuf, gl.FLOAT);
89 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after floating-point canvas readback");
91 // If default backbuffer is RGB and non-antialiased, test blitting to it too.
92 if (args && !args['alpha'] && !args['antialias']) {
93 gl.bindFramebuffer(gl.READ_FRAMEBUFFER, drawfb);
94 gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
95 gl.blitFramebuffer(0, 0, width, height, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.LINEAR);
96 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after blit to default back buffer");
97 gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
98 wtu.checkCanvas(gl, [ 0, 255, 0, 255 ], "default back buffer should be green");
102 // The format of the back buffer should have no effect on the behavior of this test.
103 runWithContextCreationArguments(undefined);
104 runWithContextCreationArguments({ alpha: true, antialias: true });
105 runWithContextCreationArguments({ alpha: true, antialias: false });
106 runWithContextCreationArguments({ alpha: false, antialias: true });
107 runWithContextCreationArguments({ alpha: false, antialias: false });
109 var successfullyParsed = true;
110 </script>
111 <script src="../../js/js-test-post.js"></script>
112 </body>
113 </html>