- Vertex Specification
- Vertex Processing
- Vertex Post-Processing
- Primitive Assembly
- Fragment Shader
- Per-Sample Processing
A Logical Operation is a Per-Sample Processing operation applied between the Fragment's color values and color values in the Framebuffer being rendered to that correspond to that particular fragment color. Logical operations are boolean operations performed on the bit pattern that represents the colors.
To activate logical operations, GL_COLOR_LOGIC_OP must be enabled. Whenever logical operations are enabled, all Blending operations are disabled.
Because logical operations are bitwise boolean operations, there are some times when such operations are not appropriate. These are defined by attributes of the image attached to the framebuffer that corresponds to that fragment color. When logical operations are enabled, logical operations will only take place for a specific color buffer if all of the following are true:
- sRGB rendering is disabled, or if it is enabled, the framebuffer image's image format is not in the sRGB colorspace.
If either of these conditions fail, then that particular color buffer will not have logical operations performed on it. Other buffers in the rendering operation may still pass these tests, and they will have logical operations performed on them.
There are a number of different logical operations available. Note that, unlike Blending, OpenGL logical operations cannot perform separate operations for different fragment colors. All fragment colors (except for those which can't use logic ops, as above) will use the same operation.
The particular operation to use is set by the following function:
The opcode defines which operation to use (the default value is . The available logic ops, and their result, is listed in the following table. Logic ops are performed individually per-component.
The component value for the fragment color is called S; the component value from the framebuffer image is called D. "&" is a bitwise and, "|" is a bitwise or, "^" is the bitwise xor, and ~ is the bitwise negation.
|GL_AND||S & D|
|GL_NAND||~(S & D)|
|GL_OR||S | D|
|GL_NOR||~(S | D)|
|GL_XOR||S ^ D|
|GL_EQUIV||~(S ^ D)|
|GL_AND_REVERSE||S & ~D|
|GL_AND_INVERTED||~S & D|
|GL_OR_REVERSE||S | ~D|
|GL_OR_INVERTED||~S | D|