1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
<!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>
|