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"
37 #include "pipe/p_context.h"
38 #include "pipe/p_defines.h"
42 * Convert GLenum blend tokens to pipe tokens.
43 * Both blend factors and blend funcs are accepted.
46 gl_blend_to_sp(GLenum blend
)
51 return PIPE_BLEND_ADD
;
52 case GL_FUNC_SUBTRACT
:
53 return PIPE_BLEND_SUBTRACT
;
54 case GL_FUNC_REVERSE_SUBTRACT
:
55 return PIPE_BLEND_REVERSE_SUBTRACT
;
57 return PIPE_BLEND_MIN
;
59 return PIPE_BLEND_MAX
;
63 return PIPE_BLENDFACTOR_ONE
;
65 return PIPE_BLENDFACTOR_SRC_COLOR
;
67 return PIPE_BLENDFACTOR_SRC_ALPHA
;
69 return PIPE_BLENDFACTOR_DST_ALPHA
;
71 return PIPE_BLENDFACTOR_DST_COLOR
;
72 case GL_SRC_ALPHA_SATURATE
:
73 return PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
;
74 case GL_CONSTANT_COLOR
:
75 return PIPE_BLENDFACTOR_CONST_COLOR
;
76 case GL_CONSTANT_ALPHA
:
77 return PIPE_BLENDFACTOR_CONST_ALPHA
;
79 return PIPE_BLENDFACTOR_SRC1_COLOR;
80 return PIPE_BLENDFACTOR_SRC1_ALPHA;
83 return PIPE_BLENDFACTOR_ZERO
;
84 case GL_ONE_MINUS_SRC_COLOR
:
85 return PIPE_BLENDFACTOR_INV_SRC_COLOR
;
86 case GL_ONE_MINUS_SRC_ALPHA
:
87 return PIPE_BLENDFACTOR_INV_SRC_ALPHA
;
88 case GL_ONE_MINUS_DST_COLOR
:
89 return PIPE_BLENDFACTOR_INV_DST_ALPHA
;
90 case GL_ONE_MINUS_DST_ALPHA
:
91 return PIPE_BLENDFACTOR_INV_DST_COLOR
;
92 case GL_ONE_MINUS_CONSTANT_COLOR
:
93 return PIPE_BLENDFACTOR_INV_CONST_COLOR
;
94 case GL_ONE_MINUS_CONSTANT_ALPHA
:
95 return PIPE_BLENDFACTOR_INV_CONST_ALPHA
;
97 return PIPE_BLENDFACTOR_INV_SRC1_COLOR;
98 return PIPE_BLENDFACTOR_INV_SRC1_ALPHA;
101 assert("invalid GL token in gl_blend_to_sp()" == NULL
);
108 * Convert GLenum logicop tokens to pipe tokens.
111 gl_logicop_to_sp(GLenum logicop
)
115 return PIPE_LOGICOP_CLEAR
;
117 return PIPE_LOGICOP_NOR
;
118 case GL_AND_INVERTED
:
119 return PIPE_LOGICOP_AND_INVERTED
;
120 case GL_COPY_INVERTED
:
121 return PIPE_LOGICOP_COPY_INVERTED
;
123 return PIPE_LOGICOP_AND_REVERSE
;
125 return PIPE_LOGICOP_INVERT
;
127 return PIPE_LOGICOP_XOR
;
129 return PIPE_LOGICOP_NAND
;
131 return PIPE_LOGICOP_AND
;
133 return PIPE_LOGICOP_EQUIV
;
135 return PIPE_LOGICOP_NOOP
;
137 return PIPE_LOGICOP_OR_INVERTED
;
139 return PIPE_LOGICOP_COPY
;
141 return PIPE_LOGICOP_OR_REVERSE
;
143 return PIPE_LOGICOP_OR
;
145 return PIPE_LOGICOP_SET
;
147 assert("invalid GL token in gl_logicop_to_sp()" == NULL
);
154 update_blend( struct st_context
*st
)
156 struct pipe_blend_state blend
;
158 memset(&blend
, 0, sizeof(blend
));
160 if (st
->ctx
->Color
.ColorLogicOpEnabled
||
161 (st
->ctx
->Color
.BlendEnabled
&&
162 st
->ctx
->Color
.BlendEquationRGB
== GL_LOGIC_OP
)) {
163 /* logicop enabled */
164 blend
.logicop_enable
= 1;
165 blend
.logicop_func
= gl_logicop_to_sp(st
->ctx
->Color
.LogicOp
);
167 else if (st
->ctx
->Color
.BlendEnabled
) {
168 /* blending enabled */
169 blend
.blend_enable
= 1;
171 blend
.rgb_func
= gl_blend_to_sp(st
->ctx
->Color
.BlendEquationRGB
);
172 blend
.rgb_src_factor
= gl_blend_to_sp(st
->ctx
->Color
.BlendSrcRGB
);
173 blend
.rgb_dst_factor
= gl_blend_to_sp(st
->ctx
->Color
.BlendDstRGB
);
175 blend
.alpha_func
= gl_blend_to_sp(st
->ctx
->Color
.BlendEquationA
);
176 blend
.alpha_src_factor
= gl_blend_to_sp(st
->ctx
->Color
.BlendSrcA
);
177 blend
.alpha_dst_factor
= gl_blend_to_sp(st
->ctx
->Color
.BlendDstA
);
180 /* no blending / logicop */
183 if (memcmp(&blend
, &st
->state
.blend
, sizeof(blend
)) != 0) {
184 /* state has changed */
185 st
->state
.blend
= blend
; /* struct copy */
186 st
->pipe
->set_blend_state(st
->pipe
, &blend
); /* set new state */
191 const struct st_tracked_state st_update_blend
= {
193 .mesa
= (_NEW_COLOR
), /* XXX _NEW_BLEND someday? */
196 .update
= update_blend