Backed out changeset 8fc3326bce7f (bug 1943032) for causing failures at browser_tab_g...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / rendering / blitframebuffer-resolve-to-back-buffer.html
blobaddbdc4e9d1ac832ffc9fbfdfb80183da2df53da
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 BlitFramebuffer Resolve to Back Buffer</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="canvasHeader"></div>
19 <div id="console"></div>
21 <script>
22 "use strict";
24 var wtu = WebGLTestUtils;
25 description("This test verifies the behavior of blitFramebuffer when resolving directly to the back buffer.");
27 debug("Regression test for <a href='http://crbug.com/699566'>http://crbug.com/699566</a>");
29 function runTest(testParams) {
30 const sz = 64;
32 if (testParams.multisampled === undefined) {
33 testParams.multisampled = true;
36 debug('');
37 debug('Testing with alpha = ' + testParams.attribs.alpha +
38 ', antialias = ' + testParams.attribs.antialias +
39 ', internalformat = ' + testParams.internalformat +
40 ', multisampled = ' + testParams.multisampled);
42 var canvas = document.createElement('canvas');
43 canvas.width = sz;
44 canvas.height = sz;
45 document.getElementById('canvasHeader').appendChild(canvas);
46 var gl = wtu.create3DContext(canvas, testParams.attribs, 2);
48 // Find the supported samples for a multisampled renderbuffer of the appropriate internal format.
49 let samples = [0];
50 if (testParams.multisampled) {
51 samples = gl.getInternalformatParameter(gl.RENDERBUFFER, gl[testParams.internalformat], gl.SAMPLES);
52 if (!samples || !samples.length) {
53 testFailed("At least one multisampled format is required to be supported");
54 return;
58 // Create a framebuffer with a multisampled renderbuffer.
59 let rb = gl.createRenderbuffer();
60 gl.bindRenderbuffer(gl.RENDERBUFFER, rb);
61 gl.renderbufferStorageMultisample(gl.RENDERBUFFER, samples[0], gl[testParams.internalformat], sz, sz);
63 // Create a framebuffer.
64 let fb = gl.createFramebuffer();
65 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
66 gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb);
68 // Check for completeness.
69 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) {
70 testFailed("Rendering to a multisampled renderbuffer of format " + testParams.internalformat + " is required by the spec");
71 return;
74 // Clear to specified color.
75 gl.clearColor.apply(gl, testParams.clearColor);
76 gl.clear(gl.COLOR_BUFFER_BIT);
78 // Unbind draw framebuffer. Read framebuffer is now user framebuffer;
79 // draw framebuffer is default framebuffer.
80 gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null);
82 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors before blit");
84 // Blit from user framebuffer to default framebuffer.
85 gl.blitFramebuffer(0, 0, sz, sz, 0, 0, sz, sz, gl.COLOR_BUFFER_BIT, gl.NEAREST);
87 if (testParams.shouldSucceed) {
88 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be legal to blit/resolve to default back buffer");
89 } else {
90 wtu.glErrorShouldBe(gl, gl.INVALID_OPERATION, "incompatible src/dest blitFramebuffer combination must fail");
93 // Unbind user framebuffer completely.
94 gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null);
96 if (testParams.shouldSucceed) {
97 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no error before readback");
98 wtu.checkCanvasRect(gl, 0, 0, 8, 8, testParams.resultColor);
99 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
103 var tests = [
104 // No-alpha, no-antialias, RGB8 source
106 attribs: {
107 alpha: false,
108 antialias: false,
110 internalformat: 'RGB8',
111 clearColor: [ 0.0, 1.0, 0.0, 0.5 ],
112 resultColor: [ 0, 255, 0, 255 ],
113 shouldSucceed: true,
115 // No-alpha, no-antialias, RGBA8 source
117 attribs: {
118 alpha: false,
119 antialias: false,
121 internalformat: 'RGBA8',
122 clearColor: [ 0.0, 1.0, 0.0, 0.5 ],
123 resultColor: [ 0, 255, 0, 255 ],
124 shouldSucceed: false,
126 // No-alpha, no-antialias, RGBA8 source, single-sampled blit
128 attribs: {
129 alpha: false,
130 antialias: false,
132 internalformat: 'RGBA8',
133 clearColor: [ 0.0, 1.0, 0.0, 0.5 ],
134 resultColor: [ 0, 255, 0, 255 ],
135 shouldSucceed: true,
136 multisampled: false,
138 // Alpha, no-antialias, RGB8 source
140 attribs: {
141 alpha: true,
142 antialias: false,
144 internalformat: 'RGB8',
145 clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
146 resultColor: [ 0, 255, 0, 255 ],
147 shouldSucceed: false,
149 // No-alpha, no-antialias, RGBA8 source
150 // premultiplyAlpha:false just to avoid semantically incorrect
151 // colors (should only affect rendering, not contents of WebGL
152 // back buffer)
154 attribs: {
155 alpha: false,
156 antialias: false,
157 premultiplyAlpha: false,
159 internalformat: 'RGBA8',
160 clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
161 resultColor: [ 0, 255, 0, 255 ],
162 shouldSucceed: false,
164 // Alpha, no-antialias, RGBA8 source
165 // premultiplyAlpha:false just to avoid semantically incorrect
166 // colors (should only affect rendering, not contents of WebGL
167 // back buffer)
169 attribs: {
170 alpha: true,
171 antialias: false,
172 premultiplyAlpha: false,
174 internalformat: 'RGBA8',
175 clearColor: [ 0.0, 1.0, 0.0, 0.0 ],
176 resultColor: [ 0, 255, 0, 0 ],
177 shouldSucceed: true,
180 // All attempts to blit to an antialiased back buffer should fail.
182 // No-alpha, antialias, RGB8 source
184 attribs: {
185 alpha: false,
186 antialias: true,
188 internalformat: 'RGB8',
189 clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
190 resultColor: [ 0, 255, 0, 255 ],
191 shouldSucceed: false,
193 // Alpha, antialias, RGB8 source
195 attribs: {
196 alpha: true,
197 antialias: true,
199 internalformat: 'RGB8',
200 clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
201 resultColor: [ 0, 255, 0, 255 ],
202 shouldSucceed: false,
204 // No-alpha, antialias, RGBA8 source
205 // premultiplyAlpha:false just to avoid semantically incorrect
206 // colors (should only affect rendering, not contents of WebGL
207 // back buffer)
209 attribs: {
210 alpha: false,
211 antialias: true,
212 premultiplyAlpha: false,
214 internalformat: 'RGBA8',
215 clearColor: [ 0.0, 1.0, 0.0, 1.0 ],
216 resultColor: [ 0, 255, 0, 255 ],
217 shouldSucceed: false,
219 // Alpha, antialias, RGBA8 source
220 // premultiplyAlpha:false just to avoid semantically incorrect
221 // colors (should only affect rendering, not contents of WebGL
222 // back buffer)
224 attribs: {
225 alpha: true,
226 antialias: true,
227 premultiplyAlpha: false,
229 internalformat: 'RGBA8',
230 clearColor: [ 0.0, 1.0, 0.0, 0.0 ],
231 resultColor: [ 0, 255, 0, 0 ],
232 shouldSucceed: false,
236 for (var ii in tests) {
237 runTest(tests[ii]);
240 var successfullyParsed = true;
241 </script>
242 <script src="../../js/js-test-post.js"></script>
244 </body>
245 </html>