glBlendFuncSeparate
glBlendFuncSeparate is an OpenGL function that sets the blending factors separately for the color (RGB) and alpha components during the blending stage. It allows you to control how source and destination colors are weighed in each channel independently, without changing the blending equation itself.
The function signature is glBlendFuncSeparate(GLenum sfactorRGB, GLenum dfactorRGB, GLenum sfactorAlpha, GLenum dfactorAlpha). The four parameters specify
- Standard non-premultiplied alpha blending: glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO)
This uses the source alpha for the RGB blend, while the alpha channel copies the source
- Premultiplied alpha blending: glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA)
Here the source color is already premultiplied by alpha, and the alpha channel blends accordingly.
Compared to glBlendFunc, which applies the same factors to RGB and alpha, glBlendFuncSeparate provides finer control
Related functions include glBlendFunc (single set of factors) and glBlendEquation or glBlendEquationSeparate (to choose the blending