glBlendFunci
glBlendFunc for one colour attachment only, when a shader writes to several at once.
Signature
void glBlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor);
How it works
With multiple render targets (glDrawBuffers), the fragment shader writes one output per attachment. glBlendFunc would give them all the same blending; glBlendFunci sets it for draw buffer number buf alone.
Weighted blended order-independent transparency needs exactly this: an accumulation buffer that adds everything (GL_ONE, GL_ONE) next to a revealage buffer that multiplies (GL_ZERO, GL_ONE_MINUS_SRC_COLOR), in one draw call.
Parameters
Index into the glDrawBuffers list (0 = the first output), not the attachment enum.
Factor for the new colour, as in glBlendFunc.
Factor for the stored colour.
Tips & pitfalls
Blending is switched per buffer too: glEnablei(GL_BLEND, buf).
Errors
When the call is invalid it does nothing and sets an error, which glGetError returns:
- GL_INVALID_VALUE
- buf is not below GL_MAX_DRAW_BUFFERS.
- GL_INVALID_ENUM
- A factor is not an accepted value.
Example
1// weighted blended OIT: two targets, two blend modes
2glEnable(GL_BLEND);
3glBlendFunci(0, GL_ONE, GL_ONE); // accumulation
4glBlendFunci(1, GL_ZERO, GL_ONE_MINUS_SRC_COLOR); // revealage
5drawTransparent();