Backed out changeset 7272b7396c78 (bug 1932758) for causing fenix debug failures...
[gecko.git] / dom / canvas / test / webgl-conf / checkout / conformance2 / textures / misc / tex-unpack-params-imagedata.html
blobd6c0765bbe63510e06829c9a05689595d672fff6
1 <!--
2 Copyright (c) 2019 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.
5 -->
7 <!DOCTYPE html>
8 <html>
9 <head>
10 <meta charset="utf-8">
11 <title>WebGL2 TexImage3D from ImageData with unpack params tests.</title>
12 <link rel="stylesheet" href="../../../resources/js-test-style.css"/>
13 <script src="../../../js/js-test-pre.js"></script>
14 <script src="../../../js/webgl-test-utils.js"></script>
15 </head>
16 <body>
17 <div id="description"></div>
18 <div id="console"></div>
19 <script>
20 var wtu = WebGLTestUtils;
21 var gl = wtu.create3DContext(undefined, undefined, 2);
22 let actual;
24 description("TexImage3D from ImageData with unpack params");
26 debug("TexImage3D from ImageData with UNPACK_IMAGE_HEIGHT set (crbug.com/804123)");
28 // framebuffer for readback
29 const fbo = gl.createFramebuffer();
30 gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);
32 function makeTestData(size, start) {
33 const data = new Uint8ClampedArray(size);
34 for (let i = 0; i < size; ++i) {
35 data[i] = (start + i) % 256;
37 return data;
40 // source data
42 // dstWidth = 4
43 // <-->
44 // xxxx ^ ^ ^ ^
45 // xxxx | | |
46 // xxxx | | |
47 // xxxx | | v dstHeight = 4
48 // ---- | |
49 // ---- | |
50 // ---- | v unpackImageHeight = 7
51 // xxxx | |
52 // xxxx |
53 // xxxx |
54 // xxxx |
55 // ---- |
56 // ---- |
57 // ---- |
58 // xxxx | |
59 // xxxx |
60 // xxxx |
61 // xxxx |
62 // ---- |
63 // ---- |
64 // ---- |
65 // xxxx | v dstDepth = 4
66 // xxxx |
67 // xxxx |
68 // xxxx v srcHeight = 25
69 // <-->
70 // srcWidth = 4
71 const unpackImageHeight = 7;
72 const dstWidth = 4;
73 const dstHeight = 4;
74 const dstDepth = 4;
75 const srcWidth = dstWidth;
76 const srcHeight = (dstDepth - 1) * unpackImageHeight + dstHeight;
77 const srcSize = srcWidth * srcHeight;
78 const sizeofR8 = 1;
79 const sizeofRGBA8 = 4;
80 const imageData = new ImageData(makeTestData(srcSize * sizeofRGBA8, 1), srcWidth, srcHeight);
81 const texture = gl.createTexture();
82 gl.bindTexture(gl.TEXTURE_3D, texture);
84 debug("");
85 // upload
86 gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, 2);
87 gl.texImage3D(gl.TEXTURE_3D, 0, gl.R8, 1, 1, 1, 0, gl.RED, gl.UNSIGNED_BYTE, imageData);
88 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "small upload");
89 // check
90 actual = new Uint8Array(sizeofRGBA8);
91 gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, texture, 0, 0);
92 if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) == gl.FRAMEBUFFER_COMPLETE) {
93 gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, actual);
94 shouldBeTrue(`areArraysEqual(actual, [1, 0, 0, 255])`);
95 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
96 } else {
97 debug("framebuffer incomplete: skipped");
100 debug("");
101 // upload
102 gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, unpackImageHeight);
103 gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA8, dstWidth, dstHeight, dstDepth, 0,
104 gl.RGBA, gl.UNSIGNED_BYTE, imageData);
105 wtu.glErrorShouldBe(gl, gl.NO_ERROR, "larger upload");
106 // check
107 actual = new Uint8Array(dstWidth * dstHeight * sizeofRGBA8);
108 let expected;
109 for (let z = 0; z < dstDepth; ++z) {
110 gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, texture, 0, z);
111 shouldBe('gl.checkFramebufferStatus(gl.FRAMEBUFFER)', 'gl.FRAMEBUFFER_COMPLETE');
112 gl.readPixels(0, 0, dstWidth, dstHeight, gl.RGBA, gl.UNSIGNED_BYTE, actual);
113 debug(`for z = ${z}:`);
114 expected = makeTestData(dstWidth * dstHeight * sizeofRGBA8,
115 1 + z * dstWidth * unpackImageHeight * sizeofRGBA8);
116 shouldBeTrue('areArraysEqual(actual, expected)');
118 wtu.glErrorShouldBe(gl, gl.NO_ERROR);
120 gl.deleteTexture(texture);
122 var successfullyParsed = true;
123 </script>
124 <script src="../../../js/js-test-post.js"></script>
125 </body>
126 </html>