blitframebuffer-size-overflow.html (4663B)
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 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 <canvas id="example" width="8" height="8"></canvas> 18 <div id="description"></div> 19 <div id="console"></div> 20 <script> 21 "use strict"; 22 23 var wtu = WebGLTestUtils; 24 description("This test verifies blitFramebuffer won't cause a crash when the computed sizes might overflow."); 25 26 var width = 8; 27 var height = 8; 28 29 var gl = wtu.create3DContext("example", undefined, 2); 30 if (!gl) { 31 testFailed("WebGL context does not exist"); 32 } else { 33 testPassed("WebGL context exists"); 34 blit_region_test(); 35 } 36 37 function blit_region_test() { 38 39 debug(""); 40 debug("Begin to run blitFramebuffer. The computed width/height of src and/or dst region might overflow during blitting."); 41 var tex0 = gl.createTexture(); 42 gl.bindTexture(gl.TEXTURE_2D, tex0); 43 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 44 var fb0 = gl.createFramebuffer(); 45 gl.bindFramebuffer(gl.READ_FRAMEBUFFER, fb0); 46 gl.framebufferTexture2D(gl.READ_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex0, 0); 47 48 var tex1 = gl.createTexture(); 49 gl.bindTexture(gl.TEXTURE_2D, tex1); 50 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 51 var fb1 = gl.createFramebuffer(); 52 gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, fb1); 53 gl.framebufferTexture2D(gl.DRAW_FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex1, 0); 54 if ((gl.checkFramebufferStatus(gl.READ_FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE) || 55 (gl.checkFramebufferStatus(gl.DRAW_FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE)) { 56 testFailed("Framebuffer incomplete."); 57 return; 58 } 59 60 var max = 0x7fffffff; 61 gl.blitFramebuffer(0, 0, max, max, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST); 62 gl.blitFramebuffer(0, 0, width, height, 0, 0, max, max, gl.COLOR_BUFFER_BIT, gl.NEAREST); 63 gl.blitFramebuffer(0, 0, max, max, 0, 0, max, max, gl.COLOR_BUFFER_BIT, gl.NEAREST); 64 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Using max 32-bit integer as blitFramebuffer parameter should succeed."); 65 66 gl.blitFramebuffer(-1, -1, max - 1, max - 1, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST); 67 gl.blitFramebuffer(0, 0, width, height, -1, -1, max - 1, max - 1, gl.COLOR_BUFFER_BIT, gl.NEAREST); 68 gl.blitFramebuffer(-1, -1, max - 1, max - 1, -1, -1, max - 1, max - 1, gl.COLOR_BUFFER_BIT, gl.NEAREST); 69 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "Using blitFramebuffer parameters where calculated width/height matches max 32-bit integer should succeed."); 70 71 gl.blitFramebuffer(-1, -1, max, max, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST); 72 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "Using source width/height greater than max 32-bit integer should fail."); 73 gl.blitFramebuffer(max, max, -1, -1, 0, 0, width, height, gl.COLOR_BUFFER_BIT, gl.NEAREST); 74 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "Using source width/height greater than max 32-bit integer should fail."); 75 gl.blitFramebuffer(0, 0, width, height, -1, -1, max, max, gl.COLOR_BUFFER_BIT, gl.NEAREST); 76 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "Using destination width/height greater than max 32-bit integer should fail."); 77 gl.blitFramebuffer(0, 0, width, height, max, max, -1, -1, gl.COLOR_BUFFER_BIT, gl.NEAREST); 78 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "Using destination width/height greater than max 32-bit integer should fail."); 79 gl.blitFramebuffer(-1, -1, max, max, -1, -1, max, max, gl.COLOR_BUFFER_BIT, gl.NEAREST); 80 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "Using both source and destination width/height greater than max 32-bit integer should fail."); 81 gl.blitFramebuffer(-max - 1, -max - 1, max, max, -max - 1, -max - 1, max, max, gl.COLOR_BUFFER_BIT, gl.NEAREST); 82 wtu.glErrorShouldBe(gl, gl.INVALID_VALUE, "Using minimum and maximum integers for all boundaries should fail."); 83 84 gl.bindTexture(gl.TEXTURE_2D, null) 85 gl.bindFramebuffer(gl.READ_FRAMEBUFFER, null); 86 gl.bindFramebuffer(gl.DRAW_FRAMEBUFFER, null); 87 gl.deleteTexture(tex0); 88 gl.deleteTexture(tex1); 89 gl.deleteFramebuffer(fb0); 90 gl.deleteFramebuffer(fb1); 91 } 92 93 var successfullyParsed = true; 94 </script> 95 <script src="../../js/js-test-post.js"></script> 96 97 </body> 98 </html>