- /* Dest RGB factor */
- switch (ctx->Color.BlendDstRGB) {
- case GL_ZERO:
- dR = dG = dB = 0.0F;
- break;
- case GL_ONE:
- dR = dG = dB = 1.0F;
- break;
- case GL_SRC_COLOR:
- dR = (GLfloat) Rs * rscale;
- dG = (GLfloat) Gs * gscale;
- dB = (GLfloat) Bs * bscale;
- break;
- case GL_ONE_MINUS_SRC_COLOR:
- dR = 1.0F - (GLfloat) Rs * rscale;
- dG = 1.0F - (GLfloat) Gs * gscale;
- dB = 1.0F - (GLfloat) Bs * bscale;
- break;
- case GL_SRC_ALPHA:
- dR = dG = dB = (GLfloat) As * ascale;
- break;
- case GL_ONE_MINUS_SRC_ALPHA:
- dR = dG = dB = (GLfloat) 1.0F - (GLfloat) As * ascale;
- break;
- case GL_DST_ALPHA:
- dR = dG = dB = (GLfloat) Ad * ascale;
- break;
- case GL_ONE_MINUS_DST_ALPHA:
- dR = dG = dB = 1.0F - (GLfloat) Ad * ascale;
- break;
- case GL_CONSTANT_COLOR:
- dR = ctx->Color.BlendColor[0];
- dG = ctx->Color.BlendColor[1];
- dB = ctx->Color.BlendColor[2];
- break;
- case GL_ONE_MINUS_CONSTANT_COLOR:
- dR = 1.0F - ctx->Color.BlendColor[0];
- dG = 1.0F - ctx->Color.BlendColor[1];
- dB = 1.0F - ctx->Color.BlendColor[2];
- break;
- case GL_CONSTANT_ALPHA:
- dR = dG = dB = ctx->Color.BlendColor[3];
- break;
- case GL_ONE_MINUS_CONSTANT_ALPHA:
- dR = dG = dB = 1.0F - ctx->Color.BlendColor[3];
- break;
- case GL_DST_COLOR: /* GL_NV_blend_square */
- dR = (GLfloat) Rd * rscale;
- dG = (GLfloat) Gd * gscale;
- dB = (GLfloat) Bd * bscale;
- break;
- case GL_ONE_MINUS_DST_COLOR: /* GL_NV_blend_square */
- dR = 1.0F - (GLfloat) Rd * rscale;
- dG = 1.0F - (GLfloat) Gd * gscale;
- dB = 1.0F - (GLfloat) Bd * bscale;
- break;
- default:
- /* this should never happen */
- dR = dG = dB = 0.0F;
- gl_problem(ctx, "Bad blend dest RGB factor in do_blend");
- }
-
- /* Dest Alpha factor */
- switch (ctx->Color.BlendDstA) {
- case GL_ZERO:
- dA = 0.0F;
- break;
- case GL_ONE:
- dA = 1.0F;
- break;
- case GL_SRC_COLOR:
- dA = (GLfloat) As * ascale;
- break;
- case GL_ONE_MINUS_SRC_COLOR:
- dA = 1.0F - (GLfloat) As * ascale;
- break;
- case GL_SRC_ALPHA:
- dA = (GLfloat) As * ascale;
- break;
- case GL_ONE_MINUS_SRC_ALPHA:
- dA = (GLfloat) 1.0F - (GLfloat) As * ascale;
- break;
- case GL_DST_ALPHA:
- dA = (GLfloat) Ad * ascale;
- break;
- case GL_ONE_MINUS_DST_ALPHA:
- dA = 1.0F - (GLfloat) Ad * ascale;
- break;
- case GL_CONSTANT_COLOR:
- dA = ctx->Color.BlendColor[3];
- break;
- case GL_ONE_MINUS_CONSTANT_COLOR:
- dA = 1.0F - ctx->Color.BlendColor[3];
- break;
- case GL_CONSTANT_ALPHA:
- dA = ctx->Color.BlendColor[3];
- break;
- case GL_ONE_MINUS_CONSTANT_ALPHA:
- dA = 1.0F - ctx->Color.BlendColor[3];
- break;
- case GL_DST_COLOR: /* GL_NV_blend_square */
- dA = (GLfloat) Ad * ascale;
- break;
- case GL_ONE_MINUS_DST_COLOR: /* GL_NV_blend_square */
- dA = 1.0F - (GLfloat) Ad * ascale;
- break;
- default:
- /* this should never happen */
- dA = 0.0F;
- gl_problem(ctx, "Bad blend dest A factor in do_blend");
- return;
- }
-
- /* Due to round-off problems we have to clamp against zero. */
- /* Optimization: we don't have to do this for all src & dst factors */
- if (dA < 0.0F) dA = 0.0F;
- if (dR < 0.0F) dR = 0.0F;
- if (dG < 0.0F) dG = 0.0F;
- if (dB < 0.0F) dB = 0.0F;
- if (sA < 0.0F) sA = 0.0F;
- if (sR < 0.0F) sR = 0.0F;
- if (sG < 0.0F) sG = 0.0F;
- if (sB < 0.0F) sB = 0.0F;
-
- ASSERT( sR <= 1.0 );
- ASSERT( sG <= 1.0 );
- ASSERT( sB <= 1.0 );
- ASSERT( sA <= 1.0 );
- ASSERT( dR <= 1.0 );
- ASSERT( dG <= 1.0 );
- ASSERT( dB <= 1.0 );
- ASSERT( dA <= 1.0 );
-
- /* compute blended color */
- if (ctx->Color.BlendEquation==GL_FUNC_ADD_EXT) {
- r = Rs * sR + Rd * dR;
- g = Gs * sG + Gd * dG;
- b = Bs * sB + Bd * dB;
- a = As * sA + Ad * dA;
- }
- else if (ctx->Color.BlendEquation==GL_FUNC_SUBTRACT_EXT) {
- r = Rs * sR - Rd * dR;
- g = Gs * sG - Gd * dG;
- b = Bs * sB - Bd * dB;
- a = As * sA - Ad * dA;
- }
- else if (ctx->Color.BlendEquation==GL_FUNC_REVERSE_SUBTRACT_EXT) {
- r = Rd * dR - Rs * sR;
- g = Gd * dG - Gs * sG;
- b = Bd * dB - Bs * sB;
- a = Ad * dA - As * sA;
- }
- else {
- /* should never get here */
- r = g = b = a = 0.0F; /* silence uninitialized var warning */
- gl_problem(ctx, "unexpected BlendEquation in blend_general()");
- }
-
- /* final clamping */
- rgba[i][RCOMP] = (GLubyte) (GLint) CLAMP( r, 0.0F, CHAN_MAXF );
- rgba[i][GCOMP] = (GLubyte) (GLint) CLAMP( g, 0.0F, CHAN_MAXF );
- rgba[i][BCOMP] = (GLubyte) (GLint) CLAMP( b, 0.0F, CHAN_MAXF );
- rgba[i][ACOMP] = (GLubyte) (GLint) CLAMP( a, 0.0F, CHAN_MAXF );
- }
- }
-}
-
-
-
-#if defined(USE_MMX_ASM)
-#include "X86/mmx.h"
-#include "X86/common_x86asm.h"
-#endif
-
-
-/*
- * Analyze current blending parameters to pick fastest blending function.
- * Result: the ctx->Color.BlendFunc pointer is updated.
- */
-static void set_blend_function( GLcontext *ctx )
-{
- const GLenum eq = ctx->Color.BlendEquation;
- const GLenum srcRGB = ctx->Color.BlendSrcRGB;
- const GLenum dstRGB = ctx->Color.BlendDstRGB;
- const GLenum srcA = ctx->Color.BlendSrcA;
- const GLenum dstA = ctx->Color.BlendDstA;
-
-#if defined(USE_MMX_ASM)
- /* Hmm. A table here would have 12^4 == way too many entries.
- * Provide a hook for MMX instead.
- */
- if (gl_x86_cpu_features & GL_CPU_MMX) {
- gl_mmx_set_blend_function (ctx);
- }
- else
-#endif
- if (srcRGB != srcA || dstRGB != dstA) {
- ctx->Color.BlendFunc = blend_general;
- }
- else if (eq==GL_FUNC_ADD_EXT && srcRGB==GL_SRC_ALPHA
- && dstRGB==GL_ONE_MINUS_SRC_ALPHA) {
- ctx->Color.BlendFunc = blend_transparency;
- }
- else if (eq==GL_FUNC_ADD_EXT && srcRGB==GL_ONE && dstRGB==GL_ONE) {
- ctx->Color.BlendFunc = blend_add;
- }
- else if (((eq==GL_FUNC_ADD_EXT || eq==GL_FUNC_REVERSE_SUBTRACT_EXT)
- && (srcRGB==GL_ZERO && dstRGB==GL_SRC_COLOR))
- ||
- ((eq==GL_FUNC_ADD_EXT || eq==GL_FUNC_SUBTRACT_EXT)
- && (srcRGB==GL_DST_COLOR && dstRGB==GL_ZERO))) {
- ctx->Color.BlendFunc = blend_modulate;
- }
- else if (eq==GL_MIN_EXT) {
- ctx->Color.BlendFunc = blend_min;
- }
- else if (eq==GL_MAX_EXT) {
- ctx->Color.BlendFunc = blend_max;
- }
- else {
- ctx->Color.BlendFunc = blend_general;
- }
-}
-
-
-
-/*
- * Apply the blending operator to a span of pixels.
- * Input: n - number of pixels in span
- * x, y - location of leftmost pixel in span in window coords.
- * mask - boolean mask indicating which pixels to blend.
- * In/Out: rgba - pixel values
- */
-void
-_mesa_blend_span( GLcontext *ctx, GLuint n, GLint x, GLint y,
- GLubyte rgba[][4], const GLubyte mask[] )
-{
- GLubyte dest[MAX_WIDTH][4];
-
- /* Check if device driver can do the work */
- if (ctx->Color.BlendEquation==GL_LOGIC_OP &&
- !ctx->Color.ColorLogicOpEnabled) {
- return;
- }
-
- /* Read span of current frame buffer pixels */
- gl_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
-
- if (!ctx->Color.BlendFunc)
- set_blend_function(ctx);
-
- (*ctx->Color.BlendFunc)( ctx, n, mask, rgba, (const GLubyte (*)[4])dest );
-}
-
-
-
-/*
- * Apply the blending operator to an array of pixels.
- * Input: n - number of pixels in span
- * x, y - array of pixel locations
- * mask - boolean mask indicating which pixels to blend.
- * In/Out: rgba - pixel values
- */
-void
-_mesa_blend_pixels( GLcontext *ctx,
- GLuint n, const GLint x[], const GLint y[],
- GLubyte rgba[][4], const GLubyte mask[] )
-{
- GLubyte dest[PB_SIZE][4];
-
- /* Check if device driver can do the work */
- if (ctx->Color.BlendEquation==GL_LOGIC_OP &&
- !ctx->Color.ColorLogicOpEnabled) {