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
16GB 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
);
23 debug("Tests that gl.readPixels() can be called on WebAssembly Memory of 16GB in size.");
25 let wtu
= WebGLTestUtils
;
26 let gl
= wtu
.create3DContext("canvas", undefined, 2);
29 const SIZE
= 16*1024*1024*1024;
30 let view
= new Uint8Array(new WebAssembly
.Memory({ index
: 'i64', initial
: SIZE
/PAGE
}).buffer
);
32 // Clear the canvas to a specific color
33 const expectedColor
= [42, 84, 128, 255];
34 gl
.clearColor(expectedColor
[0]/255.0, expectedColor[1]/255.0, expectedColor
[2]/255.0, expectedColor[3]/255.0);
35 gl
.clear(gl
.COLOR_BUFFER_BIT
);
37 // Test that gl.readPixels() can be called with a high offset to Memory
38 const offset
= SIZE
- 4;
39 view
.set([0,0,0,0], offset
); // For good measure, clear data at offset before reading
40 gl
.readPixels(0, 0, 1, 1, gl
.RGBA
, gl
.UNSIGNED_BYTE
, view
, offset
);
41 wtu
.glErrorShouldBe(gl
, gl
.NO_ERROR
);
42 let obtainedColor
= view
.subarray(offset
, offset
+4);
43 shouldBe('obtainedColor[0]', 'expectedColor[0]');
44 shouldBe('obtainedColor[1]', 'expectedColor[1]');
45 shouldBe('obtainedColor[2]', 'expectedColor[2]');
46 shouldBe('obtainedColor[3]', 'expectedColor[3]');
47 var successfullyParsed
= true;
49 <script src=
"../../js/js-test-post.js"></script>