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 51e24fc
Showing 1 changed file with 55 additions and 3 deletions.
Expand Up @@ -40,24 +40,76 @@
<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 * sizeofRGBA8, 1), srcWidth, srcHeight);
let texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_3D, texture);

debug("");
// 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");
{
actual = new Uint8Array(sizeofRGBA8);
gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, texture, 0, 0);
gl.readPixels(0, 0, 1, 1, gl.RGBA, gl.UNSIGNED_BYTE, actual);
console.log(actual);
shouldBeTrue(`areArraysEqual(actual, [1, 0, 0, 255])`);
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
}

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);
debug("");
// 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 < depth; ++z) {
gl.framebufferTextureLayer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, texture, 0, z);
gl.readPixels(0, 0, width, height, gl.RGBA, gl.UNSIGNED_BYTE, actual);
debug(`for z = ${z}`);
console.log("");
console.log(makeTestData(width * height * sizeofRGBA8,
1 + z * width * unpack_image_height * sizeofRGBA8));
console.log(actual);
shouldBeTrue(`areArraysEqual(actual,
makeTestData(/* size = */ width * height * sizeofRGBA8,
/* start = */ 1 + ${z} * width * unpack_image_height * sizeofRGBA8))`);
}
wtu.glErrorShouldBe(gl, gl.NO_ERROR);
}

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

var successfullyParsed = true;
</script>
Expand Down

0 comments on commit 51e24fc

Please sign in to comment.