OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <meta charset="utf-8"> | 4 <meta charset="utf-8"> |
5 <title>Loading a large texture using texImage2D</title> | 5 <title>Loading a large texture using texImage2D</title> |
6 <script src="../../../resources/js-test.js"></script> | 6 <script src="../../../resources/js-test.js"></script> |
7 <script src="resources/webgl-test.js"></script> | 7 <script src="resources/webgl-test.js"></script> |
8 </head> | 8 </head> |
9 | 9 |
10 <body> | 10 <body> |
(...skipping 10 matching lines...) Expand all Loading... |
21 window.initNonKhronosFramework(true); | 21 window.initNonKhronosFramework(true); |
22 | 22 |
23 if (window.internals) | 23 if (window.internals) |
24 window.internals.settings.setWebGLErrorsToConsoleEnabled(false); | 24 window.internals.settings.setWebGLErrorsToConsoleEnabled(false); |
25 | 25 |
26 description('Test loading a large texture using texImage2D'); | 26 description('Test loading a large texture using texImage2D'); |
27 | 27 |
28 runTest(); | 28 runTest(); |
29 } | 29 } |
30 | 30 |
31 function generateImageData(width, height) | 31 function andPixels(pixels32) { |
32 { | 32 var pixelsAnd = 0xffffffff; |
33 var srcCanvas = document.createElement('canvas'); | 33 for (var i = 0; i < pixels32.length; ++i) { |
34 srcCanvas.width = width; | 34 pixelsAnd &= pixels32[i]; |
35 srcCanvas.height = height; | 35 } |
36 var ctx = srcCanvas.getContext('2d'); | 36 return pixelsAnd; |
37 ctx.fillStyle = '#ffffff'; | |
38 ctx.fillRect(0, 0, srcCanvas.width, srcCanvas.height); | |
39 return srcCanvas.toDataURL('image/jpeg'); | |
40 } | 37 } |
41 | 38 |
42 function runTest() { | 39 function runTest() { |
| 40 var width = 3900; |
| 41 var height = 3900; |
| 42 |
43 var canvas = document.getElementById('canvas'); | 43 var canvas = document.getElementById('canvas'); |
44 var gl = canvas.getContext('webgl'); | 44 var gl = canvas.getContext('webgl'); |
45 | 45 |
| 46 gl.pixelStorei(gl.UNPACK_COLORSPACE_CONVERSION_WEBGL, gl.NONE); |
| 47 |
46 var texture = gl.createTexture(); | 48 var texture = gl.createTexture(); |
| 49 gl.bindTexture(gl.TEXTURE_2D, texture); |
| 50 |
47 var image = new Image(); | 51 var image = new Image(); |
48 image.onerror = function (e) { | 52 image.onerror = function (e) { |
49 testFailed('Image failed to load'); | 53 testFailed('Image failed to load'); |
50 } | 54 } |
51 image.onload = function () { | 55 image.onload = function () { |
52 var width = image.width; | 56 debug('Image width and height: ' + image.width + ', ' + image.height); |
53 var height = image.height; | 57 |
54 debug('Image width and height: ' + width + ', ' + height); | 58 if (image.width !== width || image.height !== height) { |
55 var pixels = new Uint8Array(width * height * 4); | 59 testFailed('Image did not have expected dimensions.'); |
| 60 return; |
| 61 } |
| 62 |
| 63 var pixels = new ArrayBuffer(width * height * 4); |
| 64 var pixels8 = new Uint8Array(pixels); |
| 65 var pixels32 = new Uint32Array(pixels); |
56 | 66 |
57 if (width > gl.getParameter(gl.MAX_TEXTURE_SIZE) || | 67 if (width > gl.getParameter(gl.MAX_TEXTURE_SIZE) || |
58 width > gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)) { | 68 width > gl.getParameter(gl.MAX_RENDERBUFFER_SIZE)) { |
59 // The image is allowed to be too big to be used as a texture. | 69 // The image is allowed to be too big to be used as a texture. |
60 finishJSTest(); | 70 finishJSTest(); |
61 return; | 71 return; |
62 } | 72 } |
63 | 73 |
64 gl.bindTexture(gl.TEXTURE_2D, texture); | 74 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, image); |
65 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB, gl.RGB, gl.UNSIGNED_BYTE, image); | |
66 if (gl.getError() != gl.NO_ERROR) { | 75 if (gl.getError() != gl.NO_ERROR) { |
67 // Loading the texture is allowed to fail due to resource constraints. | 76 // Loading the texture is allowed to fail due to resource constraints. |
68 finishJSTest(); | 77 finishJSTest(); |
69 return; | 78 return; |
70 } | 79 } |
71 var fb = gl.createFramebuffer(); | 80 var fb = gl.createFramebuffer(); |
72 gl.bindFramebuffer(gl.FRAMEBUFFER, fb); | 81 gl.bindFramebuffer(gl.FRAMEBUFFER, fb); |
73 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
texture, 0); | 82 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D,
texture, 0); |
74 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels); | 83 gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, pixels8); |
75 | 84 |
76 for (var i = 0; i < pixels.length; ++i) { | 85 // The image is filled with white, ignore last bit of each subpixel to accou
nt for decoding rounding differences. |
77 // The image is filled with white, 254 to account for decoding rounding di
fferences. | 86 if ((andPixels(pixels32) & 0xfefefefe) !== (0xfefefefe | 0)) { |
78 if (pixels[i] < 254) { | 87 testFailed('Texture was not loaded correctly.'); |
79 testFailed('Texture was not loaded correctly.'); | |
80 return; | |
81 } | |
82 } | 88 } |
| 89 |
83 finishJSTest(); | 90 finishJSTest(); |
84 } | 91 } |
85 image.src = generateImageData(3900, 3900); | 92 image.src = 'resources/white3900x3900.jpg'; |
86 } | 93 } |
87 | 94 |
88 init(); | 95 init(); |
89 </script> | 96 </script> |
90 </body> | 97 </body> |
91 </html> | 98 </html> |
OLD | NEW |