GPURenderPassEncoder: setScissorRect() method
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
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).
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
|
Desktop |
Mobile |
|
Chrome |
Edge |
Firefox |
Internet Explorer |
Opera |
Safari |
WebView Android |
Chrome Android |
Firefox for Android |
Opera Android |
Safari on IOS |
Samsung Internet |
setScissorRect |
113Currently supported on ChromeOS, macOS, and Windows only.
|
113Currently supported on ChromeOS, macOS, and Windows only.
|
previewCurrently supported on Linux and Windows only.
|
No |
99Currently supported on ChromeOS, macOS, and Windows only.
|
No |
No |
No |
No |
No |
No |
No |
See also