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 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>
17 <div id=
"description"></div>
18 <div id=
"canvasHeader"></div>
19 <div id=
"console"></div>
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
) {
32 if (testParams
.multisampled
=== undefined) {
33 testParams
.multisampled
= true;
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');
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.
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");
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");
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");
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
);
104 // No-alpha, no-antialias, RGB8 source
110 internalformat
: 'RGB8',
111 clearColor
: [ 0.0, 1.0, 0.0, 0.5 ],
112 resultColor
: [ 0, 255, 0, 255 ],
115 // No-alpha, no-antialias, RGBA8 source
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
132 internalformat
: 'RGBA8',
133 clearColor
: [ 0.0, 1.0, 0.0, 0.5 ],
134 resultColor
: [ 0, 255, 0, 255 ],
138 // Alpha, no-antialias, RGB8 source
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
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
172 premultiplyAlpha
: false,
174 internalformat
: 'RGBA8',
175 clearColor
: [ 0.0, 1.0, 0.0, 0.0 ],
176 resultColor
: [ 0, 255, 0, 0 ],
180 // All attempts to blit to an antialiased back buffer should fail.
182 // No-alpha, antialias, RGB8 source
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
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
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
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
) {
240 var successfullyParsed
= true;
242 <script src=
"../../js/js-test-post.js"></script>