GLAPI/glBlendFuncSeparate: Difference between revisions

From OpenGL Wiki
Jump to navigation Jump to search
m Renaming category: 'API Reference 4' to 'Core API Reference'.
m Bot: Adding better formatting.
Line 8: Line 8:
== Function Definition ==
== Function Definition ==


   void '''glBlendFuncSeparate'''(GLenum ''srcRGB'', GLenum ''dstRGB'', GLenum ''srcAlpha'', GLenum ''dstAlpha'');
   void '''glBlendFuncSeparate'''(GLenum {{param|srcRGB}}, GLenum {{param|dstRGB}}, GLenum {{param|srcAlpha}}, GLenum {{param|dstAlpha}});
   void '''glBlendFuncSeparatei'''(GLuint ''buf'', GLenum ''srcRGB'', GLenum ''dstRGB'', GLenum ''srcAlpha'', GLenum ''dstAlpha'');
   void '''glBlendFuncSeparatei'''(GLuint {{param|buf}}, GLenum {{param|srcRGB}}, GLenum {{param|dstRGB}}, GLenum {{param|srcAlpha}}, GLenum {{param|dstAlpha}});


; buf
; buf
Line 24: Line 24:
== Description ==
== 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 [[GLAPI/glEnable|glEnable]] and [[GLAPI/glDisable|glDisable]] with argument {{code|GL_BLEND}} to enable and disable blending.
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 {{apifunc|glEnable}} and {{apifunc|glDisable}} with argument {{code|GL_BLEND}} to enable and disable blending.


'''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.
'''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 {{param|buf}} when enabled for that draw buffer. {{param|srcRGB}} specifies which method is used to scale the source RGB-color components. {{param|dstRGB}} specifies which method is used to scale the destination RGB-color components. Likewise, {{param|srcAlpha}} specifies which method is used to scale the source alpha color component, and {{param|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 <math>(R_{s0}, G_{s0}, B_{s0}, A_{s0})</math>, <math>(R_{s1}, G_{s1}, B_{s1}, A_{s1})</math> and <math>(R_d, G_d, B_d, A_d)</math>, respectively. The color specified by [[GLAPI/glBlendColor|glBlendColor]] is referred to as <math>(R_c, G_c, B_c, A_c)</math>. They are understood to have integer values between 0 and <math>(k_R, k_G, k_B, k_A)</math>, where
In the table and in subsequent equations, first source, second source and destination color components are referred to as <math>(R_{s0}, G_{s0}, B_{s0}, A_{s0})</math>, <math>(R_{s1}, G_{s1}, B_{s1}, A_{s1})</math> and <math>(R_d, G_d, B_d, A_d)</math>, respectively. The color specified by {{apifunc|glBlendColor}} is referred to as <math>(R_c, G_c, B_c, A_c)</math>. They are understood to have integer values between 0 and <math>(k_R, k_G, k_B, k_A)</math>, where


<math>k_c = 2^{m_c} - 1</math>
<math>k_c = 2^{m_c} - 1</math>
Line 132: Line 132:
\end{align}</math>
\end{align}</math>


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 {{code|GL_SRC_ALPHA}}, ''dstRGB'' is {{code|GL_ONE_MINUS_SRC_ALPHA}}, and <math>A_s</math> is equal to <math>k_A</math>, the equations reduce to simple replacement:
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 {{param|srcRGB}} is {{code|GL_SRC_ALPHA}}, {{param|dstRGB}} is {{code|GL_ONE_MINUS_SRC_ALPHA}}, and <math>A_s</math> is equal to <math>k_A</math>, the equations reduce to simple replacement:


<math>\begin{align}
<math>\begin{align}
Line 145: Line 145:
Incoming (source) alpha is correctly thought of as a material opacity, ranging from 1.0 (<math>k_A</math>), representing complete opacity, to 0.0 (0), representing complete transparency.
Incoming (source) alpha is correctly thought of as a material opacity, ranging from 1.0 (<math>k_A</math>), representing complete opacity, to 0.0 (0), representing complete transparency.


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 [[GLAPI/glDrawBuffer|glDrawBuffer]].)
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 {{apifunc|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 {{code|GL_MAX_DUAL_SOURCE_DRAW_BUFFERS}}, which may be lower than {{code|GL_MAX_DRAW_BUFFERS}}.
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 {{code|GL_MAX_DUAL_SOURCE_DRAW_BUFFERS}}, which may be lower than {{code|GL_MAX_DRAW_BUFFERS}}.
Line 151: Line 151:
== Errors ==
== Errors ==


{{code|GL_INVALID_ENUM}} is generated if either ''srcRGB'' or ''dstRGB'' is not an accepted value.
{{code|GL_INVALID_ENUM}} is generated if either {{param|srcRGB}} or {{param|dstRGB}} is not an accepted value.


{{code|GL_INVALID_VALUE}} is generated by '''glBlendFuncSeparatei''' if ''buf'' is greater than or equal to the value of {{code|GL_MAX_DRAW_BUFFERS}}.
{{code|GL_INVALID_VALUE}} is generated by '''glBlendFuncSeparatei''' if {{param|buf}} is greater than or equal to the value of {{code|GL_MAX_DRAW_BUFFERS}}.


== Associated Gets ==
== Associated Gets ==


[[GLAPI/glGet|glGet]] with argument {{code|GL_BLEND_SRC_RGB}}
{{apifunc|glGet}} with argument {{code|GL_BLEND_SRC_RGB}}


[[GLAPI/glGet|glGet]] with argument {{code|GL_BLEND_SRC_ALPHA}}
{{apifunc|glGet}} with argument {{code|GL_BLEND_SRC_ALPHA}}


[[GLAPI/glGet|glGet]] with argument {{code|GL_BLEND_DST_RGB}}
{{apifunc|glGet}} with argument {{code|GL_BLEND_DST_RGB}}


[[GLAPI/glGet|glGet]] with argument {{code|GL_BLEND_DST_ALPHA}}
{{apifunc|glGet}} with argument {{code|GL_BLEND_DST_ALPHA}}


[[GLAPI/glIsEnabled|glIsEnabled]] with argument {{code|GL_BLEND}}
{{apifunc|glIsEnabled}} with argument {{code|GL_BLEND}}




Line 171: Line 171:
== See Also ==
== See Also ==


[[GLAPI/glBlendColor|glBlendColor]], [[GLAPI/glBlendFunc|glBlendFunc]], [[GLAPI/glBlendEquation|glBlendEquation]], [[GLAPI/glClear|glClear]], [[GLAPI/glDrawBuffer|glDrawBuffer]], [[GLAPI/glEnable|glEnable]], [[GLAPI/glLogicOp|glLogicOp]], [[GLAPI/glStencilFunc|glStencilFunc]]
{{apifunc|glBlendColor}}, {{apifunc|glBlendFunc}}, {{apifunc|glBlendEquation}}, {{apifunc|glClear}}, {{apifunc|glDrawBuffer}}, {{apifunc|glEnable}}, {{apifunc|glLogicOp}}, {{apifunc|glStencilFunc}}


== Copyright ==
== Copyright ==

Revision as of 01:13, 29 April 2012

glBlendFuncSeparate
Core in version 4.6
Core since version 1.4

glBlendFuncSeparate: specify pixel arithmetic for RGB and alpha components separately

Function Definition

 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.

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_{s0},G_{s0},B_{s0},A_{s0}) $, $ (R_{s1},G_{s1},B_{s1},A_{s1}) $ and $ (R_{d},G_{d},B_{d},A_{d}) $, respectively. The color specified by glBlendColor is referred to as $ (R_{c},G_{c},B_{c},A_{c}) $. They are understood to have integer values between 0 and $ (k_{R},k_{G},k_{B},k_{A}) $, where

$ k_{c}=2^{m_{c}}-1 $

and $ (m_{R},m_{G},m_{B},m_{A}) $ are the number of red, green, blue, and alpha bitplanes.

Source and destination scale factors are referred to as $ (s_{R},s_{G},s_{B},s_{A}) $ and $ (d_{R},d_{G},d_{B},d_{A}) $. All scale factors have range [0, 1].

Parameter RGB Factor Alpha Factor
GL_ZERO $ (0,0,0) $ $ 0 $
GL_ONE $ (1,1,1) $ $ 1 $
GL_SRC_COLOR $ \left({\tfrac {R_{s0}}{k_{R}}},{\tfrac {G_{s0}}{k_{G}}},{\tfrac {B_{s0}}{k_{B}}}\right) $ $ {\tfrac {A_{s0}}{k_{A}}} $
GL_ONE_MINUS_SRC_COLOR $ (1,1,1)-\left({\tfrac {R_{s0}}{k_{R}}},{\tfrac {G_{s0}}{k_{G}}},{\tfrac {B_{s0}}{k_{B}}}\right) $ $ 1-{\tfrac {A_{s0}}{k_{A}}} $
GL_DST_COLOR $ \left({\tfrac {R_{d}}{k_{R}}},{\tfrac {G_{d}}{k_{G}}},{\tfrac {B_{d}}{k_{B}}}\right) $ $ {\tfrac {A_{d}}{k_{A}}} $
GL_ONE_MINUS_DST_COLOR $ (1,1,1)-\left({\tfrac {R_{d}}{k_{R}}},{\tfrac {G_{d}}{k_{G}}},{\tfrac {B_{d}}{k_{B}}}\right) $ $ 1-{\tfrac {A_{d}}{k_{A}}} $
GL_SRC_ALPHA $ \left({\tfrac {A_{s0}}{k_{A}}},{\tfrac {A_{s0}}{k_{A}}},{\tfrac {A_{s0}}{k_{A}}}\right) $ $ {\tfrac {A_{s0}}{k_{A}}} $
GL_ONE_MINUS_SRC_ALPHA $ (1,1,1)-\left({\tfrac {A_{s0}}{k_{A}}},{\tfrac {A_{s0}}{k_{A}}},{\tfrac {A_{s0}}{k_{A}}}\right) $ $ 1-{\tfrac {A_{s0}}{k_{A}}} $
GL_DST_ALPHA $ \left({\tfrac {A_{d}}{k_{A}}},{\tfrac {A_{d}}{k_{A}}},{\tfrac {A_{d}}{k_{A}}}\right) $ $ {\tfrac {A_{d}}{k_{A}}} $
GL_ONE_MINUS_DST_ALPHA $ (1,1,1)-\left({\tfrac {A_{d}}{k_{A}}},{\tfrac {A_{d}}{k_{A}}},{\tfrac {A_{d}}{k_{A}}}\right) $ $ 1-{\tfrac {A_{d}}{k_{A}}} $
GL_CONSTANT_COLOR $ \left({\tfrac {R_{c}}{k_{R}}},{\tfrac {G_{c}}{k_{G}}},{\tfrac {B_{c}}{k_{B}}}\right) $ $ {\tfrac {A_{c}}{k_{A}}} $
GL_ONE_MINUS_CONSTANT_COLOR $ (1,1,1)-\left({\tfrac {R_{d}}{k_{R}}},{\tfrac {G_{d}}{k_{G}}},{\tfrac {B_{d}}{k_{B}}}\right) $ $ 1-{\tfrac {A_{d}}{k_{A}}} $
GL_CONSTANT_ALPHA $ \left({\tfrac {A_{c}}{k_{A}}},{\tfrac {A_{c}}{k_{A}}},{\tfrac {A_{c}}{k_{A}}}\right) $ $ {\tfrac {A_{c}}{k_{A}}} $
GL_ONE_MINUS_CONSTANT_ALPHA $ (1,1,1)-\left({\tfrac {A_{c}}{k_{A}}},{\tfrac {A_{c}}{k_{A}}},{\tfrac {A_{c}}{k_{A}}}\right) $ $ 1-{\tfrac {A_{c}}{k_{A}}} $
GL_SRC_ALPHA_SATURATE $ (i,i,i) $ $ 1 $
GL_SRC1_COLOR $ \left({\tfrac {R_{s1}}{k_{R}}},{\tfrac {G_{s1}}{k_{G}}},{\tfrac {B_{s1}}{k_{B}}}\right) $ $ {\tfrac {A_{s1}}{k_{A}}} $
GL_ONE_MINUS_SRC_COLOR $ (1,1,1)-\left({\tfrac {R_{s1}}{k_{R}}},{\tfrac {G_{s1}}{k_{G}}},{\tfrac {B_{s1}}{k_{B}}}\right) $ $ 1-{\tfrac {A_{s1}}{k_{A}}} $
GL_SRC1_ALPHA $ \left({\tfrac {A_{s1}}{k_{A}}},{\tfrac {A_{s1}}{k_{A}}},{\tfrac {A_{s1}}{k_{A}}}\right) $ $ {\tfrac {A_{s1}}{k_{A}}} $
GL_ONE_MINUS_SRC_ALPHA $ (1,1,1)-\left({\tfrac {A_{s1}}{k_{A}}},{\tfrac {A_{s1}}{k_{A}}},{\tfrac {A_{s1}}{k_{A}}}\right) $ $ 1-{\tfrac {A_{s1}}{k_{A}}} $

In the table,

$ i={\frac {min(A_{s},(k_{A}-A_{d}))}{k_{A}}} $

To determine the blended RGBA values of a pixel, the system uses the following equations:

$ {\begin{aligned}R_{d}=min(k_{R},R_{s}*s_{R}+R_{d}*d_{R})\\G_{d}=min(k_{G},G_{s}*s_{G}+G_{d}*d_{G})\\B_{d}=min(k_{B},B_{s}*s_{B}+B_{d}*d_{B})\\A_{d}=min(k_{A},A_{s}*s_{A}+A_{d}*d_{A})\\\end{aligned}} $

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_{s} $ is equal to $ k_{A} $, the equations reduce to simple replacement:

$ {\begin{aligned}R_{d}=R_{s}\\G_{d}=G_{s}\\B_{d}=B_{s}\\A_{d}=A_{s}\\\end{aligned}} $

Notes

Incoming (source) alpha is correctly thought of as a material opacity, ranging from 1.0 ($ k_{A} $), representing complete opacity, to 0.0 (0), representing complete transparency.

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.

Associated Gets

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


See Also

glBlendColor, glBlendFunc, glBlendEquation, glClear, glDrawBuffer, glEnable, glLogicOp, glStencilFunc

Copyright

Copyright © 1991-2006 Silicon Graphics, Inc. This document is licensed under the SGI Free Software B License. For details, see http://oss.sgi.com/projects/FreeB/.