diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/canvas/test/webgl-mochitest/test_tex_pbo.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/canvas/test/webgl-mochitest/test_tex_pbo.html')
-rw-r--r-- | dom/canvas/test/webgl-mochitest/test_tex_pbo.html | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/dom/canvas/test/webgl-mochitest/test_tex_pbo.html b/dom/canvas/test/webgl-mochitest/test_tex_pbo.html new file mode 100644 index 0000000000..f64d52bd41 --- /dev/null +++ b/dom/canvas/test/webgl-mochitest/test_tex_pbo.html @@ -0,0 +1,100 @@ +<!DOCTYPE HTML> +<html> + <head> + <meta charset='UTF-8'> + <script src='/tests/SimpleTest/SimpleTest.js'></script> + <link rel='stylesheet' href='/tests/SimpleTest/test.css'> + </head> + <body> + <script> + +function shouldBe(testStr, refStr) { + ok(testStr == refStr, 'Expected "' + refStr + '", was "' + testStr + '".'); +} + +function getErrorStr(gl, err) { + if (!err) return "NO_ERROR"; + for (const k in gl) { + const v = gl[k]; + if (v == err) { + return k; + } + } + return `<${err}>`; +} + +function glErrorShouldBe(gl, expected, opt_info) { + if (opt_info) { + opt_info = opt_info + ': ' + } else { + opt_info = ''; + } + + if (!expected.length) { + expected = [expected]; + } + expected = expected.map(x => getErrorStr(gl, x)); + let was = gl.getError(); + was = getErrorStr(gl, was); + console.log(expected); + ok(expected.includes(was), + `${opt_info}Expected gl.getError() in [${expected}], was ${was}.`); +} + +(() => { + const gl = document.createElement('canvas').getContext('webgl2'); + if (!gl) { + todo(false, 'No webgl2, skipping...'); + return; + } + const pbo = gl.createBuffer(); + gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, pbo); + + const PBO_DATA = new Uint8Array([ + 255, 0, 0, 255, + 0, 255, 0, 255, + ]); + gl.bufferData(gl.PIXEL_UNPACK_BUFFER, PBO_DATA, gl.STATIC_DRAW); + + const tex = gl.createTexture(); + gl.bindTexture(gl.TEXTURE_2D, tex); + + const fb = gl.createFramebuffer(); + gl.bindFramebuffer(gl.FRAMEBUFFER, fb); + gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, tex, 0); + + const readback = new Uint8Array(4); + + const PBO_LIST = [null, pbo]; + for (const cur of PBO_LIST) { + gl.bindBuffer(gl.PIXEL_UNPACK_BUFFER, cur); + + function tryUpload(arg, expectedReadback) { + let argType = typeof(arg); + if (arg === null) { + argType = 'null'; + } + const argForPbo = (argType == 'number'); + const pboBound = !!cur; + const expectedErr = (argForPbo == pboBound) ? 0 : gl.INVALID_OPERATION; + gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA8, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, + arg); + const with_without = pboBound ? 'with' : 'without'; + glErrorShouldBe(gl, expectedErr, `${with_without} pbo, texImage(..., ${argType}("${arg}"))`); + + if (expectedErr) return; + gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, readback); + shouldBe(expectedReadback.toString(), readback.toString()); + } + + const CPU_DATA = new Uint8Array([255, 255, 0, 255]); + + tryUpload(null, [0,0,0,0]); + tryUpload(CPU_DATA, CPU_DATA); + tryUpload(0, PBO_DATA.slice(0,4)); + tryUpload(4, PBO_DATA.slice(4)); + } +})(); + </script> + </body> +</html> |