Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 3 | * Copyright 2007 VMware, Inc. |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the |
| 8 | * "Software"), to deal in the Software without restriction, including |
| 9 | * without limitation the rights to use, copy, modify, merge, publish, |
| 10 | * distribute, sub license, and/or sell copies of the Software, and to |
| 11 | * permit persons to whom the Software is furnished to do so, subject to |
| 12 | * the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the |
| 15 | * next paragraph) shall be included in all copies or substantial portions |
| 16 | * of the Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 19 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 20 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 21 | * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 22 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
| 23 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 24 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | **************************************************************************/ |
| 27 | |
| 28 | /* |
| 29 | * Authors: |
José Fonseca | 8771285 | 2014-01-17 16:27:50 +0000 | [diff] [blame] | 30 | * Keith Whitwell <keithw@vmware.com> |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 31 | * Brian Paul |
| 32 | */ |
| 33 | |
| 34 | |
| 35 | #include "st_context.h" |
| 36 | #include "st_atom.h" |
Zack Rusin | e16c045 | 2007-09-17 07:56:56 -0400 | [diff] [blame] | 37 | |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 38 | #include "pipe/p_context.h" |
| 39 | #include "pipe/p_defines.h" |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 40 | #include "cso_cache/cso_context.h" |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 41 | |
Brian | 7d95efd | 2008-03-19 11:12:48 -0600 | [diff] [blame] | 42 | #include "main/macros.h" |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 43 | |
| 44 | /** |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 45 | * Convert GLenum blend tokens to pipe tokens. |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 46 | * Both blend factors and blend funcs are accepted. |
| 47 | */ |
| 48 | static GLuint |
Brian | ce0f2e8 | 2007-10-16 08:53:08 -0600 | [diff] [blame] | 49 | translate_blend(GLenum blend) |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 50 | { |
| 51 | switch (blend) { |
| 52 | /* blend functions */ |
| 53 | case GL_FUNC_ADD: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 54 | return PIPE_BLEND_ADD; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 55 | case GL_FUNC_SUBTRACT: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 56 | return PIPE_BLEND_SUBTRACT; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 57 | case GL_FUNC_REVERSE_SUBTRACT: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 58 | return PIPE_BLEND_REVERSE_SUBTRACT; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 59 | case GL_MIN: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 60 | return PIPE_BLEND_MIN; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 61 | case GL_MAX: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 62 | return PIPE_BLEND_MAX; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 63 | |
| 64 | /* blend factors */ |
| 65 | case GL_ONE: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 66 | return PIPE_BLENDFACTOR_ONE; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 67 | case GL_SRC_COLOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 68 | return PIPE_BLENDFACTOR_SRC_COLOR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 69 | case GL_SRC_ALPHA: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 70 | return PIPE_BLENDFACTOR_SRC_ALPHA; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 71 | case GL_DST_ALPHA: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 72 | return PIPE_BLENDFACTOR_DST_ALPHA; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 73 | case GL_DST_COLOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 74 | return PIPE_BLENDFACTOR_DST_COLOR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 75 | case GL_SRC_ALPHA_SATURATE: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 76 | return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 77 | case GL_CONSTANT_COLOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 78 | return PIPE_BLENDFACTOR_CONST_COLOR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 79 | case GL_CONSTANT_ALPHA: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 80 | return PIPE_BLENDFACTOR_CONST_ALPHA; |
Dave Airlie | a21df96 | 2012-03-24 13:36:17 +0000 | [diff] [blame] | 81 | case GL_SRC1_COLOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 82 | return PIPE_BLENDFACTOR_SRC1_COLOR; |
Dave Airlie | a21df96 | 2012-03-24 13:36:17 +0000 | [diff] [blame] | 83 | case GL_SRC1_ALPHA: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 84 | return PIPE_BLENDFACTOR_SRC1_ALPHA; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 85 | case GL_ZERO: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 86 | return PIPE_BLENDFACTOR_ZERO; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 87 | case GL_ONE_MINUS_SRC_COLOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 88 | return PIPE_BLENDFACTOR_INV_SRC_COLOR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 89 | case GL_ONE_MINUS_SRC_ALPHA: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 90 | return PIPE_BLENDFACTOR_INV_SRC_ALPHA; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 91 | case GL_ONE_MINUS_DST_COLOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 92 | return PIPE_BLENDFACTOR_INV_DST_COLOR; |
Brian | ce0f2e8 | 2007-10-16 08:53:08 -0600 | [diff] [blame] | 93 | case GL_ONE_MINUS_DST_ALPHA: |
| 94 | return PIPE_BLENDFACTOR_INV_DST_ALPHA; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 95 | case GL_ONE_MINUS_CONSTANT_COLOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 96 | return PIPE_BLENDFACTOR_INV_CONST_COLOR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 97 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 98 | return PIPE_BLENDFACTOR_INV_CONST_ALPHA; |
Dave Airlie | a21df96 | 2012-03-24 13:36:17 +0000 | [diff] [blame] | 99 | case GL_ONE_MINUS_SRC1_COLOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 100 | return PIPE_BLENDFACTOR_INV_SRC1_COLOR; |
Dave Airlie | a21df96 | 2012-03-24 13:36:17 +0000 | [diff] [blame] | 101 | case GL_ONE_MINUS_SRC1_ALPHA: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 102 | return PIPE_BLENDFACTOR_INV_SRC1_ALPHA; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 103 | default: |
Brian | ce0f2e8 | 2007-10-16 08:53:08 -0600 | [diff] [blame] | 104 | assert("invalid GL token in translate_blend()" == NULL); |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 105 | return 0; |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | |
| 110 | /** |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 111 | * Convert GLenum logicop tokens to pipe tokens. |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 112 | */ |
| 113 | static GLuint |
Brian | ce0f2e8 | 2007-10-16 08:53:08 -0600 | [diff] [blame] | 114 | translate_logicop(GLenum logicop) |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 115 | { |
| 116 | switch (logicop) { |
| 117 | case GL_CLEAR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 118 | return PIPE_LOGICOP_CLEAR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 119 | case GL_NOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 120 | return PIPE_LOGICOP_NOR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 121 | case GL_AND_INVERTED: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 122 | return PIPE_LOGICOP_AND_INVERTED; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 123 | case GL_COPY_INVERTED: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 124 | return PIPE_LOGICOP_COPY_INVERTED; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 125 | case GL_AND_REVERSE: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 126 | return PIPE_LOGICOP_AND_REVERSE; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 127 | case GL_INVERT: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 128 | return PIPE_LOGICOP_INVERT; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 129 | case GL_XOR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 130 | return PIPE_LOGICOP_XOR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 131 | case GL_NAND: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 132 | return PIPE_LOGICOP_NAND; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 133 | case GL_AND: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 134 | return PIPE_LOGICOP_AND; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 135 | case GL_EQUIV: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 136 | return PIPE_LOGICOP_EQUIV; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 137 | case GL_NOOP: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 138 | return PIPE_LOGICOP_NOOP; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 139 | case GL_OR_INVERTED: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 140 | return PIPE_LOGICOP_OR_INVERTED; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 141 | case GL_COPY: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 142 | return PIPE_LOGICOP_COPY; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 143 | case GL_OR_REVERSE: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 144 | return PIPE_LOGICOP_OR_REVERSE; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 145 | case GL_OR: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 146 | return PIPE_LOGICOP_OR; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 147 | case GL_SET: |
Keith Whitwell | 943964a | 2007-06-14 18:23:43 +0100 | [diff] [blame] | 148 | return PIPE_LOGICOP_SET; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 149 | default: |
Brian | ce0f2e8 | 2007-10-16 08:53:08 -0600 | [diff] [blame] | 150 | assert("invalid GL token in translate_logicop()" == NULL); |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 151 | return 0; |
| 152 | } |
| 153 | } |
| 154 | |
Roland Scheidegger | 9bc80ff | 2010-01-26 15:35:31 +0100 | [diff] [blame] | 155 | /** |
| 156 | * Figure out if colormasks are different per rt. |
| 157 | */ |
| 158 | static GLboolean |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 159 | colormask_per_rt(const struct gl_context *ctx) |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 160 | { |
Roland Scheidegger | 9bc80ff | 2010-01-26 15:35:31 +0100 | [diff] [blame] | 161 | /* a bit suboptimal have to compare lots of values */ |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 162 | unsigned i; |
| 163 | for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) { |
Roland Scheidegger | 9bc80ff | 2010-01-26 15:35:31 +0100 | [diff] [blame] | 164 | if (memcmp(ctx->Color.ColorMask[0], ctx->Color.ColorMask[i], 4)) { |
| 165 | return GL_TRUE; |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 166 | } |
| 167 | } |
Roland Scheidegger | 9bc80ff | 2010-01-26 15:35:31 +0100 | [diff] [blame] | 168 | return GL_FALSE; |
| 169 | } |
| 170 | |
| 171 | /** |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 172 | * Figure out if blend enables/state are different per rt. |
Roland Scheidegger | 9bc80ff | 2010-01-26 15:35:31 +0100 | [diff] [blame] | 173 | */ |
| 174 | static GLboolean |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 175 | blend_per_rt(const struct gl_context *ctx) |
Roland Scheidegger | 9bc80ff | 2010-01-26 15:35:31 +0100 | [diff] [blame] | 176 | { |
| 177 | if (ctx->Color.BlendEnabled && |
Jan Vesely | 3cb10cc | 2015-01-15 13:41:04 -0500 | [diff] [blame] | 178 | (ctx->Color.BlendEnabled != ((1U << ctx->Const.MaxDrawBuffers) - 1))) { |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 179 | /* This can only happen if GL_EXT_draw_buffers2 is enabled */ |
| 180 | return GL_TRUE; |
| 181 | } |
| 182 | if (ctx->Color._BlendFuncPerBuffer || ctx->Color._BlendEquationPerBuffer) { |
| 183 | /* this can only happen if GL_ARB_draw_buffers_blend is enabled */ |
Roland Scheidegger | 9bc80ff | 2010-01-26 15:35:31 +0100 | [diff] [blame] | 184 | return GL_TRUE; |
| 185 | } |
| 186 | return GL_FALSE; |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 187 | } |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 188 | |
| 189 | static void |
| 190 | update_blend( struct st_context *st ) |
| 191 | { |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 192 | struct pipe_blend_state *blend = &st->state.blend; |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 193 | const struct gl_context *ctx = st->ctx; |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 194 | unsigned num_state = 1; |
Fabian Bieler | a476ca1 | 2011-02-10 16:45:41 +0100 | [diff] [blame] | 195 | unsigned i, j; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 196 | |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 197 | memset(blend, 0, sizeof(*blend)); |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 198 | |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 199 | if (blend_per_rt(ctx) || colormask_per_rt(ctx)) { |
| 200 | num_state = ctx->Const.MaxDrawBuffers; |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 201 | blend->independent_blend_enable = 1; |
| 202 | } |
Ian Romanick | 3538bff | 2011-09-09 14:07:54 -0700 | [diff] [blame] | 203 | if (ctx->Color.ColorLogicOpEnabled) { |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 204 | /* logicop enabled */ |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 205 | blend->logicop_enable = 1; |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 206 | blend->logicop_func = translate_logicop(ctx->Color.LogicOp); |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 207 | } |
Ilia Mirkin | 6b7511c | 2017-01-01 23:47:25 -0500 | [diff] [blame] | 208 | else if (ctx->Color.BlendEnabled && !ctx->Color._AdvancedBlendMode) { |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 209 | /* blending enabled */ |
Fabian Bieler | a476ca1 | 2011-02-10 16:45:41 +0100 | [diff] [blame] | 210 | for (i = 0, j = 0; i < num_state; i++) { |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 211 | |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 212 | blend->rt[i].blend_enable = (ctx->Color.BlendEnabled >> i) & 0x1; |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 213 | |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 214 | if (ctx->Extensions.ARB_draw_buffers_blend) |
Fabian Bieler | a476ca1 | 2011-02-10 16:45:41 +0100 | [diff] [blame] | 215 | j = i; |
| 216 | |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 217 | blend->rt[i].rgb_func = |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 218 | translate_blend(ctx->Color.Blend[j].EquationRGB); |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 219 | |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 220 | if (ctx->Color.Blend[i].EquationRGB == GL_MIN || |
| 221 | ctx->Color.Blend[i].EquationRGB == GL_MAX) { |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 222 | /* Min/max are special */ |
| 223 | blend->rt[i].rgb_src_factor = PIPE_BLENDFACTOR_ONE; |
| 224 | blend->rt[i].rgb_dst_factor = PIPE_BLENDFACTOR_ONE; |
| 225 | } |
| 226 | else { |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 227 | blend->rt[i].rgb_src_factor = |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 228 | translate_blend(ctx->Color.Blend[j].SrcRGB); |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 229 | blend->rt[i].rgb_dst_factor = |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 230 | translate_blend(ctx->Color.Blend[j].DstRGB); |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 231 | } |
| 232 | |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 233 | blend->rt[i].alpha_func = |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 234 | translate_blend(ctx->Color.Blend[j].EquationA); |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 235 | |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 236 | if (ctx->Color.Blend[i].EquationA == GL_MIN || |
| 237 | ctx->Color.Blend[i].EquationA == GL_MAX) { |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 238 | /* Min/max are special */ |
| 239 | blend->rt[i].alpha_src_factor = PIPE_BLENDFACTOR_ONE; |
| 240 | blend->rt[i].alpha_dst_factor = PIPE_BLENDFACTOR_ONE; |
| 241 | } |
| 242 | else { |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 243 | blend->rt[i].alpha_src_factor = |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 244 | translate_blend(ctx->Color.Blend[j].SrcA); |
Brian Paul | 74713e2 | 2011-01-11 15:07:38 -0700 | [diff] [blame] | 245 | blend->rt[i].alpha_dst_factor = |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 246 | translate_blend(ctx->Color.Blend[j].DstA); |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 247 | } |
Brian | 1118807 | 2007-07-03 17:13:04 -0600 | [diff] [blame] | 248 | } |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 249 | } |
| 250 | else { |
| 251 | /* no blending / logicop */ |
| 252 | } |
| 253 | |
Brian | 86352ff | 2007-07-12 12:20:14 -0600 | [diff] [blame] | 254 | /* Colormask - maybe reverse these bits? */ |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 255 | for (i = 0; i < num_state; i++) { |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 256 | if (ctx->Color.ColorMask[i][0]) |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 257 | blend->rt[i].colormask |= PIPE_MASK_R; |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 258 | if (ctx->Color.ColorMask[i][1]) |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 259 | blend->rt[i].colormask |= PIPE_MASK_G; |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 260 | if (ctx->Color.ColorMask[i][2]) |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 261 | blend->rt[i].colormask |= PIPE_MASK_B; |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 262 | if (ctx->Color.ColorMask[i][3]) |
Roland Scheidegger | 5fae361 | 2010-01-25 19:27:05 +0100 | [diff] [blame] | 263 | blend->rt[i].colormask |= PIPE_MASK_A; |
| 264 | } |
Brian | 86352ff | 2007-07-12 12:20:14 -0600 | [diff] [blame] | 265 | |
Brian Paul | 971122a | 2014-07-03 12:02:16 -0600 | [diff] [blame] | 266 | blend->dither = ctx->Color.DitherFlag; |
Brian | 86352ff | 2007-07-12 12:20:14 -0600 | [diff] [blame] | 267 | |
Brian Paul | a01872f | 2016-09-15 15:13:07 -0600 | [diff] [blame] | 268 | if (ctx->Multisample.Enabled && |
Marek Olšák | 54f8efe | 2016-09-16 22:39:15 +0200 | [diff] [blame] | 269 | ctx->DrawBuffer->Visual.sampleBuffers > 0 && |
| 270 | !(ctx->DrawBuffer->_IntegerBuffers & 0x1)) { |
Brian Paul | a01872f | 2016-09-15 15:13:07 -0600 | [diff] [blame] | 271 | /* Unlike in gallium/d3d10 these operations are only performed |
| 272 | * if both msaa is enabled and we have a multisample buffer. |
| 273 | */ |
Brian Paul | 971122a | 2014-07-03 12:02:16 -0600 | [diff] [blame] | 274 | blend->alpha_to_coverage = ctx->Multisample.SampleAlphaToCoverage; |
| 275 | blend->alpha_to_one = ctx->Multisample.SampleAlphaToOne; |
Roland Scheidegger | 127328b | 2010-05-17 21:19:03 +0200 | [diff] [blame] | 276 | } |
| 277 | |
Brian | 339e7ec | 2008-03-11 18:54:31 -0600 | [diff] [blame] | 278 | cso_set_blend(st->cso_context, blend); |
Brian | 284efcf | 2007-07-03 17:19:30 -0600 | [diff] [blame] | 279 | |
Brian | 7d95efd | 2008-03-19 11:12:48 -0600 | [diff] [blame] | 280 | { |
| 281 | struct pipe_blend_color bc; |
Brian Paul | 99feecc | 2011-06-14 09:15:36 -0600 | [diff] [blame] | 282 | COPY_4FV(bc.color, ctx->Color.BlendColorUnclamped); |
Brian | 7d95efd | 2008-03-19 11:12:48 -0600 | [diff] [blame] | 283 | cso_set_blend_color(st->cso_context, &bc); |
Brian | 284efcf | 2007-07-03 17:19:30 -0600 | [diff] [blame] | 284 | } |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | |
| 288 | const struct st_tracked_state st_update_blend = { |
Alan Hourihane | 5450712 | 2008-05-02 10:08:03 +0000 | [diff] [blame] | 289 | update_blend, /* update */ |
Brian | 6debc80 | 2007-05-24 16:50:22 -0600 | [diff] [blame] | 290 | }; |