st_atom_blend.c File Reference

Include dependency graph for st_atom_blend.c:

Go to the source code of this file.

Functions

static GLuint translate_blend (GLenum blend)
 Convert GLenum blend tokens to pipe tokens.
static GLuint translate_logicop (GLenum logicop)
 Convert GLenum logicop tokens to pipe tokens.
static void update_blend (struct st_context *st)

Variables

struct st_tracked_state st_update_blend


Function Documentation

static GLuint translate_blend ( GLenum  blend  )  [static]

Convert GLenum blend tokens to pipe tokens.

Both blend factors and blend funcs are accepted.

Definition at line 49 of file st_atom_blend.c.

References assert, PIPE_BLEND_ADD, PIPE_BLEND_MAX, PIPE_BLEND_MIN, PIPE_BLEND_REVERSE_SUBTRACT, PIPE_BLEND_SUBTRACT, PIPE_BLENDFACTOR_CONST_ALPHA, PIPE_BLENDFACTOR_CONST_COLOR, PIPE_BLENDFACTOR_DST_ALPHA, PIPE_BLENDFACTOR_DST_COLOR, PIPE_BLENDFACTOR_INV_CONST_ALPHA, PIPE_BLENDFACTOR_INV_CONST_COLOR, PIPE_BLENDFACTOR_INV_DST_ALPHA, PIPE_BLENDFACTOR_INV_DST_COLOR, PIPE_BLENDFACTOR_INV_SRC_ALPHA, PIPE_BLENDFACTOR_INV_SRC_COLOR, PIPE_BLENDFACTOR_ONE, PIPE_BLENDFACTOR_SRC_ALPHA, PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE, PIPE_BLENDFACTOR_SRC_COLOR, and PIPE_BLENDFACTOR_ZERO.

00050 {
00051    switch (blend) {
00052    /* blend functions */
00053    case GL_FUNC_ADD:
00054       return PIPE_BLEND_ADD;
00055    case GL_FUNC_SUBTRACT:
00056       return PIPE_BLEND_SUBTRACT;
00057    case GL_FUNC_REVERSE_SUBTRACT:
00058       return PIPE_BLEND_REVERSE_SUBTRACT;
00059    case GL_MIN:
00060       return PIPE_BLEND_MIN;
00061    case GL_MAX:
00062       return PIPE_BLEND_MAX;
00063 
00064    /* blend factors */
00065    case GL_ONE:
00066       return PIPE_BLENDFACTOR_ONE;
00067    case GL_SRC_COLOR:
00068       return PIPE_BLENDFACTOR_SRC_COLOR;
00069    case GL_SRC_ALPHA:
00070       return PIPE_BLENDFACTOR_SRC_ALPHA;
00071    case GL_DST_ALPHA:
00072       return PIPE_BLENDFACTOR_DST_ALPHA;
00073    case GL_DST_COLOR:
00074       return PIPE_BLENDFACTOR_DST_COLOR;
00075    case GL_SRC_ALPHA_SATURATE:
00076       return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE;
00077    case GL_CONSTANT_COLOR:
00078       return PIPE_BLENDFACTOR_CONST_COLOR;
00079    case GL_CONSTANT_ALPHA:
00080       return PIPE_BLENDFACTOR_CONST_ALPHA;
00081       /*
00082       return PIPE_BLENDFACTOR_SRC1_COLOR;
00083       return PIPE_BLENDFACTOR_SRC1_ALPHA;
00084       */
00085    case GL_ZERO:
00086       return PIPE_BLENDFACTOR_ZERO;
00087    case GL_ONE_MINUS_SRC_COLOR:
00088       return PIPE_BLENDFACTOR_INV_SRC_COLOR;
00089    case GL_ONE_MINUS_SRC_ALPHA:
00090       return PIPE_BLENDFACTOR_INV_SRC_ALPHA;
00091    case GL_ONE_MINUS_DST_COLOR:
00092       return PIPE_BLENDFACTOR_INV_DST_COLOR;
00093    case GL_ONE_MINUS_DST_ALPHA:
00094       return PIPE_BLENDFACTOR_INV_DST_ALPHA;
00095    case GL_ONE_MINUS_CONSTANT_COLOR:
00096       return PIPE_BLENDFACTOR_INV_CONST_COLOR;
00097    case GL_ONE_MINUS_CONSTANT_ALPHA:
00098       return PIPE_BLENDFACTOR_INV_CONST_ALPHA;
00099       /*
00100       return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
00101       return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
00102       */
00103    default:
00104       assert("invalid GL token in translate_blend()" == NULL);
00105       return 0;
00106    }
00107 }

static GLuint translate_logicop ( GLenum  logicop  )  [static]

Convert GLenum logicop tokens to pipe tokens.

Definition at line 114 of file st_atom_blend.c.

References assert, PIPE_LOGICOP_AND, PIPE_LOGICOP_AND_INVERTED, PIPE_LOGICOP_AND_REVERSE, PIPE_LOGICOP_CLEAR, PIPE_LOGICOP_COPY, PIPE_LOGICOP_COPY_INVERTED, PIPE_LOGICOP_EQUIV, PIPE_LOGICOP_INVERT, PIPE_LOGICOP_NAND, PIPE_LOGICOP_NOOP, PIPE_LOGICOP_NOR, PIPE_LOGICOP_OR, PIPE_LOGICOP_OR_INVERTED, PIPE_LOGICOP_OR_REVERSE, PIPE_LOGICOP_SET, and PIPE_LOGICOP_XOR.

00115 {
00116    switch (logicop) {
00117    case GL_CLEAR:
00118       return PIPE_LOGICOP_CLEAR;
00119    case GL_NOR:
00120       return PIPE_LOGICOP_NOR;
00121    case GL_AND_INVERTED:
00122       return PIPE_LOGICOP_AND_INVERTED;
00123    case GL_COPY_INVERTED:
00124       return PIPE_LOGICOP_COPY_INVERTED;
00125    case GL_AND_REVERSE:
00126       return PIPE_LOGICOP_AND_REVERSE;
00127    case GL_INVERT:
00128       return PIPE_LOGICOP_INVERT;
00129    case GL_XOR:
00130       return PIPE_LOGICOP_XOR;
00131    case GL_NAND:
00132       return PIPE_LOGICOP_NAND;
00133    case GL_AND:
00134       return PIPE_LOGICOP_AND;
00135    case GL_EQUIV:
00136       return PIPE_LOGICOP_EQUIV;
00137    case GL_NOOP:
00138       return PIPE_LOGICOP_NOOP;
00139    case GL_OR_INVERTED:
00140       return PIPE_LOGICOP_OR_INVERTED;
00141    case GL_COPY:
00142       return PIPE_LOGICOP_COPY;
00143    case GL_OR_REVERSE:
00144       return PIPE_LOGICOP_OR_REVERSE;
00145    case GL_OR:
00146       return PIPE_LOGICOP_OR;
00147    case GL_SET:
00148       return PIPE_LOGICOP_SET;
00149    default:
00150       assert("invalid GL token in translate_logicop()" == NULL);
00151       return 0;
00152    }
00153 }

static void update_blend ( struct st_context st  )  [static]

Definition at line 157 of file st_atom_blend.c.

References pipe_blend_state::alpha_dst_factor, pipe_blend_state::alpha_func, pipe_blend_state::alpha_src_factor, st_context::blend, pipe_blend_state::blend_enable, pipe_blend_color::color, pipe_blend_state::colormask, COPY_4FV, st_context::cso_context, cso_set_blend(), cso_set_blend_color(), st_context::ctx, pipe_blend_state::dither, pipe_blend_state::logicop_enable, pipe_blend_state::logicop_func, PIPE_BLENDFACTOR_ONE, PIPE_MASK_A, PIPE_MASK_B, PIPE_MASK_G, PIPE_MASK_R, pipe_blend_state::rgb_dst_factor, pipe_blend_state::rgb_func, pipe_blend_state::rgb_src_factor, st_context::state, translate_blend(), and translate_logicop().

00158 {
00159    struct pipe_blend_state *blend = &st->state.blend;
00160 
00161    memset(blend, 0, sizeof(*blend));
00162 
00163    if (st->ctx->Color.ColorLogicOpEnabled ||
00164        (st->ctx->Color.BlendEnabled &&
00165         st->ctx->Color.BlendEquationRGB == GL_LOGIC_OP)) {
00166       /* logicop enabled */
00167       blend->logicop_enable = 1;
00168       blend->logicop_func = translate_logicop(st->ctx->Color.LogicOp);
00169    }
00170    else if (st->ctx->Color.BlendEnabled) {
00171       /* blending enabled */
00172       blend->blend_enable = 1;
00173 
00174       blend->rgb_func = translate_blend(st->ctx->Color.BlendEquationRGB);
00175       if (st->ctx->Color.BlendEquationRGB == GL_MIN ||
00176           st->ctx->Color.BlendEquationRGB == GL_MAX) {
00177          /* Min/max are special */
00178          blend->rgb_src_factor = PIPE_BLENDFACTOR_ONE;
00179          blend->rgb_dst_factor = PIPE_BLENDFACTOR_ONE;
00180       }
00181       else {
00182          blend->rgb_src_factor = translate_blend(st->ctx->Color.BlendSrcRGB);
00183          blend->rgb_dst_factor = translate_blend(st->ctx->Color.BlendDstRGB);
00184       }
00185 
00186       blend->alpha_func = translate_blend(st->ctx->Color.BlendEquationA);
00187       if (st->ctx->Color.BlendEquationA == GL_MIN ||
00188           st->ctx->Color.BlendEquationA == GL_MAX) {
00189          /* Min/max are special */
00190          blend->alpha_src_factor = PIPE_BLENDFACTOR_ONE;
00191          blend->alpha_dst_factor = PIPE_BLENDFACTOR_ONE;
00192       }
00193       else {
00194          blend->alpha_src_factor = translate_blend(st->ctx->Color.BlendSrcA);
00195          blend->alpha_dst_factor = translate_blend(st->ctx->Color.BlendDstA);
00196       }
00197    }
00198    else {
00199       /* no blending / logicop */
00200    }
00201 
00202    /* Colormask - maybe reverse these bits? */
00203    if (st->ctx->Color.ColorMask[0])
00204       blend->colormask |= PIPE_MASK_R;
00205    if (st->ctx->Color.ColorMask[1])
00206       blend->colormask |= PIPE_MASK_G;
00207    if (st->ctx->Color.ColorMask[2])
00208       blend->colormask |= PIPE_MASK_B;
00209    if (st->ctx->Color.ColorMask[3])
00210       blend->colormask |= PIPE_MASK_A;
00211 
00212    if (st->ctx->Color.DitherFlag)
00213       blend->dither = 1;
00214 
00215    cso_set_blend(st->cso_context, blend);
00216 
00217    {
00218       struct pipe_blend_color bc;
00219       COPY_4FV(bc.color, st->ctx->Color.BlendColor);
00220       cso_set_blend_color(st->cso_context, &bc);
00221    }
00222 }


Variable Documentation

struct st_tracked_state st_update_blend

Initial value:

 {
   "st_update_blend",                                   
   {                                                    
      (_NEW_COLOR),     
      0,                                                
   },
   update_blend,                                        
}

Definition at line 225 of file st_atom_blend.c.


Generated on Tue Sep 29 06:25:51 2009 for Gallium3D by  doxygen 1.5.4