Skip to content

Commit

Permalink
Add correctness tests to tex-unpack-params-imagedata.html
Browse files Browse the repository at this point in the history
Follow-up to KhronosGroup#2646
  • Loading branch information
kainino0x committed May 16, 2018
1 parent 2e7b0de commit 81fcf02
Showing 1 changed file with 51 additions and 3 deletions.
Expand Up @@ -40,24 +40,72 @@
<script>
var wtu = WebGLTestUtils;
var gl = wtu.create3DContext(undefined, undefined, 2);
var actual;

description("TexImage3D from ImageData with unpack params");

debug("TexImage3D from ImageData with UNPACK_IMAGE_HEIGHT set (crbug.com/804123)");

let imageData = new ImageData(64, 64);
// framebuffer for readback
var fbo = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, fbo);

function makeTestData(size, start) {
let data = new Uint8ClampedArray(size);
for (let i = 0; i < size; ++i) {
data[i] = (start + i) % 256;
}
return data;
}

// source data
const unpack_image_height = 7;
const width = 4;
const height = 4;
const depth = 4;
const srcWidth = width;
const srcHeight = (height - 1) * unpack_image_height + height;
const srcSize = srcWidth * srcHeight;
const sizeofR8 = 1;
const sizeofRGBA8 = 4;
let imageData = new ImageData(makeTestData(srcSize * 4, 0), srcWidth, srcHeight);
let texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_3D, texture);

// upload
gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, 2);
gl.texImage3D(gl.TEXTURE_3D, 0, gl.R8, 1, 1, 1, 0, gl.RED, gl.UNSIGNED_BYTE, imageData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "small upload");

gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, 7);
gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA8, 4, 4, 4, 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData);
{
actual = new Uint8Array(1);
gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, texture, 0, 0);
gl.readPixels(0, 0, 1, 1, gl.RED, gl.UNSIGNED_BYTE, actual);
shouldBeTrue(`areArraysEqual(actual, makeTestData(1 * 1 * sizeofR8, 0))`);
}

// upload
gl.pixelStorei(gl.UNPACK_IMAGE_HEIGHT, unpack_image_height);
gl.texImage3D(gl.TEXTURE_3D, 0, gl.RGBA8, width, height, depth, 0, gl.RGBA, gl.UNSIGNED_BYTE, imageData);
wtu.glErrorShouldBe(gl, gl.NO_ERROR, "larger upload");

{
actual = new Uint8Array(width * height * sizeofRGBA8);
for (let z = 0; z < 4; ++z) {
gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, texture, 0, z);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, actual);
console.log("");
console.log(makeTestData(width * height * sizeofRGBA8,
z * width * unpack_image_height * sizeofRGBA8));
console.log(actual);
shouldBeTrue(`areArraysEqual(actual,
makeTestData(${width} * ${height} * sizeofRGBA8,
${z} * ${width} * ${unpack_image_height} * sizeofRGBA8))`);
}
}

gl.deleteTexture(texture);
gl.deleteFramebuffer(fbo);

var successfullyParsed = true;
</script>
Expand Down

0 comments on commit 81fcf02

Please sign in to comment.