The getDepthInformation()
method of the XRWebGLBinding
interface returns an XRWebGLDepthInformation
object containing WebGL depth information.
getDepthInformation(view)
const canvasElement = document.querySelector(".output-canvas");
const gl = canvasElement.getContext("webgl");
await gl.makeXRCompatible();
const session = navigator.xr.requestSession("immersive-ar", {
requiredFeatures: ["depth-sensing"],
depthSensing: {
usagePreference: ["gpu-optimized"],
formatPreference: ["luminance-alpha"],
},
});
const glBinding = new XRWebGLBinding(session, gl);
function rafCallback(time, frame) {
session.requestAnimationFrame(rafCallback);
const pose = frame.getViewerPose(referenceSpace);
if (pose) {
for (const view of pose.views) {
const depthInformation = glBinding.getDepthInformation(view);
if (depthInformation) {
}
}
}
}