1 /* $Id: blend.c,v 1.25 2000/11/05 18:40:57 keithw Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 _mesa_BlendFunc( GLenum sfactor
, GLenum dfactor
)
44 GET_CURRENT_CONTEXT(ctx
);
45 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glBlendFunc");
47 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
48 fprintf(stderr
, "glBlendFunc %s %s\n",
49 gl_lookup_enum_by_nr(sfactor
),
50 gl_lookup_enum_by_nr(dfactor
));
54 case GL_ONE_MINUS_SRC_COLOR
:
55 if (!ctx
->Extensions
.NV_blend_square
) {
56 gl_error( ctx
, GL_INVALID_ENUM
, "glBlendFunc(sfactor)" );
63 case GL_ONE_MINUS_DST_COLOR
:
65 case GL_ONE_MINUS_SRC_ALPHA
:
67 case GL_ONE_MINUS_DST_ALPHA
:
68 case GL_SRC_ALPHA_SATURATE
:
69 case GL_CONSTANT_COLOR
:
70 case GL_ONE_MINUS_CONSTANT_COLOR
:
71 case GL_CONSTANT_ALPHA
:
72 case GL_ONE_MINUS_CONSTANT_ALPHA
:
73 ctx
->Color
.BlendSrcRGB
= ctx
->Color
.BlendSrcA
= sfactor
;
76 gl_error( ctx
, GL_INVALID_ENUM
, "glBlendFunc(sfactor)" );
82 case GL_ONE_MINUS_DST_COLOR
:
83 if (!ctx
->Extensions
.NV_blend_square
) {
84 gl_error( ctx
, GL_INVALID_ENUM
, "glBlendFunc(dfactor)" );
91 case GL_ONE_MINUS_SRC_COLOR
:
93 case GL_ONE_MINUS_SRC_ALPHA
:
95 case GL_ONE_MINUS_DST_ALPHA
:
96 case GL_CONSTANT_COLOR
:
97 case GL_ONE_MINUS_CONSTANT_COLOR
:
98 case GL_CONSTANT_ALPHA
:
99 case GL_ONE_MINUS_CONSTANT_ALPHA
:
100 ctx
->Color
.BlendDstRGB
= ctx
->Color
.BlendDstA
= dfactor
;
103 gl_error( ctx
, GL_INVALID_ENUM
, "glBlendFunc(dfactor)" );
107 if (ctx
->Driver
.BlendFunc
) {
108 (*ctx
->Driver
.BlendFunc
)( ctx
, sfactor
, dfactor
);
111 ctx
->NewState
|= _NEW_COLOR
;
115 /* GL_EXT_blend_func_separate */
117 _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB
, GLenum dfactorRGB
,
118 GLenum sfactorA
, GLenum dfactorA
)
120 GET_CURRENT_CONTEXT(ctx
);
121 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glBlendFuncSeparate");
123 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
124 fprintf(stderr
, "glBlendFuncSeperate %s %s %s %s\n",
125 gl_lookup_enum_by_nr(sfactorRGB
),
126 gl_lookup_enum_by_nr(dfactorRGB
),
127 gl_lookup_enum_by_nr(sfactorA
),
128 gl_lookup_enum_by_nr(dfactorA
));
130 switch (sfactorRGB
) {
132 case GL_ONE_MINUS_SRC_COLOR
:
133 if (!ctx
->Extensions
.NV_blend_square
) {
134 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendFuncSeparate(sfactorRGB)");
141 case GL_ONE_MINUS_DST_COLOR
:
143 case GL_ONE_MINUS_SRC_ALPHA
:
145 case GL_ONE_MINUS_DST_ALPHA
:
146 case GL_SRC_ALPHA_SATURATE
:
147 case GL_CONSTANT_COLOR
:
148 case GL_ONE_MINUS_CONSTANT_COLOR
:
149 case GL_CONSTANT_ALPHA
:
150 case GL_ONE_MINUS_CONSTANT_ALPHA
:
151 ctx
->Color
.BlendSrcRGB
= sfactorRGB
;
154 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendFuncSeparate(sfactorRGB)");
158 switch (dfactorRGB
) {
160 case GL_ONE_MINUS_DST_COLOR
:
161 if (!ctx
->Extensions
.NV_blend_square
) {
162 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendFuncSeparate(dfactorRGB)");
169 case GL_ONE_MINUS_SRC_COLOR
:
171 case GL_ONE_MINUS_SRC_ALPHA
:
173 case GL_ONE_MINUS_DST_ALPHA
:
174 case GL_CONSTANT_COLOR
:
175 case GL_ONE_MINUS_CONSTANT_COLOR
:
176 case GL_CONSTANT_ALPHA
:
177 case GL_ONE_MINUS_CONSTANT_ALPHA
:
178 ctx
->Color
.BlendDstRGB
= dfactorRGB
;
181 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendFuncSeparate(dfactorRGB)");
187 case GL_ONE_MINUS_SRC_COLOR
:
188 if (!ctx
->Extensions
.NV_blend_square
) {
189 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendFuncSeparate(sfactorA)");
196 case GL_ONE_MINUS_DST_COLOR
:
198 case GL_ONE_MINUS_SRC_ALPHA
:
200 case GL_ONE_MINUS_DST_ALPHA
:
201 case GL_SRC_ALPHA_SATURATE
:
202 case GL_CONSTANT_COLOR
:
203 case GL_ONE_MINUS_CONSTANT_COLOR
:
204 case GL_CONSTANT_ALPHA
:
205 case GL_ONE_MINUS_CONSTANT_ALPHA
:
206 ctx
->Color
.BlendSrcA
= sfactorA
;
209 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendFuncSeparate(sfactorA)");
215 case GL_ONE_MINUS_DST_COLOR
:
216 if (!ctx
->Extensions
.NV_blend_square
) {
217 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendFuncSeparate(dfactorA)");
224 case GL_ONE_MINUS_SRC_COLOR
:
226 case GL_ONE_MINUS_SRC_ALPHA
:
228 case GL_ONE_MINUS_DST_ALPHA
:
229 case GL_CONSTANT_COLOR
:
230 case GL_ONE_MINUS_CONSTANT_COLOR
:
231 case GL_CONSTANT_ALPHA
:
232 case GL_ONE_MINUS_CONSTANT_ALPHA
:
233 ctx
->Color
.BlendDstA
= dfactorA
;
236 gl_error( ctx
, GL_INVALID_ENUM
, "glBlendFuncSeparate(dfactorA)" );
240 ctx
->NewState
|= _NEW_COLOR
;
242 if (ctx
->Driver
.BlendFuncSeparate
) {
243 (*ctx
->Driver
.BlendFuncSeparate
)( ctx
, sfactorRGB
, dfactorRGB
,
244 sfactorA
, dfactorA
);
250 /* This is really an extension function! */
252 _mesa_BlendEquation( GLenum mode
)
254 GET_CURRENT_CONTEXT(ctx
);
255 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
, "glBlendEquation");
257 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
258 fprintf(stderr
, "glBlendEquation %s\n",
259 gl_lookup_enum_by_nr(mode
));
264 case GL_FUNC_ADD_EXT
:
265 if (ctx
->Extensions
.EXT_blend_minmax
) {
266 ctx
->Color
.BlendEquation
= mode
;
269 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
273 ctx
->Color
.BlendEquation
= mode
;
275 case GL_FUNC_SUBTRACT_EXT
:
276 case GL_FUNC_REVERSE_SUBTRACT_EXT
:
277 if (ctx
->Extensions
.EXT_blend_subtract
) {
278 ctx
->Color
.BlendEquation
= mode
;
281 gl_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
286 gl_error( ctx
, GL_INVALID_ENUM
, "glBlendEquation" );
290 /* This is needed to support 1.1's RGB logic ops AND
291 * 1.0's blending logicops.
293 if (mode
==GL_LOGIC_OP
&& ctx
->Color
.BlendEnabled
) {
294 ctx
->Color
.ColorLogicOpEnabled
= GL_TRUE
;
297 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
300 ctx
->NewState
|= _NEW_COLOR
;
302 if (ctx
->Driver
.BlendEquation
)
303 ctx
->Driver
.BlendEquation( ctx
, mode
);
309 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
311 GET_CURRENT_CONTEXT(ctx
);
312 ctx
->Color
.BlendColor
[0] = CLAMP( red
, 0.0F
, 1.0F
);
313 ctx
->Color
.BlendColor
[1] = CLAMP( green
, 0.0F
, 1.0F
);
314 ctx
->Color
.BlendColor
[2] = CLAMP( blue
, 0.0F
, 1.0F
);
315 ctx
->Color
.BlendColor
[3] = CLAMP( alpha
, 0.0F
, 1.0F
);
316 ctx
->NewState
|= _NEW_COLOR
;