mesa: Remove support for GL_EXT_blend_logic_op
[mesa.git] / src / mesa / main / blend.c
1 /**
2 * \file blend.c
3 * Blending operations.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 * Version: 6.5.1
9 *
10 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30
31
32 #include "glheader.h"
33 #include "blend.h"
34 #include "context.h"
35 #include "enums.h"
36 #include "macros.h"
37 #include "mtypes.h"
38
39
40
41 /**
42 * Check if given blend source factor is legal.
43 * \return GL_TRUE if legal, GL_FALSE otherwise.
44 */
45 static GLboolean
46 legal_src_factor(const struct gl_context *ctx, GLenum factor)
47 {
48 switch (factor) {
49 case GL_SRC_COLOR:
50 case GL_ONE_MINUS_SRC_COLOR:
51 return ctx->Extensions.NV_blend_square;
52 case GL_ZERO:
53 case GL_ONE:
54 case GL_DST_COLOR:
55 case GL_ONE_MINUS_DST_COLOR:
56 case GL_SRC_ALPHA:
57 case GL_ONE_MINUS_SRC_ALPHA:
58 case GL_DST_ALPHA:
59 case GL_ONE_MINUS_DST_ALPHA:
60 case GL_SRC_ALPHA_SATURATE:
61 case GL_CONSTANT_COLOR:
62 case GL_ONE_MINUS_CONSTANT_COLOR:
63 case GL_CONSTANT_ALPHA:
64 case GL_ONE_MINUS_CONSTANT_ALPHA:
65 return GL_TRUE;
66 default:
67 return GL_FALSE;
68 }
69 }
70
71
72 /**
73 * Check if given blend destination factor is legal.
74 * \return GL_TRUE if legal, GL_FALSE otherwise.
75 */
76 static GLboolean
77 legal_dst_factor(const struct gl_context *ctx, GLenum factor)
78 {
79 switch (factor) {
80 case GL_DST_COLOR:
81 case GL_ONE_MINUS_DST_COLOR:
82 return ctx->Extensions.NV_blend_square;
83 case GL_ZERO:
84 case GL_ONE:
85 case GL_SRC_COLOR:
86 case GL_ONE_MINUS_SRC_COLOR:
87 case GL_SRC_ALPHA:
88 case GL_ONE_MINUS_SRC_ALPHA:
89 case GL_DST_ALPHA:
90 case GL_ONE_MINUS_DST_ALPHA:
91 case GL_CONSTANT_COLOR:
92 case GL_ONE_MINUS_CONSTANT_COLOR:
93 case GL_CONSTANT_ALPHA:
94 case GL_ONE_MINUS_CONSTANT_ALPHA:
95 return GL_TRUE;
96 default:
97 return GL_FALSE;
98 }
99 }
100
101
102 /**
103 * Check if src/dest RGB/A blend factors are legal. If not generate
104 * a GL error.
105 * \return GL_TRUE if factors are legal, GL_FALSE otherwise.
106 */
107 static GLboolean
108 validate_blend_factors(struct gl_context *ctx, const char *func,
109 GLenum sfactorRGB, GLenum dfactorRGB,
110 GLenum sfactorA, GLenum dfactorA)
111 {
112 if (!legal_src_factor(ctx, sfactorRGB)) {
113 _mesa_error(ctx, GL_INVALID_ENUM,
114 "%s(sfactorRGB = %s)", func,
115 _mesa_lookup_enum_by_nr(sfactorRGB));
116 return GL_FALSE;
117 }
118
119 if (!legal_dst_factor(ctx, dfactorRGB)) {
120 _mesa_error(ctx, GL_INVALID_ENUM,
121 "%s(dfactorRGB = %s)", func,
122 _mesa_lookup_enum_by_nr(dfactorRGB));
123 return GL_FALSE;
124 }
125
126 if (sfactorA != sfactorRGB && !legal_src_factor(ctx, sfactorA)) {
127 _mesa_error(ctx, GL_INVALID_ENUM,
128 "%s(sfactorA = %s)", func,
129 _mesa_lookup_enum_by_nr(sfactorA));
130 return GL_FALSE;
131 }
132
133 if (dfactorA != dfactorRGB && !legal_dst_factor(ctx, dfactorA)) {
134 _mesa_error(ctx, GL_INVALID_ENUM,
135 "%s(dfactorA = %s)", func,
136 _mesa_lookup_enum_by_nr(dfactorA));
137 return GL_FALSE;
138 }
139
140 return GL_TRUE;
141 }
142
143
144 /**
145 * Specify the blending operation.
146 *
147 * \param sfactor source factor operator.
148 * \param dfactor destination factor operator.
149 *
150 * \sa glBlendFunc, glBlendFuncSeparateEXT
151 */
152 void GLAPIENTRY
153 _mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
154 {
155 _mesa_BlendFuncSeparateEXT(sfactor, dfactor, sfactor, dfactor);
156 }
157
158
159 /**
160 * Set the separate blend source/dest factors for all draw buffers.
161 *
162 * \param sfactorRGB RGB source factor operator.
163 * \param dfactorRGB RGB destination factor operator.
164 * \param sfactorA alpha source factor operator.
165 * \param dfactorA alpha destination factor operator.
166 */
167 void GLAPIENTRY
168 _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
169 GLenum sfactorA, GLenum dfactorA )
170 {
171 GLuint buf, numBuffers;
172 GLboolean changed;
173 GET_CURRENT_CONTEXT(ctx);
174 ASSERT_OUTSIDE_BEGIN_END(ctx);
175
176 if (MESA_VERBOSE & VERBOSE_API)
177 _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n",
178 _mesa_lookup_enum_by_nr(sfactorRGB),
179 _mesa_lookup_enum_by_nr(dfactorRGB),
180 _mesa_lookup_enum_by_nr(sfactorA),
181 _mesa_lookup_enum_by_nr(dfactorA));
182
183 if (!validate_blend_factors(ctx, "glBlendFuncSeparate",
184 sfactorRGB, dfactorRGB,
185 sfactorA, dfactorA)) {
186 return;
187 }
188
189 numBuffers = ctx->Extensions.ARB_draw_buffers_blend
190 ? ctx->Const.MaxDrawBuffers : 1;
191
192 changed = GL_FALSE;
193 for (buf = 0; buf < numBuffers; buf++) {
194 if (ctx->Color.Blend[buf].SrcRGB != sfactorRGB ||
195 ctx->Color.Blend[buf].DstRGB != dfactorRGB ||
196 ctx->Color.Blend[buf].SrcA != sfactorA ||
197 ctx->Color.Blend[buf].DstA != dfactorA) {
198 changed = GL_TRUE;
199 break;
200 }
201 }
202 if (!changed)
203 return;
204
205 FLUSH_VERTICES(ctx, _NEW_COLOR);
206
207 for (buf = 0; buf < numBuffers; buf++) {
208 ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
209 ctx->Color.Blend[buf].DstRGB = dfactorRGB;
210 ctx->Color.Blend[buf].SrcA = sfactorA;
211 ctx->Color.Blend[buf].DstA = dfactorA;
212 }
213 ctx->Color._BlendFuncPerBuffer = GL_FALSE;
214
215 if (ctx->Driver.BlendFuncSeparate) {
216 ctx->Driver.BlendFuncSeparate(ctx, sfactorRGB, dfactorRGB,
217 sfactorA, dfactorA);
218 }
219 }
220
221
222 #if _HAVE_FULL_GL
223
224
225 /**
226 * Set blend source/dest factors for one color buffer/target.
227 */
228 void GLAPIENTRY
229 _mesa_BlendFunci(GLuint buf, GLenum sfactor, GLenum dfactor)
230 {
231 _mesa_BlendFuncSeparatei(buf, sfactor, dfactor, sfactor, dfactor);
232 }
233
234
235 /**
236 * Set separate blend source/dest factors for one color buffer/target.
237 */
238 void GLAPIENTRY
239 _mesa_BlendFuncSeparatei(GLuint buf, GLenum sfactorRGB, GLenum dfactorRGB,
240 GLenum sfactorA, GLenum dfactorA)
241 {
242 GET_CURRENT_CONTEXT(ctx);
243 ASSERT_OUTSIDE_BEGIN_END(ctx);
244
245 if (!ctx->Extensions.ARB_draw_buffers_blend) {
246 _mesa_error(ctx, GL_INVALID_OPERATION, "glBlendFunc[Separate]i()");
247 return;
248 }
249
250 if (buf >= ctx->Const.MaxDrawBuffers) {
251 _mesa_error(ctx, GL_INVALID_VALUE, "glBlendFuncSeparatei(buffer=%u)",
252 buf);
253 return;
254 }
255
256 if (!validate_blend_factors(ctx, "glBlendFuncSeparatei",
257 sfactorRGB, dfactorRGB,
258 sfactorA, dfactorA)) {
259 return;
260 }
261
262 if (ctx->Color.Blend[buf].SrcRGB == sfactorRGB &&
263 ctx->Color.Blend[buf].DstRGB == dfactorRGB &&
264 ctx->Color.Blend[buf].SrcA == sfactorA &&
265 ctx->Color.Blend[buf].DstA == dfactorA)
266 return; /* no change */
267
268 FLUSH_VERTICES(ctx, _NEW_COLOR);
269
270 ctx->Color.Blend[buf].SrcRGB = sfactorRGB;
271 ctx->Color.Blend[buf].DstRGB = dfactorRGB;
272 ctx->Color.Blend[buf].SrcA = sfactorA;
273 ctx->Color.Blend[buf].DstA = dfactorA;
274 ctx->Color._BlendFuncPerBuffer = GL_TRUE;
275
276 if (ctx->Driver.BlendFuncSeparatei) {
277 ctx->Driver.BlendFuncSeparatei(ctx, buf, sfactorRGB, dfactorRGB,
278 sfactorA, dfactorA);
279 }
280 }
281
282
283 /**
284 * Check if given blend equation is legal.
285 * \return GL_TRUE if legal, GL_FALSE otherwise.
286 */
287 static GLboolean
288 legal_blend_equation(const struct gl_context *ctx, GLenum mode)
289 {
290 switch (mode) {
291 case GL_FUNC_ADD:
292 return GL_TRUE;
293 case GL_MIN:
294 case GL_MAX:
295 return ctx->Extensions.EXT_blend_minmax;
296 case GL_FUNC_SUBTRACT:
297 case GL_FUNC_REVERSE_SUBTRACT:
298 return ctx->Extensions.EXT_blend_subtract;
299 default:
300 return GL_FALSE;
301 }
302 }
303
304
305 /* This is really an extension function! */
306 void GLAPIENTRY
307 _mesa_BlendEquation( GLenum mode )
308 {
309 GLuint buf, numBuffers;
310 GLboolean changed;
311 GET_CURRENT_CONTEXT(ctx);
312 ASSERT_OUTSIDE_BEGIN_END(ctx);
313
314 if (MESA_VERBOSE & VERBOSE_API)
315 _mesa_debug(ctx, "glBlendEquation(%s)\n",
316 _mesa_lookup_enum_by_nr(mode));
317
318 if (!legal_blend_equation(ctx, mode)) {
319 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquation");
320 return;
321 }
322
323 numBuffers = ctx->Extensions.ARB_draw_buffers_blend
324 ? ctx->Const.MaxDrawBuffers : 1;
325
326 changed = GL_FALSE;
327 for (buf = 0; buf < numBuffers; buf++) {
328 if (ctx->Color.Blend[buf].EquationRGB != mode ||
329 ctx->Color.Blend[buf].EquationA != mode) {
330 changed = GL_TRUE;
331 break;
332 }
333 }
334 if (!changed)
335 return;
336
337 FLUSH_VERTICES(ctx, _NEW_COLOR);
338 for (buf = 0; buf < numBuffers; buf++) {
339 ctx->Color.Blend[buf].EquationRGB = mode;
340 ctx->Color.Blend[buf].EquationA = mode;
341 }
342 ctx->Color._BlendEquationPerBuffer = GL_FALSE;
343
344 if (ctx->Driver.BlendEquationSeparate)
345 (*ctx->Driver.BlendEquationSeparate)( ctx, mode, mode );
346 }
347
348
349 /**
350 * Set blend equation for one color buffer/target.
351 */
352 void GLAPIENTRY
353 _mesa_BlendEquationi(GLuint buf, GLenum mode)
354 {
355 GET_CURRENT_CONTEXT(ctx);
356 ASSERT_OUTSIDE_BEGIN_END(ctx);
357
358 if (MESA_VERBOSE & VERBOSE_API)
359 _mesa_debug(ctx, "glBlendEquationi(%u, %s)\n",
360 buf, _mesa_lookup_enum_by_nr(mode));
361
362 if (buf >= ctx->Const.MaxDrawBuffers) {
363 _mesa_error(ctx, GL_INVALID_VALUE, "glBlendFuncSeparatei(buffer=%u)",
364 buf);
365 return;
366 }
367
368 if (!legal_blend_equation(ctx, mode)) {
369 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationi");
370 return;
371 }
372
373 if (ctx->Color.Blend[buf].EquationRGB == mode &&
374 ctx->Color.Blend[buf].EquationA == mode)
375 return; /* no change */
376
377 FLUSH_VERTICES(ctx, _NEW_COLOR);
378 ctx->Color.Blend[buf].EquationRGB = mode;
379 ctx->Color.Blend[buf].EquationA = mode;
380 ctx->Color._BlendEquationPerBuffer = GL_TRUE;
381
382 if (ctx->Driver.BlendEquationSeparatei)
383 ctx->Driver.BlendEquationSeparatei(ctx, buf, mode, mode);
384 }
385
386
387 void GLAPIENTRY
388 _mesa_BlendEquationSeparateEXT( GLenum modeRGB, GLenum modeA )
389 {
390 GLuint buf, numBuffers;
391 GLboolean changed;
392 GET_CURRENT_CONTEXT(ctx);
393 ASSERT_OUTSIDE_BEGIN_END(ctx);
394
395 if (MESA_VERBOSE & VERBOSE_API)
396 _mesa_debug(ctx, "glBlendEquationSeparateEXT(%s %s)\n",
397 _mesa_lookup_enum_by_nr(modeRGB),
398 _mesa_lookup_enum_by_nr(modeA));
399
400 if ( (modeRGB != modeA) && !ctx->Extensions.EXT_blend_equation_separate ) {
401 _mesa_error(ctx, GL_INVALID_OPERATION,
402 "glBlendEquationSeparateEXT not supported by driver");
403 return;
404 }
405
406 if (!legal_blend_equation(ctx, modeRGB)) {
407 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeRGB)");
408 return;
409 }
410
411 if (!legal_blend_equation(ctx, modeA)) {
412 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeA)");
413 return;
414 }
415
416 numBuffers = ctx->Extensions.ARB_draw_buffers_blend
417 ? ctx->Const.MaxDrawBuffers : 1;
418
419 changed = GL_FALSE;
420 for (buf = 0; buf < numBuffers; buf++) {
421 if (ctx->Color.Blend[buf].EquationRGB != modeRGB ||
422 ctx->Color.Blend[buf].EquationA != modeA) {
423 changed = GL_TRUE;
424 break;
425 }
426 }
427 if (!changed)
428 return;
429
430 FLUSH_VERTICES(ctx, _NEW_COLOR);
431 for (buf = 0; buf < numBuffers; buf++) {
432 ctx->Color.Blend[buf].EquationRGB = modeRGB;
433 ctx->Color.Blend[buf].EquationA = modeA;
434 }
435 ctx->Color._BlendEquationPerBuffer = GL_FALSE;
436
437 if (ctx->Driver.BlendEquationSeparate)
438 ctx->Driver.BlendEquationSeparate(ctx, modeRGB, modeA);
439 }
440
441
442 /**
443 * Set separate blend equations for one color buffer/target.
444 */
445 void GLAPIENTRY
446 _mesa_BlendEquationSeparatei(GLuint buf, GLenum modeRGB, GLenum modeA)
447 {
448 GET_CURRENT_CONTEXT(ctx);
449 ASSERT_OUTSIDE_BEGIN_END(ctx);
450
451 if (MESA_VERBOSE & VERBOSE_API)
452 _mesa_debug(ctx, "glBlendEquationSeparatei(%u, %s %s)\n", buf,
453 _mesa_lookup_enum_by_nr(modeRGB),
454 _mesa_lookup_enum_by_nr(modeA));
455
456 if (buf >= ctx->Const.MaxDrawBuffers) {
457 _mesa_error(ctx, GL_INVALID_VALUE, "glBlendEquationSeparatei(buffer=%u)",
458 buf);
459 return;
460 }
461
462 if (!legal_blend_equation(ctx, modeRGB)) {
463 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparatei(modeRGB)");
464 return;
465 }
466
467 if (!legal_blend_equation(ctx, modeA)) {
468 _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparatei(modeA)");
469 return;
470 }
471
472 if (ctx->Color.Blend[buf].EquationRGB == modeRGB &&
473 ctx->Color.Blend[buf].EquationA == modeA)
474 return; /* no change */
475
476 FLUSH_VERTICES(ctx, _NEW_COLOR);
477 ctx->Color.Blend[buf].EquationRGB = modeRGB;
478 ctx->Color.Blend[buf].EquationA = modeA;
479 ctx->Color._BlendEquationPerBuffer = GL_TRUE;
480
481 if (ctx->Driver.BlendEquationSeparatei)
482 ctx->Driver.BlendEquationSeparatei(ctx, buf, modeRGB, modeA);
483 }
484
485
486
487 #endif /* _HAVE_FULL_GL */
488
489
490 /**
491 * Set the blending color.
492 *
493 * \param red red color component.
494 * \param green green color component.
495 * \param blue blue color component.
496 * \param alpha alpha color component.
497 *
498 * \sa glBlendColor().
499 *
500 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
501 * change, flushes the vertices and notifies the driver via
502 * dd_function_table::BlendColor callback.
503 */
504 void GLAPIENTRY
505 _mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
506 {
507 GLfloat tmp[4];
508 GET_CURRENT_CONTEXT(ctx);
509 ASSERT_OUTSIDE_BEGIN_END(ctx);
510
511 tmp[0] = red;
512 tmp[1] = green;
513 tmp[2] = blue;
514 tmp[3] = alpha;
515
516 if (TEST_EQ_4V(tmp, ctx->Color.BlendColorUnclamped))
517 return;
518
519 FLUSH_VERTICES(ctx, _NEW_COLOR);
520 COPY_4FV( ctx->Color.BlendColorUnclamped, tmp );
521
522 ctx->Color.BlendColor[0] = CLAMP(tmp[0], 0.0F, 1.0F);
523 ctx->Color.BlendColor[1] = CLAMP(tmp[1], 0.0F, 1.0F);
524 ctx->Color.BlendColor[2] = CLAMP(tmp[2], 0.0F, 1.0F);
525 ctx->Color.BlendColor[3] = CLAMP(tmp[3], 0.0F, 1.0F);
526
527 if (ctx->Driver.BlendColor)
528 (*ctx->Driver.BlendColor)(ctx, ctx->Color.BlendColor);
529 }
530
531
532 /**
533 * Specify the alpha test function.
534 *
535 * \param func alpha comparison function.
536 * \param ref reference value.
537 *
538 * Verifies the parameters and updates gl_colorbuffer_attrib.
539 * On a change, flushes the vertices and notifies the driver via
540 * dd_function_table::AlphaFunc callback.
541 */
542 void GLAPIENTRY
543 _mesa_AlphaFunc( GLenum func, GLclampf ref )
544 {
545 GET_CURRENT_CONTEXT(ctx);
546 ASSERT_OUTSIDE_BEGIN_END(ctx);
547
548 if (MESA_VERBOSE & VERBOSE_API)
549 _mesa_debug(ctx, "glAlphaFunc(%s, %f)\n",
550 _mesa_lookup_enum_by_nr(func), ref);
551
552 switch (func) {
553 case GL_NEVER:
554 case GL_LESS:
555 case GL_EQUAL:
556 case GL_LEQUAL:
557 case GL_GREATER:
558 case GL_NOTEQUAL:
559 case GL_GEQUAL:
560 case GL_ALWAYS:
561 if (ctx->Color.AlphaFunc == func && ctx->Color.AlphaRefUnclamped == ref)
562 return; /* no change */
563
564 FLUSH_VERTICES(ctx, _NEW_COLOR);
565 ctx->Color.AlphaFunc = func;
566 ctx->Color.AlphaRefUnclamped = ref;
567 ctx->Color.AlphaRef = CLAMP(ref, 0.0F, 1.0F);
568
569 if (ctx->Driver.AlphaFunc)
570 ctx->Driver.AlphaFunc(ctx, func, ctx->Color.AlphaRef);
571 return;
572
573 default:
574 _mesa_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
575 return;
576 }
577 }
578
579
580 /**
581 * Specify a logic pixel operation for color index rendering.
582 *
583 * \param opcode operation.
584 *
585 * Verifies that \p opcode is a valid enum and updates
586 gl_colorbuffer_attrib::LogicOp.
587 * On a change, flushes the vertices and notifies the driver via the
588 * dd_function_table::LogicOpcode callback.
589 */
590 void GLAPIENTRY
591 _mesa_LogicOp( GLenum opcode )
592 {
593 GET_CURRENT_CONTEXT(ctx);
594 ASSERT_OUTSIDE_BEGIN_END(ctx);
595
596 if (MESA_VERBOSE & VERBOSE_API)
597 _mesa_debug(ctx, "glLogicOp(%s)\n", _mesa_lookup_enum_by_nr(opcode));
598
599 switch (opcode) {
600 case GL_CLEAR:
601 case GL_SET:
602 case GL_COPY:
603 case GL_COPY_INVERTED:
604 case GL_NOOP:
605 case GL_INVERT:
606 case GL_AND:
607 case GL_NAND:
608 case GL_OR:
609 case GL_NOR:
610 case GL_XOR:
611 case GL_EQUIV:
612 case GL_AND_REVERSE:
613 case GL_AND_INVERTED:
614 case GL_OR_REVERSE:
615 case GL_OR_INVERTED:
616 break;
617 default:
618 _mesa_error( ctx, GL_INVALID_ENUM, "glLogicOp" );
619 return;
620 }
621
622 if (ctx->Color.LogicOp == opcode)
623 return;
624
625 FLUSH_VERTICES(ctx, _NEW_COLOR);
626 ctx->Color.LogicOp = opcode;
627
628 if (ctx->Driver.LogicOpcode)
629 ctx->Driver.LogicOpcode( ctx, opcode );
630 }
631
632 #if _HAVE_FULL_GL
633 void GLAPIENTRY
634 _mesa_IndexMask( GLuint mask )
635 {
636 GET_CURRENT_CONTEXT(ctx);
637 ASSERT_OUTSIDE_BEGIN_END(ctx);
638
639 if (ctx->Color.IndexMask == mask)
640 return;
641
642 FLUSH_VERTICES(ctx, _NEW_COLOR);
643 ctx->Color.IndexMask = mask;
644 }
645 #endif
646
647
648 /**
649 * Enable or disable writing of frame buffer color components.
650 *
651 * \param red whether to mask writing of the red color component.
652 * \param green whether to mask writing of the green color component.
653 * \param blue whether to mask writing of the blue color component.
654 * \param alpha whether to mask writing of the alpha color component.
655 *
656 * \sa glColorMask().
657 *
658 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
659 * change, flushes the vertices and notifies the driver via the
660 * dd_function_table::ColorMask callback.
661 */
662 void GLAPIENTRY
663 _mesa_ColorMask( GLboolean red, GLboolean green,
664 GLboolean blue, GLboolean alpha )
665 {
666 GET_CURRENT_CONTEXT(ctx);
667 GLubyte tmp[4];
668 GLuint i;
669 GLboolean flushed;
670 ASSERT_OUTSIDE_BEGIN_END(ctx);
671
672 if (MESA_VERBOSE & VERBOSE_API)
673 _mesa_debug(ctx, "glColorMask(%d, %d, %d, %d)\n",
674 red, green, blue, alpha);
675
676 /* Shouldn't have any information about channel depth in core mesa
677 * -- should probably store these as the native booleans:
678 */
679 tmp[RCOMP] = red ? 0xff : 0x0;
680 tmp[GCOMP] = green ? 0xff : 0x0;
681 tmp[BCOMP] = blue ? 0xff : 0x0;
682 tmp[ACOMP] = alpha ? 0xff : 0x0;
683
684 flushed = GL_FALSE;
685 for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
686 if (!TEST_EQ_4V(tmp, ctx->Color.ColorMask[i])) {
687 if (!flushed) {
688 FLUSH_VERTICES(ctx, _NEW_COLOR);
689 }
690 flushed = GL_TRUE;
691 COPY_4UBV(ctx->Color.ColorMask[i], tmp);
692 }
693 }
694
695 if (ctx->Driver.ColorMask)
696 ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
697 }
698
699
700 /**
701 * For GL_EXT_draw_buffers2 and GL3
702 */
703 void GLAPIENTRY
704 _mesa_ColorMaskIndexed( GLuint buf, GLboolean red, GLboolean green,
705 GLboolean blue, GLboolean alpha )
706 {
707 GLubyte tmp[4];
708 GET_CURRENT_CONTEXT(ctx);
709 ASSERT_OUTSIDE_BEGIN_END(ctx);
710
711 if (MESA_VERBOSE & VERBOSE_API)
712 _mesa_debug(ctx, "glColorMaskIndexed %u %d %d %d %d\n",
713 buf, red, green, blue, alpha);
714
715 if (buf >= ctx->Const.MaxDrawBuffers) {
716 _mesa_error(ctx, GL_INVALID_VALUE, "glColorMaskIndexed(buf=%u)", buf);
717 return;
718 }
719
720 /* Shouldn't have any information about channel depth in core mesa
721 * -- should probably store these as the native booleans:
722 */
723 tmp[RCOMP] = red ? 0xff : 0x0;
724 tmp[GCOMP] = green ? 0xff : 0x0;
725 tmp[BCOMP] = blue ? 0xff : 0x0;
726 tmp[ACOMP] = alpha ? 0xff : 0x0;
727
728 if (TEST_EQ_4V(tmp, ctx->Color.ColorMask[buf]))
729 return;
730
731 FLUSH_VERTICES(ctx, _NEW_COLOR);
732 COPY_4UBV(ctx->Color.ColorMask[buf], tmp);
733
734 if (ctx->Driver.ColorMaskIndexed)
735 ctx->Driver.ColorMaskIndexed(ctx, buf, red, green, blue, alpha);
736 }
737
738
739 void GLAPIENTRY
740 _mesa_ClampColorARB(GLenum target, GLenum clamp)
741 {
742 GET_CURRENT_CONTEXT(ctx);
743
744 ASSERT_OUTSIDE_BEGIN_END(ctx);
745
746 if (clamp != GL_TRUE && clamp != GL_FALSE && clamp != GL_FIXED_ONLY_ARB) {
747 _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(clamp)");
748 return;
749 }
750
751 switch (target) {
752 case GL_CLAMP_VERTEX_COLOR_ARB:
753 FLUSH_VERTICES(ctx, _NEW_LIGHT);
754 ctx->Light.ClampVertexColor = clamp;
755 break;
756 case GL_CLAMP_FRAGMENT_COLOR_ARB:
757 FLUSH_VERTICES(ctx, _NEW_FRAG_CLAMP);
758 ctx->Color.ClampFragmentColor = clamp;
759 break;
760 case GL_CLAMP_READ_COLOR_ARB:
761 FLUSH_VERTICES(ctx, _NEW_COLOR);
762 ctx->Color.ClampReadColor = clamp;
763 break;
764 default:
765 _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(target)");
766 return;
767 }
768 }
769
770
771
772
773 /**********************************************************************/
774 /** \name Initialization */
775 /*@{*/
776
777 /**
778 * Initialization of the context's Color attribute group.
779 *
780 * \param ctx GL context.
781 *
782 * Initializes the related fields in the context color attribute group,
783 * __struct gl_contextRec::Color.
784 */
785 void _mesa_init_color( struct gl_context * ctx )
786 {
787 GLuint i;
788
789 /* Color buffer group */
790 ctx->Color.IndexMask = ~0u;
791 memset(ctx->Color.ColorMask, 0xff, sizeof(ctx->Color.ColorMask));
792 ctx->Color.ClearIndex = 0;
793 ASSIGN_4V( ctx->Color.ClearColor.f, 0, 0, 0, 0 );
794 ctx->Color.AlphaEnabled = GL_FALSE;
795 ctx->Color.AlphaFunc = GL_ALWAYS;
796 ctx->Color.AlphaRef = 0;
797 ctx->Color.BlendEnabled = 0x0;
798 for (i = 0; i < Elements(ctx->Color.Blend); i++) {
799 ctx->Color.Blend[i].SrcRGB = GL_ONE;
800 ctx->Color.Blend[i].DstRGB = GL_ZERO;
801 ctx->Color.Blend[i].SrcA = GL_ONE;
802 ctx->Color.Blend[i].DstA = GL_ZERO;
803 ctx->Color.Blend[i].EquationRGB = GL_FUNC_ADD;
804 ctx->Color.Blend[i].EquationA = GL_FUNC_ADD;
805 }
806 ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
807 ASSIGN_4V( ctx->Color.BlendColorUnclamped, 0.0, 0.0, 0.0, 0.0 );
808 ctx->Color.IndexLogicOpEnabled = GL_FALSE;
809 ctx->Color.ColorLogicOpEnabled = GL_FALSE;
810 ctx->Color._LogicOpEnabled = GL_FALSE;
811 ctx->Color.LogicOp = GL_COPY;
812 ctx->Color.DitherFlag = GL_TRUE;
813
814 if (ctx->Visual.doubleBufferMode) {
815 ctx->Color.DrawBuffer[0] = GL_BACK;
816 }
817 else {
818 ctx->Color.DrawBuffer[0] = GL_FRONT;
819 }
820
821 ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB;
822 ctx->Color._ClampFragmentColor = GL_TRUE;
823 ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB;
824 ctx->Color._ClampReadColor = GL_TRUE;
825 }
826
827 /*@}*/