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

WebGLRenderingContext: stencilOpSeparate() method

· 52CE 我爱测

The **`WebGLRenderingContext.stencilOpSeparate()`** method of the WebGL API sets the front and/or back-facing stencil test actions.

WebGL

The WebGLRenderingContext.stencilOpSeparate() method of the WebGL API sets the front and/or back-facing stencil test actions.

Syntax

stencilOpSeparate(face, fail, zfail, zpass)

Parameters

  • face

    • : A WebGL_API/Types specifying whether the front and/or back stencil state is updated. The possible values are:
      • gl.FRONT
      • gl.BACK
      • gl.FRONT_AND_BACK
  • fail

    • : A WebGL_API/Types specifying the function to use when the stencil test fails. The default value is gl.KEEP.
  • zfail

    • : A WebGL_API/Types specifying the function to use when the stencil test passes, but the depth test fails. The default value is gl.KEEP.
  • zpass

    • : A WebGL_API/Types specifying the function to use when both the stencil test and the depth test pass, or when the stencil test passes and there is no depth buffer or depth testing is disabled. The default value is gl.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 by WebGLRenderingContext.stencilFunc().
  • gl.INCR
    • : Increments the current stencil buffer value. Clamps to the maximum representable unsigned value.
  • gl.INCR_WRAP
    • : Increments the current stencil buffer value. Wraps stencil buffer value to zero when incrementing 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 the maximum 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, use the WebGLRenderingContext.enable and WebGLRenderingContext.disable methods with the argument gl.STENCIL_TEST.

gl.enable(gl.STENCIL_TEST);
gl.stencilOpSeparate(gl.FRONT, gl.INCR, gl.DECR, gl.INVERT);

To get the current information about stencil and depth pass or fail, query the following constants with WebGLRenderingContext.getParameter.

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

Browser compatibility

See also

  • WebGLRenderingContext.stencilOp()
  • WebGLRenderingContext.stencilFunc()
  • WebGLRenderingContext.stencilFuncSeparate()
  • WebGLRenderingContext.stencilMask()
  • WebGLRenderingContext.stencilMaskSeparate()

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

资料来源与适用范围

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

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

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