5 <title>Loading a large texture using texImage2D
</title>
6 <script src=
"../../../resources/js-test.js"></script>
7 <script src=
"resources/webgl-test.js"></script>
11 <canvas id=
"canvas" width=
"64" height=
"64"></canvas>
12 <div id=
"description"></div>
13 <div id=
"console"></div>
16 var successfullyParsed
= false;
20 if (window
.initNonKhronosFramework
)
21 window
.initNonKhronosFramework(true);
24 window
.internals
.settings
.setWebGLErrorsToConsoleEnabled(false);
26 description('Test loading a large texture using texImage2D');
31 function andPixels(pixels32
) {
32 var pixelsAnd
= 0xffffffff;
33 for (var i
= 0; i
< pixels32
.length
; ++i
) {
34 pixelsAnd
&= pixels32
[i
];
43 var canvas
= document
.getElementById('canvas');
44 var gl
= canvas
.getContext('webgl');
46 gl
.pixelStorei(gl
.UNPACK_COLORSPACE_CONVERSION_WEBGL
, gl
.NONE
);
48 var texture
= gl
.createTexture();
49 gl
.bindTexture(gl
.TEXTURE_2D
, texture
);
51 var image
= new Image();
52 image
.onerror = function (e
) {
53 testFailed('Image failed to load');
55 image
.onload = function () {
56 debug('Image width and height: ' + image
.width
+ ', ' + image
.height
);
58 if (image
.width
!== width
|| image
.height
!== height
) {
59 testFailed('Image did not have expected dimensions.');
63 var pixels
= new ArrayBuffer(width
* height
* 4);
64 var pixels8
= new Uint8Array(pixels
);
65 var pixels32
= new Uint32Array(pixels
);
67 if (width
> gl
.getParameter(gl
.MAX_TEXTURE_SIZE
) ||
68 width
> gl
.getParameter(gl
.MAX_RENDERBUFFER_SIZE
)) {
69 // The image is allowed to be too big to be used as a texture.
74 gl
.texImage2D(gl
.TEXTURE_2D
, 0, gl
.RGBA
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, image
);
75 if (gl
.getError() != gl
.NO_ERROR
) {
76 // Loading the texture is allowed to fail due to resource constraints.
80 var fb
= gl
.createFramebuffer();
81 gl
.bindFramebuffer(gl
.FRAMEBUFFER
, fb
);
82 gl
.framebufferTexture2D(gl
.FRAMEBUFFER
, gl
.COLOR_ATTACHMENT0
, gl
.TEXTURE_2D
, texture
, 0);
83 gl
.readPixels(0, 0, width
, height
, gl
.RGBA
, gl
.UNSIGNED_BYTE
, pixels8
);
85 // The image is filled with white, ignore last bit of each subpixel to account for decoding rounding differences.
86 if ((andPixels(pixels32
) & 0xfefefefe) !== (0xfefefefe | 0)) {
87 testFailed('Texture was not loaded correctly.');
92 image
.src
= 'resources/white3900x3900.jpg';