# GlBlendFuncSeparate

_glBlendFuncSeparate: specify pixel arithmetic for RGB and alpha components separately

## Syntax

 SUB _glBlendFunc (BYVAL sfactor AS _UNSIGNED LONG, BYVAL dfactor AS _UNSIGNED LONG)
void _glBlendFunc(GLenum sfactor, GLenum dfactor);

 void _glBlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor);

buf
For _glBlendFunci, specifies the index of the draw buffer for which to set the blend function.
sfactor
Specifies how the red, green, blue, and alpha source blending factors are computed. The initial value is _GL_ONE.
dfactor
Specifies how the red, green, blue, and alpha destination blending factors are computed. The initial value is _GL_ZERO.

## Syntax

 void _glBlendFuncSeparate(GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);
void _glBlendFuncSeparatei(GLuint buf, GLenum srcRGB, GLenum dstRGB, GLenum srcAlpha, GLenum dstAlpha);

buf
For _glBlendFuncSeparatei, specifies the index of the draw buffer for which to set the blend functions.
srcRGB
Specifies how the red, green, and blue blending factors are computed. The initial value is _GL_ONE.
dstRGB
Specifies how the red, green, and blue destination blending factors are computed. The initial value is _GL_ZERO.
srcAlpha
Specified how the alpha source blending factor is computed. The initial value is _GL_ONE.
dstAlpha
Specified how the alpha destination blending factor is computed. The initial value is _GL_ZERO.

## Description

Pixels can be drawn using a function that blends the incoming (source) RGBA values with the RGBA values that are already in the frame buffer (the destination values). Blending is initially disabled. Use _glEnable and _glDisable with argument _GL_BLEND to enable and disable blending.

_glBlendFunc is equivalent to calling _glBlendFuncSeparate with sfactor for both the srcRGB and srcAlpha parameters, and dfactor for both the dstRGB and dstAlpha parameters. _glBlendFunci works the same way relative to _glBlendFuncSeparatei.

_glBlendFuncSeparate defines the operation of blending for all draw buffers when it is enabled. _glBlendFuncSeparatei defines the operation of blending for a single draw buffer specified by buf when enabled for that draw buffer. srcRGB specifies which method is used to scale the source RGB-color components. dstRGB specifies which method is used to scale the destination RGB-color components. Likewise, srcAlpha specifies which method is used to scale the source alpha color component, and dstAlpha specifies which method is used to scale the destination alpha component. The possible methods are described in the following table. Each method defines four scale factors, one each for red, green, blue, and alpha.

In the table and in subsequent equations, first source, second source and destination color components are referred to as (R<sub>s0</sub>, G<sub>s0</sub>, B<sub>s0</sub>, A<sub>s0</sub>), (R<sub>s1</sub>, G<sub>s1</sub>, B<sub>s1</sub>, A<sub>s1</sub>) and (R<sub>d</sub>, G<sub>d</sub>, B<sub>d</sub>, A<sub>d</sub>), respectively. The color specified by _glBlendColor is referred to as (R<sub>c</sub>, G<sub>c</sub>, B<sub>c</sub>, A<sub>c</sub>).

Source and destination scale factors are referred to as (s<sub>R</sub>, s<sub>G</sub>, s<sub>B</sub>, s<sub>A</sub>) and (d<sub>R</sub>, d<sub>G</sub>, d<sub>B</sub>, d<sub>A</sub>).

Parameter RGB Factor Alpha Factor
_GL_ZERO (0, 0, 0) 0
_GL_ONE (1, 1, 1) 1
_GL_SRC_COLOR (R<sub>s0</sub>, G<sub>s0</sub>, B<sub>s0</sub>) A<sub>s0</sub>
_GL_ONE_MINUS_SRC_COLOR (1, 1, 1) - (R<sub>s0</sub>, G<sub>s0</sub>, B<sub>s0</sub>) 1 - A<sub>s0</sub>
_GL_DST_COLOR (R<sub>d</sub>, G<sub>d</sub>, B<sub>d</sub>) A<sub>d</sub>
_GL_ONE_MINUS_DST_COLOR (1, 1, 1) - (R<sub>d</sub>, G<sub>d</sub>, B<sub>d</sub>) 1 - A<sub>d</sub>
_GL_SRC_ALPHA (A<sub>s0</sub>, A<sub>s0</sub>, A<sub>s0</sub>) A<sub>s0</sub>
_GL_ONE_MINUS_SRC_ALPHA (1, 1, 1) - (A<sub>s0</sub>, A<sub>s0</sub>, A<sub>s0</sub>) 1 - A<sub>s0</sub>
_GL_DST_ALPHA (A<sub>d</sub>, A<sub>d</sub>, A<sub>d</sub>) A<sub>d</sub>
_GL_ONE_MINUS_DST_ALPHA (1, 1, 1) - (A<sub>d</sub>, A<sub>d</sub>, A<sub>d</sub>) A<sub>d</sub>
_GL_CONSTANT_COLOR (R<sub>c</sub>, G<sub>c</sub>, B<sub>c</sub>) A<sub>c</sub>
_GL_ONE_MINUS_CONSTANT_COLOR (1, 1, 1) - (R<sub>c</sub>, G<sub>c</sub>, B<sub>c</sub>) 1 - A<sub>c</sub>
_GL_CONSTANT_ALPHA (A<sub>c</sub>, A<sub>c</sub>, A<sub>c</sub>) A<sub>c</sub>
_GL_ONE_MINUS_CONSTANT_ALPHA (1, 1, 1) - (A<sub>c</sub>, A<sub>c</sub>, A<sub>c</sub>) 1 - A<sub>c</sub>
_GL_SRC_ALPHA_SATURATE (i, i, i) 1
_GL_SRC1_COLOR (R<sub>s1</sub>, G<sub>s1</sub>, B<sub>s1</sub>) A<sub>s1</sub>
_GL_ONE_MINUS_SRC_COLOR (1, 1, 1) - (R<sub>s1</sub>, G<sub>s1</sub>, B<sub>s1</sub>) 1 - A<sub>s1</sub>
_GL_SRC1_ALPHA (A<sub>s1</sub>, A<sub>s1</sub>, A<sub>s1</sub>) A<sub>s1</sub>
_GL_ONE_MINUS_SRC_ALPHA (1, 1, 1) - (A<sub>s1</sub>, A<sub>s1</sub>, A<sub>s1</sub>) 1 - A<sub>s1</sub>

In the table,

$i = min(A_{s0}, (1 - A_d))$

Despite the apparent precision of the above equations, blending arithmetic is not exactly specified, because blending operates with imprecise integer color values. However, a blend factor that should be equal to 1 is guaranteed not to modify its multiplicand, and a blend factor equal to 0 reduces its multiplicand to 0. For example, when srcRGB is _GL_SRC_ALPHA, dstRGB is _GL_ONE_MINUS_SRC_ALPHA, and A<sub>s0</sub> is equal to 1, the equations reduce to simple replacement:

\begin{align} R_d = R_{s0}\\ G_d = G_{s0}\\ B_d = B_{s0}\\ A_d = A_{s0}\\ \end{align}

Notes:

When more than one color buffer is enabled for drawing, the GL performs blending separately for each enabled buffer, using the contents of that buffer for destination color. (See _glDrawBuffer.)

When dual source blending is enabled (i.e., one of the blend factors requiring the second color input is used), the maximum number of enabled draw buffers is given by _GL_MAX_DUAL_SOURCE_DRAW_BUFFERS, which may be lower than _GL_MAX_DRAW_BUFFERS.

### Errors

_GL_INVALID_ENUM is generated if either srcRGB or dstRGB is not an accepted value.

_GL_INVALID_VALUE is generated by _glBlendFuncSeparatei if buf is greater than or equal to the value of _GL_MAX_DRAW_BUFFERS.

Use With:

_glGet with argument _GL_BLEND_SRC_RGB

_glGet with argument _GL_BLEND_SRC_ALPHA

_glGet with argument _GL_BLEND_DST_RGB

_glGet with argument _GL_BLEND_DST_ALPHA

_glIsEnabled with argument _GL_BLEND