XRView: requestViewportScale() method

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The requestViewportScale() method of the XRView interface requests that the user agent sets the requested viewport scale for this viewport to the given value. This is used for dynamic viewport scaling which allows rendering to a subset of the WebXR viewport using a scale factor that can be changed every animation frame.

Syntax

js
requestViewportScale(scale)

Parameters

scale

A number greater than 0.0 and less than or equal to 1.0 representing the scale factor.

Return value

None (undefined).

Dynamic viewport scaling

Dynamic viewport scaling allows applications to only use a subset of the available framebuffer. The feature may not be available on all systems since it depends on driver support, so you might want to ensure that requestViewportScale() exists before calling it.

The scale parameter can be a number greater than 0.0 and less than or equal to 1.0.

Alternatively, you can use the XRView.recommendedViewportScale property which contains the user agent's recommended value based on internal heuristics. If the user agent doesn't provide a recommended viewport scale, its value is null and the call to requestViewportScale() is ignored.

Examples

The following example shows how to request and apply a new viewport scale. The call to XRWebGLLayer.getViewport() applies the change and returns the updated viewport.

js
for (const view of pose.views) {
  if (view.requestViewportScale) {
    view.requestViewportScale(0.8);
    // or use view.requestViewportScale(view.recommendedViewportScale);
  }
  const viewport = glLayer.getViewport(view);
}

Specifications

Specification
WebXR Device API
# dom-xrview-requestviewportscale

Browser compatibility

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
requestViewportScale
Experimental

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support
Experimental. Expect behavior to change in the future.

See also