Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. WebGLRenderingContext
  4. stencilOp()

WebGLRenderingContext: stencilOp() method

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

Note: This feature is available inWeb Workers.

TheWebGLRenderingContext.stencilOp() method of theWebGL API sets both the front and back-facingstencil test actions.

Syntax

js
stencilOp(fail, zfail, zpass)

Parameters

fail

AGLenum specifying the function to use when the stencil test fails.The default value isgl.KEEP.

zfail

AGLenum specifying the function to use when the stencil test passes,but the depth test fails. The default value isgl.KEEP.

zpass

AGLenum specifying the function to use when both the stencil testand the depth test pass, or when the stencil test passes and there is no depth bufferor depth testing is disabled. The default value isgl.KEEP.

Return value

None (undefined).

Constants

gl.KEEP

Keeps the current value.

gl.ZERO

Sets the stencil buffer value to 0.

gl.REPLACE

Sets the stencil buffer value to the reference value as specified byWebGLRenderingContext.stencilFunc().

gl.INCR

Increments the current stencil buffer value. Clamps to the maximum representableunsigned value.

gl.INCR_WRAP

Increments the current stencil buffer value. Wraps stencil buffer value to zero whenincrementing the maximum representable unsigned value.

gl.DECR

Decrements the current stencil buffer value. Clamps to 0.

gl.DECR_WRAP

Decrements the current stencil buffer value. Wraps stencil buffer value to themaximum representable unsigned value when decrementing a stencil buffer value of 0.

gl.INVERT

Inverts the current stencil buffer value bitwise.

Examples

The stencil testing is disabled by default. To enable or disable stencil testing, usetheenable() anddisable() methods with the argumentgl.STENCIL_TEST.

js
gl.enable(gl.STENCIL_TEST);gl.stencilOp(gl.INCR, gl.DECR, gl.INVERT);

To get the current information about stencil and depth pass or fail, query thefollowing constants withgetParameter().

js
gl.getParameter(gl.STENCIL_FAIL);gl.getParameter(gl.STENCIL_PASS_DEPTH_PASS);gl.getParameter(gl.STENCIL_PASS_DEPTH_FAIL);gl.getParameter(gl.STENCIL_BACK_FAIL);gl.getParameter(gl.STENCIL_BACK_PASS_DEPTH_PASS);gl.getParameter(gl.STENCIL_BACK_PASS_DEPTH_FAIL);gl.getParameter(gl.STENCIL_BITS);

Specifications

Specification
WebGL Specification
# 5.14.3

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp