WebGLRenderingContext.blendFuncSeparate()
方法在
WebGL API
defines which function is used for blending pixel arithmetic for RGB and alpha components separately.
void gl.blendFuncSeparate(srcRGB, dstRGB, srcAlpha, dstAlpha);
srcRGB
GLenum
specifying a multiplier for the red, green and blue (RGB) source blending factors. The default value is
gl.ONE
. For possible values, see below.
dstRGB
GLenum
specifying a multiplier for the red, green and blue (RGB) destination blending factors. The default value is
gl.ZERO
. For possible values, see below.
srcAlpha
GLenum
specifying a multiplier for the alpha source blending factor. The default value is
gl.ONE
. For possible values, see below.
dstAlpha
GLenum
specifying a multiplier for the alpha destination blending factor. The default value is
gl.ZERO
. For possible values, see below.
None.
gl.INVALID_ENUM
error is thrown.
srcRGB
) and destination (
dstRGB
) factors, a
gl.INVALID_ENUM
error is thrown.
The following constants can be used for srcRGB , dstRGB , srcAlpha ,和 dstAlpha
The formulas for the blending factors can be described like this (all RGBA values are between 0 and 1):
| 常量 | RGB factor | Alpha factor | 描述 |
|---|---|---|---|
gl.ZERO
|
0,0,0 | 0 | Multiplies all colors by 0. |
gl.ONE
|
1,1,1,1 | 1 | Multiplies all colors by 1. |
gl.SRC_COLOR
|
R S , G S , B S | A S | Multiplies all colors by the source colors. |
gl.ONE_MINUS_SRC_COLOR
|
1-R S , 1-G S , 1-B S | 1-A S | Multiplies all colors by 1 minus each source color. |
gl.DST_COLOR
|
R D , G D , B D | A D | Multiplies all colors by the destination color. |
gl.ONE_MINUS_DST_COLOR
|
1-R D , 1-G D , 1-B D | 1-A D | Multiplies all colors by 1 minus each destination color. |
gl.SRC_ALPHA
|
A S , A S , A S | A S | Multiplies all colors by the source alpha color. |
gl.ONE_MINUS_SRC_ALPHA
|
1-A S , 1-A S , 1-A S | 1-A S | Multiplies all colors by 1 minus the source alpha color. |
gl.DST_ALPHA
|
A D , A D , A D | A D | Multiplies all colors by the destination alpha color. |
gl.ONE_MINUS_DST_ALPHA
|
1-A D , 1-A D , 1-A D | 1-A D | Multiplies all colors by 1 minus the destination alpha color. |
gl.CONSTANT_COLOR
|
R C , G C , B C | A C | Multiplies all colors by a constant color. |
gl.ONE_MINUS_CONSTANT_COLOR
|
1-R C , 1-G C , 1-B C | 1-A C | Multiplies all colors by 1 minus a constant color. |
gl.CONSTANT_ALPHA
|
A C , A C , A C | A C | Multiplies all colors by a constant alpha value. |
gl.ONE_MINUS_CONSTANT_ALPHA
|
1-A C , 1-A C , 1-A C | 1-A C | Multiplies all colors by 1 minus a constant alpha value. |
gl.SRC_ALPHA_SATURATE
|
min(A S , 1 - A D ), min(A S , 1 - A D ), min(A S , 1 - A D ) | 1 | Multiplies the RGB colors by the smaller of either the source alpha color or the value of 1 minus the destination alpha color. The alpha value is multiplied by 1. |
To use the blend function, you first have to activate blending with
WebGLRenderingContext.enable()
with the argument
gl.BLEND
.
gl.enable(gl.BLEND); gl.blendFuncSeparate(gl.SRC_COLOR, gl.DST_COLOR, gl.ONE, gl.ZERO);
To get the current blend function, query the
BLEND_SRC_RGB
,
BLEND_SRC_ALPHA
,
BLEND_DST_RGB
,和
BLEND_DST_ALPHA
constants which return one of the blend function constants.
gl.enable(gl.BLEND); gl.blendFuncSeparate(gl.SRC_COLOR, gl.DST_COLOR, gl.ONE, gl.ZERO); gl.getParameter(gl.BLEND_SRC_RGB) == gl.SRC_COLOR; // true
| 规范 | 状态 | 注释 |
|---|---|---|
|
WebGL 1.0
The definition of 'blendFunc' in that specification. |
推荐 |
初始定义。
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. |
|
OpenGL ES 2.0
The definition of 'glBlendFunc' in that specification. |
标准 | Man page of the OpenGL API. |
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
更新 GitHub 上的兼容性数据| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
blendFuncSeparate
|
Chrome 9 | Edge 12 | Firefox 4 | IE 11 | Opera 12 | Safari 5.1 | WebView Android Yes | Chrome Android 25 | Firefox Android Yes | Opera Android 12 | Safari iOS 8 | Samsung Internet Android 1.5 |
SharedArrayBuffer
as a parameter
|
Chrome 60 | Edge ≤79 | Firefox 79 | IE ? | Opera 47 | Safari ? | WebView Android 60 | Chrome Android 60 | Firefox Android ? | Opera Android 44 | Safari iOS ? | Samsung Internet Android 8.0 |
完整支持
兼容性未知
WebGLRenderingContext
activeTexture()
attachShader()
bindAttribLocation()
bindBuffer()
bindFramebuffer()
bindRenderbuffer()
bindTexture()
blendColor()
blendEquation()
blendEquationSeparate()
blendFunc()
blendFuncSeparate()
bufferData()
bufferSubData()
checkFramebufferStatus()
clear()
clearColor()
clearDepth()
clearStencil()
colorMask()
commit()
compileShader()
compressedTexImage[23]D()
compressedTexSubImage2D()
copyTexImage2D()
copyTexSubImage2D()
createBuffer()
createFramebuffer()
createProgram()
createRenderbuffer()
createShader()
createTexture()
cullFace()
deleteBuffer()
deleteFramebuffer()
deleteProgram()
deleteRenderbuffer()
deleteShader()
deleteTexture()
depthFunc()
depthMask()
depthRange()
detachShader()
disable()
disableVertexAttribArray()
drawArrays()
drawElements()
enable()
enableVertexAttribArray()
finish()
flush()
framebufferRenderbuffer()
framebufferTexture2D()
frontFace()
generateMipmap()
getActiveAttrib()
getActiveUniform()
getAttachedShaders()
getAttribLocation()
getBufferParameter()
getContextAttributes()
getError()
getExtension()
getFramebufferAttachmentParameter()
getParameter()
getProgramInfoLog()
getProgramParameter()
getRenderbufferParameter()
getShaderInfoLog()
getShaderParameter()
getShaderPrecisionFormat()
getShaderSource()
getSupportedExtensions()
getTexParameter()
getUniform()
getUniformLocation()
getVertexAttrib()
getVertexAttribOffset()
hint()
isBuffer()
isContextLost()
isEnabled()
isFramebuffer()
isProgram()
isRenderbuffer()
isShader()
isTexture()
lineWidth()
linkProgram()
pixelStorei()
polygonOffset()
readPixels()
renderbufferStorage()
sampleCoverage()
scissor()
shaderSource()
stencilFunc()
stencilFuncSeparate()
stencilMask()
stencilMaskSeparate()
stencilOp()
stencilOpSeparate()
texImage2D()
texParameter[fi]()
texSubImage2D()
uniform[1234][fi][v]()
uniformMatrix[234]fv()
useProgram()
validateProgram()
vertexAttrib[1234]f[v]()
vertexAttribPointer()
viewport()
ANGLE_instanced_arrays
EXT_blend_minmax
EXT_color_buffer_half_float
EXT_disjoint_timer_query
EXT_frag_depth
EXT_sRGB
EXT_shader_texture_lod
EXT_texture_filter_anisotropic
OES_element_index_uint
OES_standard_derivatives
OES_texture_float
OES_texture_float_linear
OES_texture_half_float
OES_texture_half_float_linear
OES_vertex_array_object
WEBGL_color_buffer_float
WEBGL_compressed_texture_atc
WEBGL_compressed_texture_etc1
WEBGL_compressed_texture_pvrtc
WEBGL_compressed_texture_s3tc
WEBGL_compressed_texture_s3tc_srgb
WEBGL_debug_renderer_info
WEBGL_debug_shaders
WEBGL_depth_texture
WEBGL_draw_buffers
WEBGL_lose_context
WebGL2RenderingContext
WebGLActiveInfo
WebGLBuffer
WebGLContextEvent
WebGLFramebuffer
WebGLObject
WebGLProgram
WebGLQuery
WebGLRenderbuffer
WebGLSampler
WebGLShader
WebGLShaderPrecisionFormat
WebGLSync
WebGLTexture
WebGLTransformFeedback
WebGLUniformLocation
WebGLVertexArrayObject