2 Copyright (c) 2023 The Khronos Group Inc.
3 Use of this source code is governed by an MIT-style license that can be
4 found in the LICENSE.txt file.
10 <title>gl.readPixels() test to Wasm Memory
4GB in size.
</title>
11 <link rel=
"stylesheet" href=
"../../resources/js-test-style.css"/>
12 <script src=
"../../js/js-test-pre.js"></script>
13 <script src=
"../../js/webgl-test-utils.js"> </script>
16 <canvas id=
"canvas" width=
"2" height=
"2" style=
"width: 40px; height: 40px;"></canvas>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
21 description(document
.title
);
22 debug("Tests that gl.readPixels() can be called on WebAssembly Memory of 4GB in size.");
24 let wtu
= WebGLTestUtils
;
25 let gl
= wtu
.create3DContext("canvas", undefined, 2);
28 const SIZE
= 4*1024*1024*1024 - PAGE
; // when uint32_t size is max, we can only reach one page short of full 4GB
29 let view
= new Uint8Array(new WebAssembly
.Memory({ initial
: SIZE
/PAGE
}).buffer
);
31 // Clear the canvas to a specific color
32 const expectedColor
= [42, 84, 128, 255];
33 gl
.clearColor(expectedColor
[0]/255.0, expectedColor[1]/255.0, expectedColor
[2]/255.0, expectedColor[3]/255.0);
34 gl
.clear(gl
.COLOR_BUFFER_BIT
);
36 // Test that gl.readPixels() can be called with a high offset to Memory
37 const offset
= SIZE
- 4;
38 view
.set([0,0,0,0], offset
); // For good measure, clear data at offset before reading
39 gl
.readPixels(0, 0, 1, 1, gl
.RGBA
, gl
.UNSIGNED_BYTE
, view
, offset
);
40 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
41 let obtainedColor
= view
.subarray(offset
, offset
+4);
42 shouldBe('obtainedColor[0]', 'expectedColor[0]');
43 shouldBe('obtainedColor[1]', 'expectedColor[1]');
44 shouldBe('obtainedColor[2]', 'expectedColor[2]');
45 shouldBe('obtainedColor[3]', 'expectedColor[3]');
46 var successfullyParsed
= true;
48 <script src=
"../../js/js-test-post.js"></script>