XRWebGLBinding.getViewSubImage()

The getViewSubImage() method of the XRWebGLBinding interface returns a XRWebGLSubImage object representing the WebGL texture to render for a view.

Syntax

getViewSubImage(layer, view)

Parameters

layer

The XRProjectionLayer to use for rendering (to render other layer types, see XRWebGLBinding.getSubImage()).

view

The XRView to use for rendering.

Return value

A XRWebGLSubImage object.

Exceptions

A TypeError is thrown,

Examples

Rendering an XRProjectionLayer

The following example renders an XRProjectionLayer to a view.

const xrGlBinding = new XRWebGLBinding(xrSession, gl);
const layer = xrGlBinding.createProjectionLayer({});
const framebuffer = gl.createFramebuffer();

xrSession.updateRenderState({ layers: [layer] });
xrSession.requestAnimationFrame(onXRFrame);

function onXRFrame(time, xrFrame) {
  xrSession.requestAnimationFrame(onXRFrame);

  gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);

  for (let view in xrViewerPose.views) {
    let subImage = xrGlBinding.getViewSubImage(layer, view);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0,
      gl.TEXTURE_2D, subImage.colorTexture, 0);
    gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT,
      gl.TEXTURE_2D, subImage.depthStencilTexture, 0);
    let viewport = subImage.viewport;
    gl.viewport(viewport.x, viewport.y, viewport.width, viewport.height);

    // Render from the viewpoint of xrView
  }
}

Specifications

No specification found

No specification data found for api.XRWebGLBinding.getViewSubImage.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Browser compatibility

No compatibility data found for api.XRWebGLBinding.getViewSubImage.
Check for problems with this page or contribute missing data to mdn/browser-compat-data.

See also