st_atom_blend.c

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028  /*
00029   * Authors:
00030   *   Keith Whitwell <keith@tungstengraphics.com>
00031   *   Brian Paul
00032   */
00033  
00034 
00035 #include "st_context.h"
00036 #include "st_atom.h"
00037 
00038 #include "pipe/p_context.h"
00039 #include "pipe/p_defines.h"
00040 #include "cso_cache/cso_context.h"
00041 
00042 #include "main/macros.h"
00043 
00048 static GLuint
00049 translate_blend(GLenum blend)
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 }
00108 
00109 
00113 static GLuint
00114 translate_logicop(GLenum logicop)
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 }
00154 
00155 
00156 static void 
00157 update_blend( struct st_context *st )
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 }
00223 
00224 
00225 const struct st_tracked_state st_update_blend = {
00226    "st_update_blend",                                   /* name */
00227    {                                                    /* dirty */
00228       (_NEW_COLOR),  /* XXX _NEW_BLEND someday? */      /* mesa */
00229       0,                                                /* st */
00230    },
00231    update_blend,                                        /* update */
00232 };

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