copy-tex-image-crash.html (2232B)
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>copyTexImage2D should not crash</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 <canvas id="canvas"></canvas> 19 <div id="console"></div> 20 21 <script> 22 "use strict"; 23 description("Draw into source of copyTexSubImage2D shouldn't crash: regression test for https://crbug.com/707445"); 24 25 var wtu = WebGLTestUtils; 26 var canvas = document.getElementById("canvas"); 27 canvas.width = 16; 28 canvas.height = 16; 29 var gl = wtu.create3DContext(canvas); 30 31 function runTest() { 32 // Setup/clear source texture 33 let tex1 = gl.createTexture(); 34 gl.bindTexture(gl.TEXTURE_2D, tex1); 35 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 36 let fb1 = gl.createFramebuffer(); 37 gl.bindFramebuffer(gl.FRAMEBUFFER, fb1); 38 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex1, 0); 39 gl.clear(gl.COLOR_BUFFER_BIT); 40 41 // Setup/clear destination texture 42 let tex2 = gl.createTexture(); 43 gl.bindTexture(gl.TEXTURE_2D, tex2); 44 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 45 let fb2 = gl.createFramebuffer(); 46 gl.bindFramebuffer(gl.FRAMEBUFFER, fb2); 47 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex2, 0); 48 gl.clear(gl.COLOR_BUFFER_BIT); 49 50 // Copy from source to destination texture 51 gl.bindFramebuffer(gl.FRAMEBUFFER, fb1); 52 gl.bindTexture(gl.TEXTURE_2D, tex2); 53 gl.copyTexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 0, 0, 16, 16, 0); 54 55 // Draw into source texture 56 gl.bindFramebuffer(gl.FRAMEBUFFER, fb2); 57 let program = wtu.setupColorQuad(gl); // Used as a trivial shader; any shader will work. 58 gl.useProgram(program); 59 gl.drawArrays(gl.TRIANGLES, 0, 3); 60 } 61 62 runTest(); 63 64 var successfullyParsed = true; 65 </script> 66 <script src="../../../js/js-test-post.js"></script> 67 68 </body> 69 </html>