texture-copying-and-deletion.html (3318B)
1 <!-- 2 Copyright (c) 2020 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 Texture Copying and Deletion Test</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="1" height="1" style="width: 40px; height: 40px;"></canvas> 18 <div id="description"></div> 19 <div id="console"></div> 20 21 <script> 22 "use strict"; 23 description('Checks that texture copying and deletion work correctly together.'); 24 debug('Regression test for <a href="http://anglebug.com/4267">http://anglebug.com/4267</a>'); 25 const wtu = WebGLTestUtils; 26 const canvas = document.getElementById("example"); 27 canvas.addEventListener('webglcontextlost', contextLost, false); 28 29 let contextWasLost = false; 30 function contextLost(e) { 31 e.preventDefault(); 32 contextWasLost = true; 33 debug("***context lost -- should not happen***"); 34 } 35 36 const gl = wtu.create3DContext(canvas); 37 38 const texture = gl.createTexture(); 39 gl.bindTexture(gl.TEXTURE_2D, texture); 40 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 41 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 42 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 43 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 44 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 45 46 const texture2 = gl.createTexture(); 47 gl.bindTexture(gl.TEXTURE_2D, texture2); 48 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 2, 2, 0, gl.RGBA, gl.UNSIGNED_BYTE, null); 49 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); 50 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); 51 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE); 52 gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE); 53 54 const framebuffer = gl.createFramebuffer(); 55 gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer); 56 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); 57 assertMsg(gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE, 58 "framebuffer should be FRAMEBUFFER_COMPLETE."); 59 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "after setup"); 60 61 // This test does not call getError, because doing so seems to cause 62 // an implicit flush which intermittently masks the bug. 63 64 debug(""); 65 debug("testing copyTexImage2D"); 66 gl.bindTexture(gl.TEXTURE_2D, texture); 67 gl.copyTexImage2D(gl.TEXTURE_2D, 1, gl.RGBA, 0, 0, 2, 2, 0); 68 // Not necessary to do any CopyTexImage2D operations to texture2. 69 70 debug(""); 71 debug("testing copyTexSubImage2D"); 72 gl.bindTexture(gl.TEXTURE_2D, texture); 73 gl.copyTexSubImage2D(gl.TEXTURE_2D, 1, 0, 0, 0, 0, 1, 1); 74 gl.bindTexture(gl.TEXTURE_2D, texture2); 75 gl.copyTexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1); 76 77 debug('deleting framebuffer'); 78 gl.deleteFramebuffer(framebuffer); 79 debug('deleting texture'); 80 gl.deleteTexture(texture); 81 debug('deleting texture2'); 82 // On buggy driver, crashes during this deleteTexture call. 83 gl.deleteTexture(texture2); 84 85 setTimeout(function() { 86 shouldBe("contextWasLost", "false"); 87 finishTest(); 88 }, 1000); 89 </script> 90 </body> 91 </html>