From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- .../api/webglrenderingcontext/blendfunc/index.html | 180 +++++++++++++++++++++ 1 file changed, 180 insertions(+) create mode 100644 files/zh-cn/web/api/webglrenderingcontext/blendfunc/index.html (limited to 'files/zh-cn/web/api/webglrenderingcontext/blendfunc/index.html') diff --git a/files/zh-cn/web/api/webglrenderingcontext/blendfunc/index.html b/files/zh-cn/web/api/webglrenderingcontext/blendfunc/index.html new file mode 100644 index 0000000000..1b7bc65eb7 --- /dev/null +++ b/files/zh-cn/web/api/webglrenderingcontext/blendfunc/index.html @@ -0,0 +1,180 @@ +--- +title: WebGLRenderingContext.blendFunc() +slug: Web/API/WebGLRenderingContext/blendFunc +translation_of: Web/API/WebGLRenderingContext/blendFunc +--- +
{{APIRef("WebGL")}}
+ +

WebGL APIWebGLRenderingContext.blendFunc() 方法定义了一个用于混合像素算法的函数.

+ +

语法

+ +
void gl.blendFunc(sfactor, dfactor);
+
+ +

参数

+ +
+
sfactor
+
 {{domxref("GLenum")}} 为源混合因子指定一个乘数. 默认值是 gl.ONE. 有关可能的值, 查看下面.
+
dfactor
+
 {{domxref("GLenum")}} 为源目标合因子指定一个乘数. 默认值是 gl.ZERO. 有关可能的值, 查看下面.
+
+ +

返回值

+ +

None.

+ +

异常

+ + + +

常量

+ +

下列常数可用于  sfactordfactor.

+ +

混合颜色的公式可以这样描述: color(RGBA) = (sourceColor * sfactor) + (destinationColor * dfactor). RBGA 值在 0 到1 之间.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
ConstantFactorDescription
gl.ZERO0,0,0,0所有颜色乘0.
gl.ONE1,1,1,1所有颜色乘1.
gl.SRC_COLORRS, GS, BS, AS将所有颜色乘上源颜色.
gl.ONE_MINUS_SRC_COLOR1-RS, 1-GS, 1-BS, 1-AS每个源颜色所有颜色乘1 .
gl.DST_COLORRD, GD, BD, AD将所有颜色与目标颜色相乘.
gl.ONE_MINUS_DST_COLOR1-RD, 1-GD, 1-BD, 1-AD将所有颜色乘以1减去每个目标颜色.
gl.SRC_ALPHAAS, AS, AS, AS将所有颜色乘以源alpha值.
gl.ONE_MINUS_SRC_ALPHA1-AS, 1-AS, 1-AS, 1-AS将所有颜色乘以1 减去源alpha值.
gl.DST_ALPHAAD, AD, AD, AD将所有颜色与目标alpha值相乘.
gl.ONE_MINUS_DST_ALPHA1-AD, 1-AD, 1-AD, 1-AD将所有颜色乘以1减去目标alpha值.
gl.CONSTANT_COLORRC, GC, BC, AC将所有颜色乘以一个常数颜色.
gl.ONE_MINUS_CONSTANT_COLOR1-RC, 1-GC, 1-BC, 1-AC所有颜色乘以1减去一个常数颜色.
gl.CONSTANT_ALPHAAC, AC, AC, AC将所有颜色乘以一个常数.
gl.ONE_MINUS_CONSTANT_ALPHA1-AC, 1-AC, 1-AC, 1-AC所有颜色乘以1减去一个常数.
gl.SRC_ALPHA_SATURATE +

min(AS, 1 - AD), min(AS, 1 - AD), min(AS, 1 - AD), 1

+
将RGB颜色乘以源alpha值或1减去目标alpha值中的较小值。alpha值乘以1.
+ +

示例

+ +

使用混合函数, 您首先必须使用参数 gl.BLEND来激活{{domxref("WebGLRenderingContext.enable()")}} 的混合.

+ +
gl.enable(gl.BLEND);
+gl.blendFunc(gl.SRC_COLOR, gl.DST_COLOR);
+
+ +

要获得当前的混合函数, 查询BLEND_SRC_RGB, BLEND_SRC_ALPHA, BLEND_DST_RGB, 和BLEND_DST_ALPHA 常量中返回混合函数常量.

+ +
gl.enable(gl.BLEND);
+gl.blendFunc(gl.SRC_COLOR, gl.DST_COLOR);
+gl.getParameter(gl.BLEND_SRC_RGB) == gl.SRC_COLOR;
+// true
+
+ +

说明

+ + + + + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('WebGL', "#5.14.3", "blendFunc")}}{{Spec2('WebGL')}}Initial definition.
+ In WebGL, constant color and constant alpha cannot be used together as source and destination factors in the blend function. See section 6.13. of the specification.
{{SpecName('OpenGL ES 2.0', "glBlendFunc.xml", "glBlendFunc")}}{{Spec2('OpenGL ES 2.0')}}Man page of the OpenGL API.
+ +

浏览器兼容性

+ + + +

{{Compat("api.WebGLRenderingContext.blendFunc")}}

+ +

另见

+ + -- cgit v1.2.3-54-g00ecf