blitframebuffer-resolve-to-back-buffer.html (7644B)
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 --> 6 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> 20 21 <script> 22 "use strict"; 23 24 var wtu = WebGLTestUtils; 25 description("This test verifies the behavior of blitFramebuffer when resolving directly to the back buffer."); 26 27 debug("Regression test for <a href='http://crbug.com/699566'>http://crbug.com/699566</a>"); 28 29 function runTest(testParams) { 30 const sz = 64; 31 32 if (testParams.multisampled === undefined) { 33 testParams.multisampled = true; 34 } 35 36 debug(''); 37 debug('Testing with alpha = ' + testParams.attribs.alpha + 38 ', antialias = ' + testParams.attribs.antialias + 39 ', internalformat = ' + testParams.internalformat + 40 ', multisampled = ' + testParams.multisampled); 41 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); 47 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; 55 } 56 } 57 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); 62 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); 67 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; 72 } 73 74 // Clear to specified color. 75 gl.clearColor.apply(gl, testParams.clearColor); 76 gl.clear(gl.COLOR_BUFFER_BIT); 77 78 // Unbind draw framebuffer. Read framebuffer is now user framebuffer; 79 // draw framebuffer is default framebuffer. 80 gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null); 81 82 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "should be no errors before blit"); 83 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); 86 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"); 91 } 92 93 // Unbind user framebuffer completely. 94 gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null); 95 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); 100 } 101 } 102 103 var tests = [ 104 // No-alpha, no-antialias, RGB8 source 105 { 106 attribs: { 107 alpha: false, 108 antialias: false, 109 }, 110 internalformat: 'RGB8', 111 clearColor: [ 0.0, 1.0, 0.0, 0.5 ], 112 resultColor: [ 0, 255, 0, 255 ], 113 shouldSucceed: true, 114 }, 115 // No-alpha, no-antialias, RGBA8 source 116 { 117 attribs: { 118 alpha: false, 119 antialias: false, 120 }, 121 internalformat: 'RGBA8', 122 clearColor: [ 0.0, 1.0, 0.0, 0.5 ], 123 resultColor: [ 0, 255, 0, 255 ], 124 shouldSucceed: false, 125 }, 126 // No-alpha, no-antialias, RGBA8 source, single-sampled blit 127 { 128 attribs: { 129 alpha: false, 130 antialias: false, 131 }, 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, 137 }, 138 // Alpha, no-antialias, RGB8 source 139 { 140 attribs: { 141 alpha: true, 142 antialias: false, 143 }, 144 internalformat: 'RGB8', 145 clearColor: [ 0.0, 1.0, 0.0, 1.0 ], 146 resultColor: [ 0, 255, 0, 255 ], 147 shouldSucceed: false, 148 }, 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) 153 { 154 attribs: { 155 alpha: false, 156 antialias: false, 157 premultiplyAlpha: false, 158 }, 159 internalformat: 'RGBA8', 160 clearColor: [ 0.0, 1.0, 0.0, 1.0 ], 161 resultColor: [ 0, 255, 0, 255 ], 162 shouldSucceed: false, 163 }, 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) 168 { 169 attribs: { 170 alpha: true, 171 antialias: false, 172 premultiplyAlpha: false, 173 }, 174 internalformat: 'RGBA8', 175 clearColor: [ 0.0, 1.0, 0.0, 0.0 ], 176 resultColor: [ 0, 255, 0, 0 ], 177 shouldSucceed: true, 178 }, 179 180 // All attempts to blit to an antialiased back buffer should fail. 181 182 // No-alpha, antialias, RGB8 source 183 { 184 attribs: { 185 alpha: false, 186 antialias: true, 187 }, 188 internalformat: 'RGB8', 189 clearColor: [ 0.0, 1.0, 0.0, 1.0 ], 190 resultColor: [ 0, 255, 0, 255 ], 191 shouldSucceed: false, 192 }, 193 // Alpha, antialias, RGB8 source 194 { 195 attribs: { 196 alpha: true, 197 antialias: true, 198 }, 199 internalformat: 'RGB8', 200 clearColor: [ 0.0, 1.0, 0.0, 1.0 ], 201 resultColor: [ 0, 255, 0, 255 ], 202 shouldSucceed: false, 203 }, 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) 208 { 209 attribs: { 210 alpha: false, 211 antialias: true, 212 premultiplyAlpha: false, 213 }, 214 internalformat: 'RGBA8', 215 clearColor: [ 0.0, 1.0, 0.0, 1.0 ], 216 resultColor: [ 0, 255, 0, 255 ], 217 shouldSucceed: false, 218 }, 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) 223 { 224 attribs: { 225 alpha: true, 226 antialias: true, 227 premultiplyAlpha: false, 228 }, 229 internalformat: 'RGBA8', 230 clearColor: [ 0.0, 1.0, 0.0, 0.0 ], 231 resultColor: [ 0, 255, 0, 0 ], 232 shouldSucceed: false, 233 }, 234 ]; 235 236 for (var ii in tests) { 237 runTest(tests[ii]); 238 } 239 240 var successfullyParsed = true; 241 </script> 242 <script src="../../js/js-test-post.js"></script> 243 244 </body> 245 </html>