大网数据广告活动
Web 标准与前端开发

XRView: requestViewportScale() method

· 52CE 我爱测

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 fa

WebXR Device API

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

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 XRWebGLLayer.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.

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

Browser compatibility

See also

  • XRView.recommendedViewportScale

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。