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

GPURenderPassEncoder: setScissorRect() method

· 52CE 我爱测

The **`setScissorRect()`** method of the GPURenderPassEncoder interface sets the scissor rectangle used during the rasterization stage. After transformation into viewport coordinates any fragments that fall outside the scissor rectangle will be discarded.

WebGPU API

The setScissorRect() method of the GPURenderPassEncoder interface sets the scissor rectangle used during the rasterization stage. After transformation into viewport coordinates any fragments that fall outside the scissor rectangle will be discarded.

Syntax

setScissorRect(x, y, width, height)

Parameters

  • x
    • : A number representing the minimum X value of the scissor rectangle, in pixels.
  • y
    • : A number representing the minimum Y value of the scissor rectangle, in pixels.
  • width
    • : A number representing the width of the scissor rectangle, in pixels.
  • height
    • : A number representing the height of the scissor rectangle, in pixels.

[!NOTE] If a setScissorRect() call is not made, the default values are (0, 0, attachment width, attachment height) for each render pass.

Return value

None (undefined).

Validation

The following criteria must be met when calling setViewport(), otherwise a GPUValidationError is generated and the GPURenderPassEncoder becomes invalid:

  • x + width is less than or equal to the width of the render pass's render attachments (see note below).
  • y + height is less than or equal to the height of the render pass's render attachments (see note below).

[!NOTE] See the color and depth/stencil attachments specified in the descriptor of GPUCommandEncoder.beginRenderPass(); the width and height are based on that of the GPUTexture that their views originate from.

Examples

Basic snippet

In a typical canvas render, the following could be used to discard any rendering outside of the top-left quarter of the canvas:

passEncoder.setScissorRect(0, 0, canvas.width / 2, canvas.height / 2);

Specifications

Browser compatibility

See also

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

资料来源与适用范围

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

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

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