1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
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.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "st_context.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_defines.h"
40 #include "cso_cache/cso_context.h"
44 * Convert GLenum blend tokens to pipe tokens.
45 * Both blend factors and blend funcs are accepted.
48 translate_blend(GLenum blend
)
53 return PIPE_BLEND_ADD
;
54 case GL_FUNC_SUBTRACT
:
55 return PIPE_BLEND_SUBTRACT
;
56 case GL_FUNC_REVERSE_SUBTRACT
:
57 return PIPE_BLEND_REVERSE_SUBTRACT
;
59 return PIPE_BLEND_MIN
;
61 return PIPE_BLEND_MAX
;
65 return PIPE_BLENDFACTOR_ONE
;
67 return PIPE_BLENDFACTOR_SRC_COLOR
;
69 return PIPE_BLENDFACTOR_SRC_ALPHA
;
71 return PIPE_BLENDFACTOR_DST_ALPHA
;
73 return PIPE_BLENDFACTOR_DST_COLOR
;
74 case GL_SRC_ALPHA_SATURATE
:
75 return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
;
76 case GL_CONSTANT_COLOR
:
77 return PIPE_BLENDFACTOR_CONST_COLOR
;
78 case GL_CONSTANT_ALPHA
:
79 return PIPE_BLENDFACTOR_CONST_ALPHA
;
81 return PIPE_BLENDFACTOR_SRC1_COLOR;
82 return PIPE_BLENDFACTOR_SRC1_ALPHA;
85 return PIPE_BLENDFACTOR_ZERO
;
86 case GL_ONE_MINUS_SRC_COLOR
:
87 return PIPE_BLENDFACTOR_INV_SRC_COLOR
;
88 case GL_ONE_MINUS_SRC_ALPHA
:
89 return PIPE_BLENDFACTOR_INV_SRC_ALPHA
;
90 case GL_ONE_MINUS_DST_COLOR
:
91 return PIPE_BLENDFACTOR_INV_DST_COLOR
;
92 case GL_ONE_MINUS_DST_ALPHA
:
93 return PIPE_BLENDFACTOR_INV_DST_ALPHA
;
94 case GL_ONE_MINUS_CONSTANT_COLOR
:
95 return PIPE_BLENDFACTOR_INV_CONST_COLOR
;
96 case GL_ONE_MINUS_CONSTANT_ALPHA
:
97 return PIPE_BLENDFACTOR_INV_CONST_ALPHA
;
99 return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
100 return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
103 assert("invalid GL token in translate_blend()" == NULL
);
110 * Convert GLenum logicop tokens to pipe tokens.
113 translate_logicop(GLenum logicop
)
117 return PIPE_LOGICOP_CLEAR
;
119 return PIPE_LOGICOP_NOR
;
120 case GL_AND_INVERTED
:
121 return PIPE_LOGICOP_AND_INVERTED
;
122 case GL_COPY_INVERTED
:
123 return PIPE_LOGICOP_COPY_INVERTED
;
125 return PIPE_LOGICOP_AND_REVERSE
;
127 return PIPE_LOGICOP_INVERT
;
129 return PIPE_LOGICOP_XOR
;
131 return PIPE_LOGICOP_NAND
;
133 return PIPE_LOGICOP_AND
;
135 return PIPE_LOGICOP_EQUIV
;
137 return PIPE_LOGICOP_NOOP
;
139 return PIPE_LOGICOP_OR_INVERTED
;
141 return PIPE_LOGICOP_COPY
;
143 return PIPE_LOGICOP_OR_REVERSE
;
145 return PIPE_LOGICOP_OR
;
147 return PIPE_LOGICOP_SET
;
149 assert("invalid GL token in translate_logicop()" == NULL
);
156 update_blend( struct st_context
*st
)
158 struct pipe_blend_state
*blend
= &st
->state
.blend
;
160 memset(blend
, 0, sizeof(*blend
));
162 if (st
->ctx
->Color
.ColorLogicOpEnabled
||
163 (st
->ctx
->Color
.BlendEnabled
&&
164 st
->ctx
->Color
.BlendEquationRGB
== GL_LOGIC_OP
)) {
165 /* logicop enabled */
166 blend
->logicop_enable
= 1;
167 blend
->logicop_func
= translate_logicop(st
->ctx
->Color
.LogicOp
);
169 else if (st
->ctx
->Color
.BlendEnabled
) {
170 /* blending enabled */
171 blend
->blend_enable
= 1;
173 blend
->rgb_func
= translate_blend(st
->ctx
->Color
.BlendEquationRGB
);
174 if (st
->ctx
->Color
.BlendEquationRGB
== GL_MIN
||
175 st
->ctx
->Color
.BlendEquationRGB
== GL_MAX
) {
176 /* Min/max are special */
177 blend
->rgb_src_factor
= PIPE_BLENDFACTOR_ONE
;
178 blend
->rgb_dst_factor
= PIPE_BLENDFACTOR_ONE
;
181 blend
->rgb_src_factor
= translate_blend(st
->ctx
->Color
.BlendSrcRGB
);
182 blend
->rgb_dst_factor
= translate_blend(st
->ctx
->Color
.BlendDstRGB
);
185 blend
->alpha_func
= translate_blend(st
->ctx
->Color
.BlendEquationA
);
186 if (st
->ctx
->Color
.BlendEquationA
== GL_MIN
||
187 st
->ctx
->Color
.BlendEquationA
== GL_MAX
) {
188 /* Min/max are special */
189 blend
->alpha_src_factor
= PIPE_BLENDFACTOR_ONE
;
190 blend
->alpha_dst_factor
= PIPE_BLENDFACTOR_ONE
;
193 blend
->alpha_src_factor
= translate_blend(st
->ctx
->Color
.BlendSrcA
);
194 blend
->alpha_dst_factor
= translate_blend(st
->ctx
->Color
.BlendDstA
);
198 /* no blending / logicop */
201 /* Colormask - maybe reverse these bits? */
202 if (st
->ctx
->Color
.ColorMask
[0])
203 blend
->colormask
|= PIPE_MASK_R
;
204 if (st
->ctx
->Color
.ColorMask
[1])
205 blend
->colormask
|= PIPE_MASK_G
;
206 if (st
->ctx
->Color
.ColorMask
[2])
207 blend
->colormask
|= PIPE_MASK_B
;
208 if (st
->ctx
->Color
.ColorMask
[3])
209 blend
->colormask
|= PIPE_MASK_A
;
211 if (st
->ctx
->Color
.DitherFlag
)
214 cso_set_blend(st
->cso_context
, blend
);
216 if (memcmp(st
->ctx
->Color
.BlendColor
, &st
->state
.blend_color
, 4 * sizeof(GLfloat
)) != 0) {
217 /* state has changed */
218 st
->state
.blend_color
.color
[0] = st
->ctx
->Color
.BlendColor
[0];
219 st
->state
.blend_color
.color
[1] = st
->ctx
->Color
.BlendColor
[1];
220 st
->state
.blend_color
.color
[2] = st
->ctx
->Color
.BlendColor
[2];
221 st
->state
.blend_color
.color
[3] = st
->ctx
->Color
.BlendColor
[3];
222 st
->pipe
->set_blend_color(st
->pipe
, (struct pipe_blend_color
*) st
->ctx
->Color
.BlendColor
);
227 const struct st_tracked_state st_update_blend
= {
228 .name
= "st_update_blend",
230 .mesa
= (_NEW_COLOR
), /* XXX _NEW_BLEND someday? */
233 .update
= update_blend