test_tex_large_uploads.html (2660B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <meta charset='UTF-8'> 5 <script src='/tests/SimpleTest/SimpleTest.js'></script> 6 <link rel='stylesheet' href='/tests/SimpleTest/test.css'> 7 </head> 8 <body> 9 <img id='e_blank_15000x10000' src='blank_15000x10000.png'> 10 <script> 11 12 function shouldBe(testStr, refStr) { 13 ok(testStr == refStr, 'Expected "' + refStr + '", was "' + testStr + '".'); 14 } 15 16 function getErrorStr(gl, err) { 17 if (!err) return "NO_ERROR"; 18 for (const k in gl) { 19 const v = gl[k]; 20 if (v == err) { 21 return k; 22 } 23 } 24 return `<${err}>`; 25 } 26 27 function glErrorShouldBe(gl, expected, opt_info) { 28 if (opt_info) { 29 opt_info = opt_info + ': ' 30 } else { 31 opt_info = ''; 32 } 33 34 if (!expected.length) { 35 expected = [expected]; 36 } 37 expected = expected.map(x => getErrorStr(gl, x)); 38 let was = gl.getError(); 39 was = getErrorStr(gl, was); 40 ok(expected.includes(was), 41 `${opt_info}Expected gl.getError() in [${expected}], was ${was}.`); 42 } 43 SimpleTest.waitForExplicitFinish(); 44 (async () => { 45 const gl = document.createElement('canvas').getContext('webgl2'); 46 window.gl = gl; 47 if (!gl) { 48 todo(false, 'No webgl2, skipping...'); 49 return; 50 } 51 const tex = gl.createTexture(); 52 gl.bindTexture(gl.TEXTURE_2D, tex); 53 54 const TESTS = [ 55 //{w: 16000, h: 8000}, // TODO: This asserts. 56 //{w: 8000, h: 16000}, // TODO: This asserts. 57 {w: 8000, h: 4000}, 58 {w: 4000, h: 8000}, 59 {w: 4000, h: 4000}, 60 ]; 61 const src = document.createElement('canvas').getContext('webgl', 62 {antialias:false, depth:false}); 63 const maxTexSize = gl.getParameter(gl.MAX_TEXTURE_SIZE); 64 for (const t of TESTS) { 65 ok(true, 'canvas: ' + JSON.stringify(t)); 66 if (t.w > maxTexSize || t.h > maxTexSize) { 67 ok(true, `Larger than MAX_TEXTURE_SIZE of ${maxTexSize}`); 68 continue; 69 } 70 src.canvas.width = t.w; 71 src.canvas.height = t.h; 72 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, 73 src.canvas); 74 75 glErrorShouldBe(gl, [0, gl.OUT_OF_MEMORY], `after texImage(${JSON.stringify(t)})`); 76 77 src.canvas.width = src.canvas.height = 1; 78 } 79 80 if (15000 > maxTexSize) { 81 ok(true, `e_blank_15000x10000 larger than MAX_TEXTURE_SIZE of ${maxTexSize}, skipping.`); 82 } else { 83 await e_blank_15000x10000.decode(); // Otherwise it will not have loaded yet. 84 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, gl.RGBA, gl.UNSIGNED_BYTE, 85 e_blank_15000x10000); 86 glErrorShouldBe(gl, [0, gl.OUT_OF_MEMORY], `after texImage(e_blank_15000x10000)`); 87 ok(!gl.isContextLost(), '!gl.isContextLost()'); 88 } 89 90 SimpleTest.finish(); 91 })(); 92 </script> 93 </body> 94 </html>