<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Loading a large texture using texImage2D</title> <script src="../../../resources/js-test.js"></script> <script src="resources/webgl-test.js"></script> </head> <body> <canvas id="canvas" width="64" height="64"></canvas> <div id="description"></div> <div id="console"></div> <script> var successfullyParsed = false; function init() { if (window.initNonKhronosFramework) window.initNonKhronosFramework(true); if (window.internals) window.internals.settings.setWebGLErrorsToConsoleEnabled(false); description('Test loading a large texture using texImage2D'); runTest(); } function andPixels(pixels32) { var pixelsAnd = 0xffffffff; for (var i = 0; i < pixels32.length; ++i) { pixelsAnd &= pixels32[i]; } return pixelsAnd; } function runTest() { var width = 3900; var height = 3900; var canvas = document.getElementById('canvas'); var gl = canvas.getContext('webgl'); gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); var texture = gl.createTexture(); gl.bindTexture(gl.TEXTURE_2D, texture); var image = new Image(); image.onerror = function (e) { testFailed('Image failed to load'); } image.onload = function () { debug('Image width and height: ' + image.width + ', ' + image.height); if (image.width !== width || image.height !== height) { testFailed('Image did not have expected dimensions.'); return; } var pixels = new ArrayBuffer(width * height * 4); var pixels8 = new Uint8Array(pixels); var pixels32 = new Uint32Array(pixels); if (width > gl.getParameter(gl.MAX_TEXTURE_SIZE) || width > gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)) { // The image is allowed to be too big to be used as a texture. finishJSTest(); return; } gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); if (gl.getError() != gl.NO_ERROR) { // Loading the texture is allowed to fail due to resource constraints. finishJSTest(); return; } var fb = gl.createFramebuffer(); gl.bindFramebuffer(gl.FRAMEBUFFER, fb); gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0); gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels8); // The image is filled with white, ignore last bit of each subpixel to account for decoding rounding differences. if ((andPixels(pixels32) & 0xfefefefe) !== (0xfefefefe | 0)) { testFailed('Texture was not loaded correctly.'); } finishJSTest(); } image.src = 'resources/white3900x3900.jpg'; } init(); </script> </body> </html>