removed unused var
[mesa.git] / src / mesa / main / blend.c
1 /* $Id: blend.c,v 1.25 2000/11/05 18:40:57 keithw Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
8 *
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:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
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.
25 */
26
27
28
29 #ifdef PC_HEADER
30 #include "all.h"
31 #else
32 #include "glheader.h"
33 #include "blend.h"
34 #include "context.h"
35 #include "enums.h"
36 #include "macros.h"
37 #include "types.h"
38 #endif
39
40
41 void
42 _mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
43 {
44 GET_CURRENT_CONTEXT(ctx);
45 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBlendFunc");
46
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));
51
52 switch (sfactor) {
53 case GL_SRC_COLOR:
54 case GL_ONE_MINUS_SRC_COLOR:
55 if (!ctx->Extensions.NV_blend_square) {
56 gl_error( ctx, GL_INVALID_ENUM, "glBlendFunc(sfactor)" );
57 return;
58 }
59 /* fall-through */
60 case GL_ZERO:
61 case GL_ONE:
62 case GL_DST_COLOR:
63 case GL_ONE_MINUS_DST_COLOR:
64 case GL_SRC_ALPHA:
65 case GL_ONE_MINUS_SRC_ALPHA:
66 case GL_DST_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;
74 break;
75 default:
76 gl_error( ctx, GL_INVALID_ENUM, "glBlendFunc(sfactor)" );
77 return;
78 }
79
80 switch (dfactor) {
81 case GL_DST_COLOR:
82 case GL_ONE_MINUS_DST_COLOR:
83 if (!ctx->Extensions.NV_blend_square) {
84 gl_error( ctx, GL_INVALID_ENUM, "glBlendFunc(dfactor)" );
85 return;
86 }
87 /* fall-through */
88 case GL_ZERO:
89 case GL_ONE:
90 case GL_SRC_COLOR:
91 case GL_ONE_MINUS_SRC_COLOR:
92 case GL_SRC_ALPHA:
93 case GL_ONE_MINUS_SRC_ALPHA:
94 case GL_DST_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;
101 break;
102 default:
103 gl_error( ctx, GL_INVALID_ENUM, "glBlendFunc(dfactor)" );
104 return;
105 }
106
107 if (ctx->Driver.BlendFunc) {
108 (*ctx->Driver.BlendFunc)( ctx, sfactor, dfactor );
109 }
110
111 ctx->NewState |= _NEW_COLOR;
112 }
113
114
115 /* GL_EXT_blend_func_separate */
116 void
117 _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
118 GLenum sfactorA, GLenum dfactorA )
119 {
120 GET_CURRENT_CONTEXT(ctx);
121 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBlendFuncSeparate");
122
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));
129
130 switch (sfactorRGB) {
131 case GL_SRC_COLOR:
132 case GL_ONE_MINUS_SRC_COLOR:
133 if (!ctx->Extensions.NV_blend_square) {
134 gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorRGB)");
135 return;
136 }
137 /* fall-through */
138 case GL_ZERO:
139 case GL_ONE:
140 case GL_DST_COLOR:
141 case GL_ONE_MINUS_DST_COLOR:
142 case GL_SRC_ALPHA:
143 case GL_ONE_MINUS_SRC_ALPHA:
144 case GL_DST_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;
152 break;
153 default:
154 gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorRGB)");
155 return;
156 }
157
158 switch (dfactorRGB) {
159 case GL_DST_COLOR:
160 case GL_ONE_MINUS_DST_COLOR:
161 if (!ctx->Extensions.NV_blend_square) {
162 gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(dfactorRGB)");
163 return;
164 }
165 /* fall-through */
166 case GL_ZERO:
167 case GL_ONE:
168 case GL_SRC_COLOR:
169 case GL_ONE_MINUS_SRC_COLOR:
170 case GL_SRC_ALPHA:
171 case GL_ONE_MINUS_SRC_ALPHA:
172 case GL_DST_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;
179 break;
180 default:
181 gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(dfactorRGB)");
182 return;
183 }
184
185 switch (sfactorA) {
186 case GL_SRC_COLOR:
187 case GL_ONE_MINUS_SRC_COLOR:
188 if (!ctx->Extensions.NV_blend_square) {
189 gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorA)");
190 return;
191 }
192 /* fall-through */
193 case GL_ZERO:
194 case GL_ONE:
195 case GL_DST_COLOR:
196 case GL_ONE_MINUS_DST_COLOR:
197 case GL_SRC_ALPHA:
198 case GL_ONE_MINUS_SRC_ALPHA:
199 case GL_DST_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;
207 break;
208 default:
209 gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorA)");
210 return;
211 }
212
213 switch (dfactorA) {
214 case GL_DST_COLOR:
215 case GL_ONE_MINUS_DST_COLOR:
216 if (!ctx->Extensions.NV_blend_square) {
217 gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(dfactorA)");
218 return;
219 }
220 /* fall-through */
221 case GL_ZERO:
222 case GL_ONE:
223 case GL_SRC_COLOR:
224 case GL_ONE_MINUS_SRC_COLOR:
225 case GL_SRC_ALPHA:
226 case GL_ONE_MINUS_SRC_ALPHA:
227 case GL_DST_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;
234 break;
235 default:
236 gl_error( ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(dfactorA)" );
237 return;
238 }
239
240 ctx->NewState |= _NEW_COLOR;
241
242 if (ctx->Driver.BlendFuncSeparate) {
243 (*ctx->Driver.BlendFuncSeparate)( ctx, sfactorRGB, dfactorRGB,
244 sfactorA, dfactorA );
245 }
246 }
247
248
249
250 /* This is really an extension function! */
251 void
252 _mesa_BlendEquation( GLenum mode )
253 {
254 GET_CURRENT_CONTEXT(ctx);
255 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBlendEquation");
256
257 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
258 fprintf(stderr, "glBlendEquation %s\n",
259 gl_lookup_enum_by_nr(mode));
260
261 switch (mode) {
262 case GL_MIN_EXT:
263 case GL_MAX_EXT:
264 case GL_FUNC_ADD_EXT:
265 if (ctx->Extensions.EXT_blend_minmax) {
266 ctx->Color.BlendEquation = mode;
267 }
268 else {
269 gl_error(ctx, GL_INVALID_ENUM, "glBlendEquation");
270 return;
271 }
272 case GL_LOGIC_OP:
273 ctx->Color.BlendEquation = mode;
274 break;
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;
279 }
280 else {
281 gl_error(ctx, GL_INVALID_ENUM, "glBlendEquation");
282 return;
283 }
284 break;
285 default:
286 gl_error( ctx, GL_INVALID_ENUM, "glBlendEquation" );
287 return;
288 }
289
290 /* This is needed to support 1.1's RGB logic ops AND
291 * 1.0's blending logicops.
292 */
293 if (mode==GL_LOGIC_OP && ctx->Color.BlendEnabled) {
294 ctx->Color.ColorLogicOpEnabled = GL_TRUE;
295 }
296 else {
297 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
298 }
299
300 ctx->NewState |= _NEW_COLOR;
301
302 if (ctx->Driver.BlendEquation)
303 ctx->Driver.BlendEquation( ctx, mode );
304 }
305
306
307
308 void
309 _mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
310 {
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;
317 }
318