The getSubImage()
method of the XRWebGLBinding
interface returns a XRWebGLSubImage
object representing the WebGL texture to render.
getSubImage(layer, frame)
getSubImage(layer, frame, eye)
The following example renders an XRQuadLayer
.
const xrGlBinding = new XRWebGLBinding(xrSession, gl);
const quadLayer = xrGlBinding.createQuadLayer({
space: xrReferenceSpace,
viewPixelWidth: 512,
viewPixelHeight: 512,
});
quadLayer.transform = new XRRigidTransform({ z: -2 });
quadLayer.width = 1.5;
quadLayer.height = 1.5;
const framebuffer = gl.createFramebuffer();
xrSession.updateRenderState({ layers: [quadLayer] });
xrSession.requestAnimationFrame(onXRFrame);
function onXRFrame(time, xrFrame) {
xrSession.requestAnimationFrame(onXRFrame);
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
let subImage = xrGlBinding.getSubImage(quadLayer, xrFrame);
gl.framebufferTexture2D(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
subImage.colorTexture,
0,
);
let viewport = subImage.viewport;
gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);
}