--- title: WebGLRenderingContext.blendEquation() slug: Web/API/WebGLRenderingContext/blendEquation tags: - API - Method - Reference - WebGL - WebGLRenderingContext translation_of: Web/API/WebGLRenderingContext/blendEquation ---
{{APIRef("WebGL")}}

WebGL API 的 WebGLRenderingContext.blendEquation() 方法用于将RGB混合方程和阿尔法混合方程设置为单个方程。

混合方程式确定新像素如何与 {{domxref("WebGLFramebuffer")}} 中的像素组合。

语法

void gl.blendEquation(mode);

参数

mode
{{domxref("GLenum")}} 指定源和目标颜色的组合方式。 必须是:

异常

如果模式不是三个可能的值之一,则会抛出gl.INVALID_ENUM错误。

返回值

None.

示例

要设置混合方程式,请使用:

gl.blendEquation(gl.FUNC_ADD);
gl.blendEquation(gl.FUNC_SUBTRACT);
gl.blendEquation(gl.FUNC_REVERSE_SUBTRACT);

要获得混合方程,请查询返回 gl.FUNC_ADD,gl.FUNC_SUBTRACT,gl.FUNC_REVERSE_SUBTRACT 或 {{domxref("EXT_blend_minmax")}} 的 BLEND_EQUATION,BLEND_EQUATION_RGB 和 BLEND_EQUATION_ALPHA 常量:ext.MIN_EXT 或 ext.MAX_EXT 。

gl.getParameter(gl.BLEND_EQUATION_RGB) === gl.FUNC_ADD;
// true

gl.getParameter(gl.BLEND_EQUATION_ALPHA) === gl.FUNC_ADD;
// true

规范

Specification Status Comment
{{SpecName('WebGL', "#5.14.3", "blendEquation")}} {{Spec2('WebGL')}} Initial definition for WebGL.
{{SpecName('OpenGL ES 2.0', "glBlendEquation.xml", "glBlendEquation")}} {{Spec2('OpenGL ES 2.0')}} Man page of the OpenGL ES 2.0 API.
{{SpecName('OpenGL ES 3.0', "glBlendEquation.xml", "glBlendEquation")}} {{Spec2('OpenGL ES 3.0')}} Man page of the OpenGL ES 3.0 API.

浏览器兼容性

{{Compat("api/WebGLRenderingContext", "WebGLRenderingContext.blendEquation")}}

另见