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.
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>
17 <div id=
"description"></div>
18 <div id=
"console"></div>
20 var wtu
= WebGLTestUtils
;
21 var gl
= wtu
.create3DContext(undefined, undefined, 2);
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;
47 // xxxx | | v dstHeight = 4
50 // ---- | v unpackImageHeight = 7
65 // xxxx | v dstDepth = 4
68 // xxxx v srcHeight = 25
71 const unpackImageHeight
= 7;
75 const srcWidth
= dstWidth
;
76 const srcHeight
= (dstDepth
- 1) * unpackImageHeight
+ dstHeight
;
77 const srcSize
= srcWidth
* srcHeight
;
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
);
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");
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
);
97 debug("framebuffer incomplete: skipped");
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");
107 actual
= new Uint8Array(dstWidth
* dstHeight
* sizeofRGBA8
);
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;
124 <script src=
"../../../js/js-test-post.js"></script>