1 /* $Id: s_blend.c,v 1.4 2001/03/03 21:11:33 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include "s_alphabuf.h"
35 #include "s_context.h"
40 #if defined(USE_MMX_ASM)
42 #include "X86/common_x86_asm.h"
43 #define _BLENDAPI _ASMAPI
50 * Common transparency blending mode.
53 blend_transparency( GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
54 GLchan rgba
[][4], CONST GLchan dest
[][4] )
57 ASSERT(ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
);
58 ASSERT(ctx
->Color
.BlendSrcRGB
==GL_SRC_ALPHA
);
59 ASSERT(ctx
->Color
.BlendDstRGB
==GL_ONE_MINUS_SRC_ALPHA
);
64 const GLint t
= rgba
[i
][ACOMP
]; /* t in [0, CHAN_MAX] */
67 rgba
[i
][RCOMP
] = dest
[i
][RCOMP
];
68 rgba
[i
][GCOMP
] = dest
[i
][GCOMP
];
69 rgba
[i
][BCOMP
] = dest
[i
][BCOMP
];
70 rgba
[i
][ACOMP
] = dest
[i
][ACOMP
];
72 else if (t
== CHAN_MAX
) {
73 /* 100% alpha, no-op */
77 /* This is pretty close, but Glean complains */
78 const GLint s
= CHAN_MAX
- t
;
79 const GLint r
= (rgba
[i
][RCOMP
] * t
+ dest
[i
][RCOMP
] * s
+ 1) >> 8;
80 const GLint g
= (rgba
[i
][GCOMP
] * t
+ dest
[i
][GCOMP
] * s
+ 1) >> 8;
81 const GLint b
= (rgba
[i
][BCOMP
] * t
+ dest
[i
][BCOMP
] * s
+ 1) >> 8;
82 const GLint a
= (rgba
[i
][ACOMP
] * t
+ dest
[i
][ACOMP
] * s
+ 1) >> 8;
84 /* This is slower but satisfies Glean */
85 const GLint s
= CHAN_MAX
- t
;
86 const GLint r
= (rgba
[i
][RCOMP
] * t
+ dest
[i
][RCOMP
] * s
) / 255;
87 const GLint g
= (rgba
[i
][GCOMP
] * t
+ dest
[i
][GCOMP
] * s
) / 255;
88 const GLint b
= (rgba
[i
][BCOMP
] * t
+ dest
[i
][BCOMP
] * s
) / 255;
89 const GLint a
= (rgba
[i
][ACOMP
] * t
+ dest
[i
][ACOMP
] * s
) / 255;
92 /* This satisfies Glean and should be reasonably fast */
93 /* Contributed by Nathan Hand */
94 #define DIV255(X) (((X) << 8) + (X) + 256) >> 16
95 const GLint s
= CHAN_MAX
- t
;
96 const GLint r
= DIV255(rgba
[i
][RCOMP
] * t
+ dest
[i
][RCOMP
] * s
);
97 const GLint g
= DIV255(rgba
[i
][GCOMP
] * t
+ dest
[i
][GCOMP
] * s
);
98 const GLint b
= DIV255(rgba
[i
][BCOMP
] * t
+ dest
[i
][BCOMP
] * s
);
99 const GLint a
= DIV255(rgba
[i
][ACOMP
] * t
+ dest
[i
][ACOMP
] * s
);
102 const GLint s
= CHAN_MAX
- t
;
103 const GLint r
= (rgba
[i
][RCOMP
] * t
+ dest
[i
][RCOMP
] * s
) / CHAN_MAX
;
104 const GLint g
= (rgba
[i
][GCOMP
] * t
+ dest
[i
][GCOMP
] * s
) / CHAN_MAX
;
105 const GLint b
= (rgba
[i
][BCOMP
] * t
+ dest
[i
][BCOMP
] * s
) / CHAN_MAX
;
106 const GLint a
= (rgba
[i
][ACOMP
] * t
+ dest
[i
][ACOMP
] * s
) / CHAN_MAX
;
109 ASSERT(r
<= CHAN_MAX
);
110 ASSERT(g
<= CHAN_MAX
);
111 ASSERT(b
<= CHAN_MAX
);
112 ASSERT(a
<= CHAN_MAX
);
113 rgba
[i
][RCOMP
] = (GLchan
) r
;
114 rgba
[i
][GCOMP
] = (GLchan
) g
;
115 rgba
[i
][BCOMP
] = (GLchan
) b
;
116 rgba
[i
][ACOMP
] = (GLchan
) a
;
127 static void _BLENDAPI
128 blend_add( GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
129 GLchan rgba
[][4], CONST GLchan dest
[][4] )
132 ASSERT(ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
);
133 ASSERT(ctx
->Color
.BlendSrcRGB
==GL_ONE
);
134 ASSERT(ctx
->Color
.BlendDstRGB
==GL_ONE
);
139 GLint r
= rgba
[i
][RCOMP
] + dest
[i
][RCOMP
];
140 GLint g
= rgba
[i
][GCOMP
] + dest
[i
][GCOMP
];
141 GLint b
= rgba
[i
][BCOMP
] + dest
[i
][BCOMP
];
142 GLint a
= rgba
[i
][ACOMP
] + dest
[i
][ACOMP
];
143 rgba
[i
][RCOMP
] = (GLchan
) MIN2( r
, CHAN_MAX
);
144 rgba
[i
][GCOMP
] = (GLchan
) MIN2( g
, CHAN_MAX
);
145 rgba
[i
][BCOMP
] = (GLchan
) MIN2( b
, CHAN_MAX
);
146 rgba
[i
][ACOMP
] = (GLchan
) MIN2( a
, CHAN_MAX
);
154 * Blend min function (for GL_EXT_blend_minmax)
156 static void _BLENDAPI
157 blend_min( GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
158 GLchan rgba
[][4], CONST GLchan dest
[][4] )
161 ASSERT(ctx
->Color
.BlendEquation
==GL_MIN_EXT
);
166 rgba
[i
][RCOMP
] = (GLchan
) MIN2( rgba
[i
][RCOMP
], dest
[i
][RCOMP
] );
167 rgba
[i
][GCOMP
] = (GLchan
) MIN2( rgba
[i
][GCOMP
], dest
[i
][GCOMP
] );
168 rgba
[i
][BCOMP
] = (GLchan
) MIN2( rgba
[i
][BCOMP
], dest
[i
][BCOMP
] );
169 rgba
[i
][ACOMP
] = (GLchan
) MIN2( rgba
[i
][ACOMP
], dest
[i
][ACOMP
] );
177 * Blend max function (for GL_EXT_blend_minmax)
179 static void _BLENDAPI
180 blend_max( GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
181 GLchan rgba
[][4], CONST GLchan dest
[][4] )
184 ASSERT(ctx
->Color
.BlendEquation
==GL_MAX_EXT
);
189 rgba
[i
][RCOMP
] = (GLchan
) MAX2( rgba
[i
][RCOMP
], dest
[i
][RCOMP
] );
190 rgba
[i
][GCOMP
] = (GLchan
) MAX2( rgba
[i
][GCOMP
], dest
[i
][GCOMP
] );
191 rgba
[i
][BCOMP
] = (GLchan
) MAX2( rgba
[i
][BCOMP
], dest
[i
][BCOMP
] );
192 rgba
[i
][ACOMP
] = (GLchan
) MAX2( rgba
[i
][ACOMP
], dest
[i
][ACOMP
] );
200 * Modulate: result = src * dest
202 static void _BLENDAPI
203 blend_modulate( GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
204 GLchan rgba
[][4], CONST GLchan dest
[][4] )
211 GLint r
= (rgba
[i
][RCOMP
] * dest
[i
][RCOMP
]) >> 8;
212 GLint g
= (rgba
[i
][GCOMP
] * dest
[i
][GCOMP
]) >> 8;
213 GLint b
= (rgba
[i
][BCOMP
] * dest
[i
][BCOMP
]) >> 8;
214 GLint a
= (rgba
[i
][ACOMP
] * dest
[i
][ACOMP
]) >> 8;
215 rgba
[i
][RCOMP
] = (GLchan
) r
;
216 rgba
[i
][GCOMP
] = (GLchan
) g
;
217 rgba
[i
][BCOMP
] = (GLchan
) b
;
218 rgba
[i
][ACOMP
] = (GLchan
) a
;
226 * General case blend pixels.
227 * Input: n - number of pixels
228 * mask - the usual write mask
229 * In/Out: rgba - the incoming and modified pixels
230 * Input: dest - the pixels from the dest color buffer
232 static void _BLENDAPI
233 blend_general( GLcontext
*ctx
, GLuint n
, const GLubyte mask
[],
234 GLchan rgba
[][4], CONST GLchan dest
[][4] )
236 GLfloat rscale
= 1.0F
/ CHAN_MAXF
;
237 GLfloat gscale
= 1.0F
/ CHAN_MAXF
;
238 GLfloat bscale
= 1.0F
/ CHAN_MAXF
;
239 GLfloat ascale
= 1.0F
/ CHAN_MAXF
;
244 GLint Rs
, Gs
, Bs
, As
; /* Source colors */
245 GLint Rd
, Gd
, Bd
, Ad
; /* Dest colors */
246 GLfloat sR
, sG
, sB
, sA
; /* Source scaling */
247 GLfloat dR
, dG
, dB
, dA
; /* Dest scaling */
256 /* Frame buffer color */
262 /* Source RGB factor */
263 switch (ctx
->Color
.BlendSrcRGB
) {
271 sR
= (GLfloat
) Rd
* rscale
;
272 sG
= (GLfloat
) Gd
* gscale
;
273 sB
= (GLfloat
) Bd
* bscale
;
275 case GL_ONE_MINUS_DST_COLOR
:
276 sR
= 1.0F
- (GLfloat
) Rd
* rscale
;
277 sG
= 1.0F
- (GLfloat
) Gd
* gscale
;
278 sB
= 1.0F
- (GLfloat
) Bd
* bscale
;
281 sR
= sG
= sB
= (GLfloat
) As
* ascale
;
283 case GL_ONE_MINUS_SRC_ALPHA
:
284 sR
= sG
= sB
= (GLfloat
) 1.0F
- (GLfloat
) As
* ascale
;
287 sR
= sG
= sB
= (GLfloat
) Ad
* ascale
;
289 case GL_ONE_MINUS_DST_ALPHA
:
290 sR
= sG
= sB
= 1.0F
- (GLfloat
) Ad
* ascale
;
292 case GL_SRC_ALPHA_SATURATE
:
293 if (As
< CHAN_MAX
- Ad
) {
294 sR
= sG
= sB
= (GLfloat
) As
* ascale
;
297 sR
= sG
= sB
= 1.0F
- (GLfloat
) Ad
* ascale
;
300 case GL_CONSTANT_COLOR
:
301 sR
= ctx
->Color
.BlendColor
[0];
302 sG
= ctx
->Color
.BlendColor
[1];
303 sB
= ctx
->Color
.BlendColor
[2];
305 case GL_ONE_MINUS_CONSTANT_COLOR
:
306 sR
= 1.0F
- ctx
->Color
.BlendColor
[0];
307 sG
= 1.0F
- ctx
->Color
.BlendColor
[1];
308 sB
= 1.0F
- ctx
->Color
.BlendColor
[2];
310 case GL_CONSTANT_ALPHA
:
311 sR
= sG
= sB
= ctx
->Color
.BlendColor
[3];
313 case GL_ONE_MINUS_CONSTANT_ALPHA
:
314 sR
= sG
= sB
= 1.0F
- ctx
->Color
.BlendColor
[3];
316 case GL_SRC_COLOR
: /* GL_NV_blend_square */
317 sR
= (GLfloat
) Rs
* rscale
;
318 sG
= (GLfloat
) Gs
* gscale
;
319 sB
= (GLfloat
) Bs
* bscale
;
321 case GL_ONE_MINUS_SRC_COLOR
: /* GL_NV_blend_square */
322 sR
= 1.0F
- (GLfloat
) Rs
* rscale
;
323 sG
= 1.0F
- (GLfloat
) Gs
* gscale
;
324 sB
= 1.0F
- (GLfloat
) Bs
* bscale
;
327 /* this should never happen */
328 _mesa_problem(ctx
, "Bad blend source RGB factor in do_blend");
332 /* Source Alpha factor */
333 switch (ctx
->Color
.BlendSrcA
) {
341 sA
= (GLfloat
) Ad
* ascale
;
343 case GL_ONE_MINUS_DST_COLOR
:
344 sA
= 1.0F
- (GLfloat
) Ad
* ascale
;
347 sA
= (GLfloat
) As
* ascale
;
349 case GL_ONE_MINUS_SRC_ALPHA
:
350 sA
= (GLfloat
) 1.0F
- (GLfloat
) As
* ascale
;
353 sA
=(GLfloat
) Ad
* ascale
;
355 case GL_ONE_MINUS_DST_ALPHA
:
356 sA
= 1.0F
- (GLfloat
) Ad
* ascale
;
358 case GL_SRC_ALPHA_SATURATE
:
361 case GL_CONSTANT_COLOR
:
362 sA
= ctx
->Color
.BlendColor
[3];
364 case GL_ONE_MINUS_CONSTANT_COLOR
:
365 sA
= 1.0F
- ctx
->Color
.BlendColor
[3];
367 case GL_CONSTANT_ALPHA
:
368 sA
= ctx
->Color
.BlendColor
[3];
370 case GL_ONE_MINUS_CONSTANT_ALPHA
:
371 sA
= 1.0F
- ctx
->Color
.BlendColor
[3];
373 case GL_SRC_COLOR
: /* GL_NV_blend_square */
374 sA
= (GLfloat
) As
* ascale
;
376 case GL_ONE_MINUS_SRC_COLOR
: /* GL_NV_blend_square */
377 sA
= 1.0F
- (GLfloat
) As
* ascale
;
380 /* this should never happen */
382 _mesa_problem(ctx
, "Bad blend source A factor in do_blend");
385 /* Dest RGB factor */
386 switch (ctx
->Color
.BlendDstRGB
) {
394 dR
= (GLfloat
) Rs
* rscale
;
395 dG
= (GLfloat
) Gs
* gscale
;
396 dB
= (GLfloat
) Bs
* bscale
;
398 case GL_ONE_MINUS_SRC_COLOR
:
399 dR
= 1.0F
- (GLfloat
) Rs
* rscale
;
400 dG
= 1.0F
- (GLfloat
) Gs
* gscale
;
401 dB
= 1.0F
- (GLfloat
) Bs
* bscale
;
404 dR
= dG
= dB
= (GLfloat
) As
* ascale
;
406 case GL_ONE_MINUS_SRC_ALPHA
:
407 dR
= dG
= dB
= (GLfloat
) 1.0F
- (GLfloat
) As
* ascale
;
410 dR
= dG
= dB
= (GLfloat
) Ad
* ascale
;
412 case GL_ONE_MINUS_DST_ALPHA
:
413 dR
= dG
= dB
= 1.0F
- (GLfloat
) Ad
* ascale
;
415 case GL_CONSTANT_COLOR
:
416 dR
= ctx
->Color
.BlendColor
[0];
417 dG
= ctx
->Color
.BlendColor
[1];
418 dB
= ctx
->Color
.BlendColor
[2];
420 case GL_ONE_MINUS_CONSTANT_COLOR
:
421 dR
= 1.0F
- ctx
->Color
.BlendColor
[0];
422 dG
= 1.0F
- ctx
->Color
.BlendColor
[1];
423 dB
= 1.0F
- ctx
->Color
.BlendColor
[2];
425 case GL_CONSTANT_ALPHA
:
426 dR
= dG
= dB
= ctx
->Color
.BlendColor
[3];
428 case GL_ONE_MINUS_CONSTANT_ALPHA
:
429 dR
= dG
= dB
= 1.0F
- ctx
->Color
.BlendColor
[3];
431 case GL_DST_COLOR
: /* GL_NV_blend_square */
432 dR
= (GLfloat
) Rd
* rscale
;
433 dG
= (GLfloat
) Gd
* gscale
;
434 dB
= (GLfloat
) Bd
* bscale
;
436 case GL_ONE_MINUS_DST_COLOR
: /* GL_NV_blend_square */
437 dR
= 1.0F
- (GLfloat
) Rd
* rscale
;
438 dG
= 1.0F
- (GLfloat
) Gd
* gscale
;
439 dB
= 1.0F
- (GLfloat
) Bd
* bscale
;
442 /* this should never happen */
444 _mesa_problem(ctx
, "Bad blend dest RGB factor in do_blend");
447 /* Dest Alpha factor */
448 switch (ctx
->Color
.BlendDstA
) {
456 dA
= (GLfloat
) As
* ascale
;
458 case GL_ONE_MINUS_SRC_COLOR
:
459 dA
= 1.0F
- (GLfloat
) As
* ascale
;
462 dA
= (GLfloat
) As
* ascale
;
464 case GL_ONE_MINUS_SRC_ALPHA
:
465 dA
= (GLfloat
) 1.0F
- (GLfloat
) As
* ascale
;
468 dA
= (GLfloat
) Ad
* ascale
;
470 case GL_ONE_MINUS_DST_ALPHA
:
471 dA
= 1.0F
- (GLfloat
) Ad
* ascale
;
473 case GL_CONSTANT_COLOR
:
474 dA
= ctx
->Color
.BlendColor
[3];
476 case GL_ONE_MINUS_CONSTANT_COLOR
:
477 dA
= 1.0F
- ctx
->Color
.BlendColor
[3];
479 case GL_CONSTANT_ALPHA
:
480 dA
= ctx
->Color
.BlendColor
[3];
482 case GL_ONE_MINUS_CONSTANT_ALPHA
:
483 dA
= 1.0F
- ctx
->Color
.BlendColor
[3];
485 case GL_DST_COLOR
: /* GL_NV_blend_square */
486 dA
= (GLfloat
) Ad
* ascale
;
488 case GL_ONE_MINUS_DST_COLOR
: /* GL_NV_blend_square */
489 dA
= 1.0F
- (GLfloat
) Ad
* ascale
;
492 /* this should never happen */
494 _mesa_problem(ctx
, "Bad blend dest A factor in do_blend");
498 /* Due to round-off problems we have to clamp against zero. */
499 /* Optimization: we don't have to do this for all src & dst factors */
500 if (dA
< 0.0F
) dA
= 0.0F
;
501 if (dR
< 0.0F
) dR
= 0.0F
;
502 if (dG
< 0.0F
) dG
= 0.0F
;
503 if (dB
< 0.0F
) dB
= 0.0F
;
504 if (sA
< 0.0F
) sA
= 0.0F
;
505 if (sR
< 0.0F
) sR
= 0.0F
;
506 if (sG
< 0.0F
) sG
= 0.0F
;
507 if (sB
< 0.0F
) sB
= 0.0F
;
518 /* compute blended color */
519 if (ctx
->Color
.BlendEquation
==GL_FUNC_ADD_EXT
) {
520 r
= Rs
* sR
+ Rd
* dR
+ 0.5F
;
521 g
= Gs
* sG
+ Gd
* dG
+ 0.5F
;
522 b
= Bs
* sB
+ Bd
* dB
+ 0.5F
;
523 a
= As
* sA
+ Ad
* dA
+ 0.5F
;
525 else if (ctx
->Color
.BlendEquation
==GL_FUNC_SUBTRACT_EXT
) {
526 r
= Rs
* sR
- Rd
* dR
+ 0.5F
;
527 g
= Gs
* sG
- Gd
* dG
+ 0.5F
;
528 b
= Bs
* sB
- Bd
* dB
+ 0.5F
;
529 a
= As
* sA
- Ad
* dA
+ 0.5F
;
531 else if (ctx
->Color
.BlendEquation
==GL_FUNC_REVERSE_SUBTRACT_EXT
) {
532 r
= Rd
* dR
- Rs
* sR
+ 0.5F
;
533 g
= Gd
* dG
- Gs
* sG
+ 0.5F
;
534 b
= Bd
* dB
- Bs
* sB
+ 0.5F
;
535 a
= Ad
* dA
- As
* sA
+ 0.5F
;
538 /* should never get here */
539 r
= g
= b
= a
= 0.0F
; /* silence uninitialized var warning */
540 _mesa_problem(ctx
, "unexpected BlendEquation in blend_general()");
544 rgba
[i
][RCOMP
] = (GLchan
) (GLint
) CLAMP( r
, 0.0F
, CHAN_MAXF
);
545 rgba
[i
][GCOMP
] = (GLchan
) (GLint
) CLAMP( g
, 0.0F
, CHAN_MAXF
);
546 rgba
[i
][BCOMP
] = (GLchan
) (GLint
) CLAMP( b
, 0.0F
, CHAN_MAXF
);
547 rgba
[i
][ACOMP
] = (GLchan
) (GLint
) CLAMP( a
, 0.0F
, CHAN_MAXF
);
557 * Analyze current blending parameters to pick fastest blending function.
558 * Result: the ctx->Color.BlendFunc pointer is updated.
560 void _swrast_choose_blend_func( GLcontext
*ctx
)
562 const GLenum eq
= ctx
->Color
.BlendEquation
;
563 const GLenum srcRGB
= ctx
->Color
.BlendSrcRGB
;
564 const GLenum dstRGB
= ctx
->Color
.BlendDstRGB
;
565 const GLenum srcA
= ctx
->Color
.BlendSrcA
;
566 const GLenum dstA
= ctx
->Color
.BlendDstA
;
568 if (srcRGB
!= srcA
|| dstRGB
!= dstA
) {
569 SWRAST_CONTEXT(ctx
)->BlendFunc
= blend_general
;
571 else if (eq
==GL_FUNC_ADD_EXT
&& srcRGB
==GL_SRC_ALPHA
572 && dstRGB
==GL_ONE_MINUS_SRC_ALPHA
)
574 #if defined(USE_MMX_ASM)
576 SWRAST_CONTEXT(ctx
)->BlendFunc
= _mesa_mmx_blend_transparency
;
580 SWRAST_CONTEXT(ctx
)->BlendFunc
= blend_transparency
;
582 else if (eq
==GL_FUNC_ADD_EXT
&& srcRGB
==GL_ONE
&& dstRGB
==GL_ONE
) {
583 SWRAST_CONTEXT(ctx
)->BlendFunc
= blend_add
;
585 else if (((eq
==GL_FUNC_ADD_EXT
|| eq
==GL_FUNC_REVERSE_SUBTRACT_EXT
)
586 && (srcRGB
==GL_ZERO
&& dstRGB
==GL_SRC_COLOR
))
588 ((eq
==GL_FUNC_ADD_EXT
|| eq
==GL_FUNC_SUBTRACT_EXT
)
589 && (srcRGB
==GL_DST_COLOR
&& dstRGB
==GL_ZERO
))) {
590 SWRAST_CONTEXT(ctx
)->BlendFunc
= blend_modulate
;
592 else if (eq
==GL_MIN_EXT
) {
593 SWRAST_CONTEXT(ctx
)->BlendFunc
= blend_min
;
595 else if (eq
==GL_MAX_EXT
) {
596 SWRAST_CONTEXT(ctx
)->BlendFunc
= blend_max
;
599 SWRAST_CONTEXT(ctx
)->BlendFunc
= blend_general
;
606 * Apply the blending operator to a span of pixels.
607 * Input: n - number of pixels in span
608 * x, y - location of leftmost pixel in span in window coords.
609 * mask - boolean mask indicating which pixels to blend.
610 * In/Out: rgba - pixel values
613 _mesa_blend_span( GLcontext
*ctx
, GLuint n
, GLint x
, GLint y
,
614 GLchan rgba
[][4], const GLubyte mask
[] )
616 GLchan dest
[MAX_WIDTH
][4];
618 /* Check if device driver can do the work */
619 if (ctx
->Color
.BlendEquation
==GL_LOGIC_OP
&&
620 !ctx
->Color
.ColorLogicOpEnabled
) {
624 /* Read span of current frame buffer pixels */
625 _mesa_read_rgba_span( ctx
, ctx
->DrawBuffer
, n
, x
, y
, dest
);
627 SWRAST_CONTEXT(ctx
)->BlendFunc( ctx
, n
, mask
, rgba
,
628 (const GLchan (*)[4])dest
);
634 * Apply the blending operator to an array of pixels.
635 * Input: n - number of pixels in span
636 * x, y - array of pixel locations
637 * mask - boolean mask indicating which pixels to blend.
638 * In/Out: rgba - pixel values
641 _mesa_blend_pixels( GLcontext
*ctx
,
642 GLuint n
, const GLint x
[], const GLint y
[],
643 GLchan rgba
[][4], const GLubyte mask
[] )
645 SWcontext
*swrast
= SWRAST_CONTEXT(ctx
);
646 GLchan dest
[PB_SIZE
][4];
648 /* Check if device driver can do the work */
649 if (ctx
->Color
.BlendEquation
==GL_LOGIC_OP
&&
650 !ctx
->Color
.ColorLogicOpEnabled
) {
654 /* Read pixels from current color buffer */
655 (*ctx
->Driver
.ReadRGBAPixels
)( ctx
, n
, x
, y
, dest
, mask
);
656 if (swrast
->_RasterMask
& ALPHABUF_BIT
) {
657 _mesa_read_alpha_pixels( ctx
, n
, x
, y
, dest
, mask
);
660 swrast
->BlendFunc( ctx
, n
, mask
, rgba
, (const GLchan (*)[4])dest
);