Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / dom / canvas / test / webgl-mochitest / test_tex_pbo.html
blobf64d52bd41cd4ce12aa242a537a16cfcc0425f68
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset='UTF-8'>
5 <script src='/tests/SimpleTest/SimpleTest.js'></script>
6 <link rel='stylesheet' href='/tests/SimpleTest/test.css'>
7 </head>
8 <body>
9 <script>
11 function shouldBe(testStr, refStr) {
12 ok(testStr == refStr, 'Expected "' + refStr + '", was "' + testStr + '".');
15 function getErrorStr(gl, err) {
16 if (!err) return "NO_ERROR";
17 for (const k in gl) {
18 const v = gl[k];
19 if (v == err) {
20 return k;
23 return `<${err}>`;
26 function glErrorShouldBe(gl, expected, opt_info) {
27 if (opt_info) {
28 opt_info = opt_info + ': '
29 } else {
30 opt_info = '';
33 if (!expected.length) {
34 expected = [expected];
36 expected = expected.map(x => getErrorStr(gl, x));
37 let was = gl.getError();
38 was = getErrorStr(gl, was);
39 console.log(expected);
40 ok(expected.includes(was),
41 `${opt_info}Expected gl.getError() in [${expected}], was ${was}.`);
44 (() => {
45 const gl = document.createElement('canvas').getContext('webgl2');
46 if (!gl) {
47 todo(false, 'No webgl2, skipping...');
48 return;
50 const pbo = gl.createBuffer();
51 gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, pbo);
53 const PBO_DATA = new Uint8Array([
54 255, 0, 0, 255,
55 0, 255, 0, 255,
56 ]);
57 gl.bufferData(gl.PIXEL_UNPACK_BUFFER, PBO_DATA, gl.STATIC_DRAW);
59 const tex = gl.createTexture();
60 gl.bindTexture(gl.TEXTURE_2D, tex);
62 const fb = gl.createFramebuffer();
63 gl.bindFramebuffer(gl.FRAMEBUFFER, fb);
64 gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0);
66 const readback = new Uint8Array(4);
68 const PBO_LIST = [null, pbo];
69 for (const cur of PBO_LIST) {
70 gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, cur);
72 function tryUpload(arg, expectedReadback) {
73 let argType = typeof(arg);
74 if (arg === null) {
75 argType = 'null';
77 const argForPbo = (argType == 'number');
78 const pboBound = !!cur;
79 const expectedErr = (argForPbo == pboBound) ? 0 : gl.INVALID_OPERATION;
80 gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE,
81 arg);
82 const with_without = pboBound ? 'with' : 'without';
83 glErrorShouldBe(gl, expectedErr, `${with_without} pbo, texImage(..., ${argType}("${arg}"))`);
85 if (expectedErr) return;
86 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, readback);
87 shouldBe(expectedReadback.toString(), readback.toString());
90 const CPU_DATA = new Uint8Array([255, 255, 0, 255]);
92 tryUpload(null, [0,0,0,0]);
93 tryUpload(CPU_DATA, CPU_DATA);
94 tryUpload(0, PBO_DATA.slice(0,4));
95 tryUpload(4, PBO_DATA.slice(4));
97 })();
98 </script>
99 </body>
100 </html>