blob: 18222933999244b7ddbfcaa9ac20aa9e5054a199 [file] [log] [blame]
<!doctype html>
<!--
Tests WebXR poses are correct through the pipeline.
We encode frame id in the canvas/image, and cache the pose information. The
test can query for whether each submitted frame used the correct pose.
-->
<html>
<head>
<link rel="stylesheet" type="text/css" href="../resources/webxr_e2e.css">
</head>
<body>
<canvas id="webgl-canvas"></canvas>
<script src="../../../../../../third_party/blink/web_tests/resources/testharness.js"></script>
<script src="../resources/webxr_e2e.js"></script>
<script src="../resources/webxr_boilerplate.js"></script>
<script>
var t = async_test("Pose data is correct");
var frame_id = 0;
var frame_data_array = {};
// We exit presentation before checking stuff that needs the frame of
// reference, so we need to cache its value.
var cached_frame_of_ref = null;
function FloatCompare(a, b) {
return Math.abs(a-b) < 0.001;
}
function MatrixCompare(a, b) {
for (var i = 0; i < 16; ++i) {
if (!FloatCompare(a[i], b[i])) return false;
}
return true;
}
function checkFrameOccurred(frame_id) {
return frame_id in frame_data_array;
}
function checkFrameProjection(frame_id, eye, expected) {
return MatrixCompare(frame_data_array[frame_id].views[eye].projectionMatrix, expected);
}
function checkFrameView(frame_id, eye, expected) {
let frame_data = frame_data_array[frame_id];
let pose = frame_data.getDevicePose(cached_frame_of_ref);
return MatrixCompare(pose.getViewMatrix(frame_data_array[frame_id].views[eye]), expected);
}
function checkFramePose(frame_id, expected) {
let frame_data = frame_data_array[frame_id];
let pose = frame_data.getDevicePose(cached_frame_of_ref);
if (!pose) {
// We can intermittently get null poses. For now treat them as passing,
// even though this should be fixed.
// TODO(https://crbug.com/859700): Make it so we don't get null poses unexpectedly.
console.log("null pose - unexpected, but pass");
return true;
}
console.log("checkFramePose: " + pose.poseModelMatrix + "\n" + expected);
return MatrixCompare(pose.poseModelMatrix, expected);
}
onImmersiveXRFrameCallback = function(session, frame, gl) {
// Encode an index into the clear color.
frame_id++;
frame_data_array[frame_id] = frame;
cached_frame_of_ref = sessionInfos[sessionTypes.IMMERSIVE].currentFrameOfRef;
var encoded_frame_id = {};
encoded_frame_id.r = frame_id % 256;
encoded_frame_id.g = ((frame_id - frame_id % 256) / 256) % 256;
encoded_frame_id.b = ((frame_id - frame_id % (256 * 256)) / (256 * 256)) % 256;
// We divide by 255 rather than 256, because our range of values is [0, 255],
// which should map to [0.0f, 1.0f].
gl.clearColor(encoded_frame_id.r / 255, encoded_frame_id.g / 255, encoded_frame_id.b / 255, 1.0);
gl.clear(gl.COLOR_BUFFER_BIT);
console.log("Submitting frame: " + frame_id + " " + encoded_frame_id.r);
}
function finishTest() {
t.done();
}
</script>
</body>
</html>