aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/extras/ogl-sample/main/doc/man/mangl/standard/blendfunc.gl
blob: 7afec27320b1e55e4298bfc665c09170e29c3170 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
_C_ License Applicability. Except to the extent portions of this file are
_C_ made subject to an alternative license as permitted in the SGI Free
_C_ Software License B, Version 1.1 (the "License"), the contents of this
_C_ file are subject only to the provisions of the License. You may not use
_C_ this file except in compliance with the License. You may obtain a copy
_C_ of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
_C_ Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
_C_ 
_C_ http://oss.sgi.com/projects/FreeB
_C_ 
_C_ Note that, as provided in the License, the Software is distributed on an
_C_ "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
_C_ DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
_C_ CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
_C_ PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
_C_ 
_C_ Original Code. The Original Code is: OpenGL Sample Implementation,
_C_ Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
_C_ Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
_C_ Copyright in any portions created by third parties is as indicated
_C_ elsewhere herein. All Rights Reserved.
_C_ 
_C_ Additional Notice Provisions: The application programming interfaces
_C_ established by SGI in conjunction with the Original Code are The
_C_ OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
_C_ April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
_C_ 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
_C_ Window System(R) (Version 1.3), released October 19, 1998. This software
_C_ was created using the OpenGL(R) version 1.2.1 Sample Implementation
_C_ published by SGI, but has not been independently verified as being
_C_ compliant with the OpenGL(R) version 1.2.1 Specification.
_C_
_C_ The first character in this file must be an '_'!
_C_ Anything on a line after _C_ is ignored
_define(_filters,tbl|eqn)_C_
_C_      eqn is automatically replaced with neqn for nroff
_header(BlendFunc, specify pixel arithmetic)
_names(BlendFunc)
.EQ
delim $$
.EN
.SH PARAMETERS
_phead(_param1)
Specifies how the red, green, blue,
and alpha source blending factors are computed.
The following symbolic constants are accepted:
_const(ZERO),
_const(ONE),
_const(DST_COLOR),
_const(ONE_MINUS_DST_COLOR),
_const(SRC_ALPHA),
_const(ONE_MINUS_SRC_ALPHA),
_const(DST_ALPHA),
_const(ONE_MINUS_DST_ALPHA), and
_const(SRC_ALPHA_SATURATE).
The initial value is _const(ONE).
.TE

Additionally, if the _arbstring(imaging) extension is supported, the
following constants are accepted:
_const(CONSTANT_COLOR),
_const(ONE_MINUS_CONSTANT_COLOR),
_const(CONSTANT_ALPHA),
_const(ONE_MINUS_CONSTANT_ALPHA).
_phead(_param2)
Specifies how the red, green, blue,
and alpha destination blending factors are computed.
Eight symbolic constants are accepted:
_const(ZERO),
_const(ONE),
_const(SRC_COLOR),
_const(ONE_MINUS_SRC_COLOR),
_const(SRC_ALPHA),
_const(ONE_MINUS_SRC_ALPHA),
_const(DST_ALPHA), and
_const(ONE_MINUS_DST_ALPHA).
The initial value is _const(ZERO).
.TE

Additionally, if the _arbstring(imaging) extension is supported, the
following constants are accepted:
_const(CONSTANT_COLOR),
_const(ONE_MINUS_CONSTANT_COLOR),
_const(CONSTANT_ALPHA),
_const(ONE_MINUS_CONSTANT_ALPHA).
.SH DESCRIPTION
In RGBA mode, 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 _cmnd(Enable) and _cmnd(Disable) with argument _const(BLEND)
to enable and disable blending.
.P
_cmnd defines the operation of blending when it is enabled.
_param1 specifies which of nine methods is used to scale the
source color components.
_param2 specifies which of eight methods is used to scale the
destination color components.
The eleven possible methods are described in the following table.
Each method defines four scale factors,
one each for red, green, blue, and alpha.
.P
In the table and in subsequent equations, source and destination
color components are referred to as
$(R sub s , G sub s , B sub s , A sub s )$ and
$(R sub d , G sub d , B sub d , A sub d )$.
The color specified by _cmnd(BlendColor) is referred to as
$(R sub c , G sub c , B sub c , A sub c )$.
They are understood to have integer values between 0 and
$(k sub R , k sub G , k sub B , k sub A )$,
where
.P
.RS
.ce
$k sub c ~=~ 2 sup m sub c - 1$ 
.RE
.P
and
$(m sub R , m sub G , m sub B , m sub A )$
is the number of red,
green,
blue,
and alpha bitplanes.
.P
Source and destination scale factors are referred to as
$(s sub R , s sub G , s sub B , s sub A )$ and
$(d sub R , d sub G , d sub B , d sub A )$.
The scale factors described in the table,
denoted $(f sub R , f sub G , f sub B , f sub A )$,
represent either source or destination factors.
All scale factors have range [0,\ 1].
.P
.TS
center;
lb cb
l c .
_
Parameter	$(f sub R , ~~ f sub G , ~~ f sub B , ~~ f sub A )$ 
_
_const(ZERO)	$(0, ~0, ~0, ~0 )$
_const(ONE)	$(1, ~1, ~1, ~1 )$
_const(SRC_COLOR)	$(R sub s / k sub R , ~G sub s / k sub G , ~B sub s / k sub B , ~A sub s / k sub A )$
_const(ONE_MINUS_SRC_COLOR)	$(1, ~1, ~1, ~1 ) ~-~ (R sub s / k sub R , ~G sub s / k sub G , ~B sub s / k sub B , ~A sub s / k sub A )$
_const(DST_COLOR)	$(R sub d / k sub R , ~G sub d / k sub G , ~B sub d / k sub B , ~A sub d / k sub A )$
_const(ONE_MINUS_DST_COLOR)	$(1, ~1, ~1, ~1 ) ~-~ (R sub d / k sub R , ~G sub d / k sub G , ~B sub d / k sub B , ~A sub d / k sub A )$
_const(SRC_ALPHA)	$(A sub s / k sub A , ~A sub s / k sub A , ~A sub s / k sub A , ~A sub s / k sub A )$
_const(ONE_MINUS_SRC_ALPHA)	$(1, ~1, ~1, ~1 ) ~-~ (A sub s / k sub A , ~A sub s / k sub A , ~A sub s / k sub A , ~A sub s / k sub A )$
_const(DST_ALPHA)	$(A sub d / k sub A , ~A sub d / k sub A , ~A sub d / k sub A , ~A sub d / k sub A )$
_const(ONE_MINUS_DST_ALPHA)	$(1, ~1, ~1, ~1 ) ~-~ (A sub d / k sub A , ~A sub d / k sub A , ~A sub d / k sub A , ~A sub d / k sub A )$
_const(SRC_ALPHA_SATURATE)	$(i, ~i, ~i, ~1 )$
_const(CONSTANT_COLOR)	$(R sub c, G sub c, B sub c, A sub c)$
_const(ONE_MINUS_CONSTANT_COLOR)	$(1, ~1, ~1, ~1 ) ~-~ (R sub c, G sub c, B sub c, A sub c)$
_const(CONSTANT_ALPHA)	$(A sub c, A sub c, A sub c, A sub c)$
_const(ONE_MINUS_CONSTANT_ALPHA)	$(1, ~1, ~1, ~1 ) ~-~ (A sub c, A sub c, A sub c, A sub c)$
_
.TE
.sp
In the table,
.P
.RS
.nf
.IP
$i ~=~  min (A sub s , ~k sub A ~-~ A sub d ) ~/~ k sub A$
.fi
.RE
.P
To determine the blended RGBA values of a pixel when drawing in RGBA mode,
the system uses the following equations:
.P
.RS
.nf
.IP
$R sub d ~=~ mark   min ( k sub R, ~R sub s~s sub R~+~R sub d~d sub R )$
$G sub d ~=~ lineup min ( k sub G, ~G sub s~s sub G~+~G sub d~d sub G )$
$B sub d ~=~ lineup min ( k sub B, ~B sub s~s sub B~+~B sub d~d sub B )$
$A sub d ~=~ lineup min ( k sub A, ~A sub s~s sub A~+~A sub d~d sub A )$
.fi
.RE
.P
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 _param1 is _const(SRC_ALPHA),
_param2 is _const(ONE_MINUS_SRC_ALPHA),
and $A sub s$ is equal to $k sub A$,
the equations reduce to simple replacement:
.P
.RS
.nf
.IP
$R sub d ~=~ mark   R sub s$
$G sub d ~=~ lineup G sub s$
$B sub d ~=~ lineup B sub s$
$A sub d ~=~ lineup A sub s$
.fi
.RE
.P
.SH EXAMPLES
.P
Transparency is best implemented using blend function
(_const(SRC_ALPHA), _const(ONE_MINUS_SRC_ALPHA))
with primitives sorted from farthest to nearest.
Note that this transparency calculation does not require
the presence of alpha bitplanes in the frame buffer.
.P
Blend function
(_const(SRC_ALPHA), _const(ONE_MINUS_SRC_ALPHA))
is also useful for rendering antialiased points and lines
in arbitrary order.
.P
Polygon antialiasing is optimized using blend function
.br
(_const(SRC_ALPHA_SATURATE), _const(ONE))
with polygons sorted from nearest to farthest.
(See the _cmnd(Enable), _cmnd(Disable) reference page and the 
_const(POLYGON_SMOOTH) argument for information on polygon antialiasing.)
Destination alpha bitplanes,
which must be present for this blend function to operate correctly,
store the accumulated coverage.
.SH NOTES
Incoming (source) alpha is correctly thought of as a material opacity,
ranging from 1.0 ($K sub A$), representing complete opacity,
to 0.0 (0), representing complete 
transparency.
.P
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 _cmnd(DrawBuffer).)
.P
Blending affects only RGBA rendering.
It is ignored by color index renderers.
.P
_const(CONSTANT_COLOR), _const(ONE_MINUS_CONSTANT_COLOR),
_const(CONSTANT_ALPHA), _const(ONE_MINUS_CONSTANT_ALPHA) are only
available if the _arbstring(imaging) is supported by your implementation.
.SH ERRORS
_const(INVALID_ENUM) is generated if either _param1 or _param2 is not an
accepted value.
.P
_const(INVALID_OPERATION) is generated if _cmnd
is executed between the execution of _cmnd(Begin)
and the corresponding execution of _cmnd(End).
.SH ASSOCIATED GETS
_cmnd(Get) with argument _const(BLEND_SRC)
.br
_cmnd(Get) with argument _const(BLEND_DST)
.br
_cmnd(IsEnabled) with argument _const(BLEND)
.br
.SH SEE ALSO
_cmnd(AlphaFunc),
_cmnd(BlendColor),
_cmnd(BlendEquation),
_cmnd(Clear),
_cmnd(DrawBuffer),
_cmnd(Enable),
_cmnd(LogicOp),
_cmnd(StencilFunc)