7 * Mesa 3-D graphics library
10 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
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:
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
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.
42 * Check if given blend source factor is legal.
43 * \return GL_TRUE if legal, GL_FALSE otherwise.
46 legal_src_factor(const struct gl_context
*ctx
, GLenum factor
)
50 case GL_ONE_MINUS_SRC_COLOR
:
51 return ctx
->Extensions
.NV_blend_square
;
55 case GL_ONE_MINUS_DST_COLOR
:
57 case GL_ONE_MINUS_SRC_ALPHA
:
59 case GL_ONE_MINUS_DST_ALPHA
:
60 case GL_SRC_ALPHA_SATURATE
:
62 case GL_CONSTANT_COLOR
:
63 case GL_ONE_MINUS_CONSTANT_COLOR
:
64 case GL_CONSTANT_ALPHA
:
65 case GL_ONE_MINUS_CONSTANT_ALPHA
:
66 return _mesa_is_desktop_gl(ctx
) || ctx
->API
== API_OPENGLES2
;
69 case GL_ONE_MINUS_SRC1_COLOR
:
70 case GL_ONE_MINUS_SRC1_ALPHA
:
71 return _mesa_is_desktop_gl(ctx
)
72 && ctx
->Extensions
.ARB_blend_func_extended
;
80 * Check if given blend destination factor is legal.
81 * \return GL_TRUE if legal, GL_FALSE otherwise.
84 legal_dst_factor(const struct gl_context
*ctx
, GLenum factor
)
88 case GL_ONE_MINUS_DST_COLOR
:
89 return ctx
->Extensions
.NV_blend_square
;
93 case GL_ONE_MINUS_SRC_COLOR
:
95 case GL_ONE_MINUS_SRC_ALPHA
:
97 case GL_ONE_MINUS_DST_ALPHA
:
99 case GL_CONSTANT_COLOR
:
100 case GL_ONE_MINUS_CONSTANT_COLOR
:
101 case GL_CONSTANT_ALPHA
:
102 case GL_ONE_MINUS_CONSTANT_ALPHA
:
103 return _mesa_is_desktop_gl(ctx
) || ctx
->API
== API_OPENGLES2
;
104 case GL_SRC_ALPHA_SATURATE
:
105 return (_mesa_is_desktop_gl(ctx
)
106 && ctx
->Extensions
.ARB_blend_func_extended
)
107 || _mesa_is_gles3(ctx
);
110 case GL_ONE_MINUS_SRC1_COLOR
:
111 case GL_ONE_MINUS_SRC1_ALPHA
:
112 return _mesa_is_desktop_gl(ctx
)
113 && ctx
->Extensions
.ARB_blend_func_extended
;
121 * Check if src/dest RGB/A blend factors are legal. If not generate
123 * \return GL_TRUE if factors are legal, GL_FALSE otherwise.
126 validate_blend_factors(struct gl_context
*ctx
, const char *func
,
127 GLenum sfactorRGB
, GLenum dfactorRGB
,
128 GLenum sfactorA
, GLenum dfactorA
)
130 if (!legal_src_factor(ctx
, sfactorRGB
)) {
131 _mesa_error(ctx
, GL_INVALID_ENUM
,
132 "%s(sfactorRGB = %s)", func
,
133 _mesa_lookup_enum_by_nr(sfactorRGB
));
137 if (!legal_dst_factor(ctx
, dfactorRGB
)) {
138 _mesa_error(ctx
, GL_INVALID_ENUM
,
139 "%s(dfactorRGB = %s)", func
,
140 _mesa_lookup_enum_by_nr(dfactorRGB
));
144 if (sfactorA
!= sfactorRGB
&& !legal_src_factor(ctx
, sfactorA
)) {
145 _mesa_error(ctx
, GL_INVALID_ENUM
,
146 "%s(sfactorA = %s)", func
,
147 _mesa_lookup_enum_by_nr(sfactorA
));
151 if (dfactorA
!= dfactorRGB
&& !legal_dst_factor(ctx
, dfactorA
)) {
152 _mesa_error(ctx
, GL_INVALID_ENUM
,
153 "%s(dfactorA = %s)", func
,
154 _mesa_lookup_enum_by_nr(dfactorA
));
163 * Specify the blending operation.
165 * \param sfactor source factor operator.
166 * \param dfactor destination factor operator.
168 * \sa glBlendFunc, glBlendFuncSeparateEXT
171 _mesa_BlendFunc( GLenum sfactor
, GLenum dfactor
)
173 _mesa_BlendFuncSeparateEXT(sfactor
, dfactor
, sfactor
, dfactor
);
177 blend_factor_is_dual_src(GLenum factor
)
179 return (factor
== GL_SRC1_COLOR
||
180 factor
== GL_SRC1_ALPHA
||
181 factor
== GL_ONE_MINUS_SRC1_COLOR
||
182 factor
== GL_ONE_MINUS_SRC1_ALPHA
);
186 update_uses_dual_src(struct gl_context
*ctx
, int buf
)
188 ctx
->Color
.Blend
[buf
]._UsesDualSrc
=
189 (blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].SrcRGB
) ||
190 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].DstRGB
) ||
191 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].SrcA
) ||
192 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].DstA
));
196 * Set the separate blend source/dest factors for all draw buffers.
198 * \param sfactorRGB RGB source factor operator.
199 * \param dfactorRGB RGB destination factor operator.
200 * \param sfactorA alpha source factor operator.
201 * \param dfactorA alpha destination factor operator.
204 _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB
, GLenum dfactorRGB
,
205 GLenum sfactorA
, GLenum dfactorA
)
207 GLuint buf
, numBuffers
;
209 GET_CURRENT_CONTEXT(ctx
);
210 ASSERT_OUTSIDE_BEGIN_END(ctx
);
212 if (MESA_VERBOSE
& VERBOSE_API
)
213 _mesa_debug(ctx
, "glBlendFuncSeparate %s %s %s %s\n",
214 _mesa_lookup_enum_by_nr(sfactorRGB
),
215 _mesa_lookup_enum_by_nr(dfactorRGB
),
216 _mesa_lookup_enum_by_nr(sfactorA
),
217 _mesa_lookup_enum_by_nr(dfactorA
));
219 if (!validate_blend_factors(ctx
, "glBlendFuncSeparate",
220 sfactorRGB
, dfactorRGB
,
221 sfactorA
, dfactorA
)) {
225 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
226 ? ctx
->Const
.MaxDrawBuffers
: 1;
229 for (buf
= 0; buf
< numBuffers
; buf
++) {
230 if (ctx
->Color
.Blend
[buf
].SrcRGB
!= sfactorRGB
||
231 ctx
->Color
.Blend
[buf
].DstRGB
!= dfactorRGB
||
232 ctx
->Color
.Blend
[buf
].SrcA
!= sfactorA
||
233 ctx
->Color
.Blend
[buf
].DstA
!= dfactorA
) {
241 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
243 for (buf
= 0; buf
< numBuffers
; buf
++) {
244 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
245 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
246 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
247 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
248 update_uses_dual_src(ctx
, buf
);
250 ctx
->Color
._BlendFuncPerBuffer
= GL_FALSE
;
252 if (ctx
->Driver
.BlendFuncSeparate
) {
253 ctx
->Driver
.BlendFuncSeparate(ctx
, sfactorRGB
, dfactorRGB
,
263 * Set blend source/dest factors for one color buffer/target.
266 _mesa_BlendFunci(GLuint buf
, GLenum sfactor
, GLenum dfactor
)
268 _mesa_BlendFuncSeparatei(buf
, sfactor
, dfactor
, sfactor
, dfactor
);
273 * Set separate blend source/dest factors for one color buffer/target.
276 _mesa_BlendFuncSeparatei(GLuint buf
, GLenum sfactorRGB
, GLenum dfactorRGB
,
277 GLenum sfactorA
, GLenum dfactorA
)
279 GET_CURRENT_CONTEXT(ctx
);
280 ASSERT_OUTSIDE_BEGIN_END(ctx
);
282 if (!ctx
->Extensions
.ARB_draw_buffers_blend
) {
283 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlendFunc[Separate]i()");
287 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
288 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
293 if (!validate_blend_factors(ctx
, "glBlendFuncSeparatei",
294 sfactorRGB
, dfactorRGB
,
295 sfactorA
, dfactorA
)) {
299 if (ctx
->Color
.Blend
[buf
].SrcRGB
== sfactorRGB
&&
300 ctx
->Color
.Blend
[buf
].DstRGB
== dfactorRGB
&&
301 ctx
->Color
.Blend
[buf
].SrcA
== sfactorA
&&
302 ctx
->Color
.Blend
[buf
].DstA
== dfactorA
)
303 return; /* no change */
305 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
307 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
308 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
309 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
310 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
311 update_uses_dual_src(ctx
, buf
);
312 ctx
->Color
._BlendFuncPerBuffer
= GL_TRUE
;
314 if (ctx
->Driver
.BlendFuncSeparatei
) {
315 ctx
->Driver
.BlendFuncSeparatei(ctx
, buf
, sfactorRGB
, dfactorRGB
,
322 * Check if given blend equation is legal.
323 * \return GL_TRUE if legal, GL_FALSE otherwise.
326 legal_blend_equation(const struct gl_context
*ctx
, GLenum mode
)
330 case GL_FUNC_SUBTRACT
:
331 case GL_FUNC_REVERSE_SUBTRACT
:
335 return ctx
->Extensions
.EXT_blend_minmax
;
342 /* This is really an extension function! */
344 _mesa_BlendEquation( GLenum mode
)
346 GLuint buf
, numBuffers
;
348 GET_CURRENT_CONTEXT(ctx
);
349 ASSERT_OUTSIDE_BEGIN_END(ctx
);
351 if (MESA_VERBOSE
& VERBOSE_API
)
352 _mesa_debug(ctx
, "glBlendEquation(%s)\n",
353 _mesa_lookup_enum_by_nr(mode
));
355 if (!legal_blend_equation(ctx
, mode
)) {
356 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
360 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
361 ? ctx
->Const
.MaxDrawBuffers
: 1;
364 for (buf
= 0; buf
< numBuffers
; buf
++) {
365 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= mode
||
366 ctx
->Color
.Blend
[buf
].EquationA
!= mode
) {
374 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
375 for (buf
= 0; buf
< numBuffers
; buf
++) {
376 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
377 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
379 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
381 if (ctx
->Driver
.BlendEquationSeparate
)
382 (*ctx
->Driver
.BlendEquationSeparate
)( ctx
, mode
, mode
);
387 * Set blend equation for one color buffer/target.
390 _mesa_BlendEquationi(GLuint buf
, GLenum mode
)
392 GET_CURRENT_CONTEXT(ctx
);
393 ASSERT_OUTSIDE_BEGIN_END(ctx
);
395 if (MESA_VERBOSE
& VERBOSE_API
)
396 _mesa_debug(ctx
, "glBlendEquationi(%u, %s)\n",
397 buf
, _mesa_lookup_enum_by_nr(mode
));
399 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
400 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
405 if (!legal_blend_equation(ctx
, mode
)) {
406 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationi");
410 if (ctx
->Color
.Blend
[buf
].EquationRGB
== mode
&&
411 ctx
->Color
.Blend
[buf
].EquationA
== mode
)
412 return; /* no change */
414 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
415 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
416 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
417 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
419 if (ctx
->Driver
.BlendEquationSeparatei
)
420 ctx
->Driver
.BlendEquationSeparatei(ctx
, buf
, mode
, mode
);
425 _mesa_BlendEquationSeparateEXT( GLenum modeRGB
, GLenum modeA
)
427 GLuint buf
, numBuffers
;
429 GET_CURRENT_CONTEXT(ctx
);
430 ASSERT_OUTSIDE_BEGIN_END(ctx
);
432 if (MESA_VERBOSE
& VERBOSE_API
)
433 _mesa_debug(ctx
, "glBlendEquationSeparateEXT(%s %s)\n",
434 _mesa_lookup_enum_by_nr(modeRGB
),
435 _mesa_lookup_enum_by_nr(modeA
));
437 if ( (modeRGB
!= modeA
) && !ctx
->Extensions
.EXT_blend_equation_separate
) {
438 _mesa_error(ctx
, GL_INVALID_OPERATION
,
439 "glBlendEquationSeparateEXT not supported by driver");
443 if (!legal_blend_equation(ctx
, modeRGB
)) {
444 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeRGB)");
448 if (!legal_blend_equation(ctx
, modeA
)) {
449 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeA)");
453 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
454 ? ctx
->Const
.MaxDrawBuffers
: 1;
457 for (buf
= 0; buf
< numBuffers
; buf
++) {
458 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= modeRGB
||
459 ctx
->Color
.Blend
[buf
].EquationA
!= modeA
) {
467 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
468 for (buf
= 0; buf
< numBuffers
; buf
++) {
469 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
470 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
472 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
474 if (ctx
->Driver
.BlendEquationSeparate
)
475 ctx
->Driver
.BlendEquationSeparate(ctx
, modeRGB
, modeA
);
480 * Set separate blend equations for one color buffer/target.
483 _mesa_BlendEquationSeparatei(GLuint buf
, GLenum modeRGB
, GLenum modeA
)
485 GET_CURRENT_CONTEXT(ctx
);
486 ASSERT_OUTSIDE_BEGIN_END(ctx
);
488 if (MESA_VERBOSE
& VERBOSE_API
)
489 _mesa_debug(ctx
, "glBlendEquationSeparatei(%u, %s %s)\n", buf
,
490 _mesa_lookup_enum_by_nr(modeRGB
),
491 _mesa_lookup_enum_by_nr(modeA
));
493 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
494 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendEquationSeparatei(buffer=%u)",
499 if (!legal_blend_equation(ctx
, modeRGB
)) {
500 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeRGB)");
504 if (!legal_blend_equation(ctx
, modeA
)) {
505 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeA)");
509 if (ctx
->Color
.Blend
[buf
].EquationRGB
== modeRGB
&&
510 ctx
->Color
.Blend
[buf
].EquationA
== modeA
)
511 return; /* no change */
513 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
514 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
515 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
516 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
518 if (ctx
->Driver
.BlendEquationSeparatei
)
519 ctx
->Driver
.BlendEquationSeparatei(ctx
, buf
, modeRGB
, modeA
);
524 #endif /* _HAVE_FULL_GL */
528 * Set the blending color.
530 * \param red red color component.
531 * \param green green color component.
532 * \param blue blue color component.
533 * \param alpha alpha color component.
535 * \sa glBlendColor().
537 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
538 * change, flushes the vertices and notifies the driver via
539 * dd_function_table::BlendColor callback.
542 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
545 GET_CURRENT_CONTEXT(ctx
);
546 ASSERT_OUTSIDE_BEGIN_END(ctx
);
553 if (TEST_EQ_4V(tmp
, ctx
->Color
.BlendColorUnclamped
))
556 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
557 COPY_4FV( ctx
->Color
.BlendColorUnclamped
, tmp
);
559 ctx
->Color
.BlendColor
[0] = CLAMP(tmp
[0], 0.0F
, 1.0F
);
560 ctx
->Color
.BlendColor
[1] = CLAMP(tmp
[1], 0.0F
, 1.0F
);
561 ctx
->Color
.BlendColor
[2] = CLAMP(tmp
[2], 0.0F
, 1.0F
);
562 ctx
->Color
.BlendColor
[3] = CLAMP(tmp
[3], 0.0F
, 1.0F
);
564 if (ctx
->Driver
.BlendColor
)
565 (*ctx
->Driver
.BlendColor
)(ctx
, ctx
->Color
.BlendColor
);
570 * Specify the alpha test function.
572 * \param func alpha comparison function.
573 * \param ref reference value.
575 * Verifies the parameters and updates gl_colorbuffer_attrib.
576 * On a change, flushes the vertices and notifies the driver via
577 * dd_function_table::AlphaFunc callback.
580 _mesa_AlphaFunc( GLenum func
, GLclampf ref
)
582 GET_CURRENT_CONTEXT(ctx
);
583 ASSERT_OUTSIDE_BEGIN_END(ctx
);
585 if (MESA_VERBOSE
& VERBOSE_API
)
586 _mesa_debug(ctx
, "glAlphaFunc(%s, %f)\n",
587 _mesa_lookup_enum_by_nr(func
), ref
);
598 if (ctx
->Color
.AlphaFunc
== func
&& ctx
->Color
.AlphaRefUnclamped
== ref
)
599 return; /* no change */
601 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
602 ctx
->Color
.AlphaFunc
= func
;
603 ctx
->Color
.AlphaRefUnclamped
= ref
;
604 ctx
->Color
.AlphaRef
= CLAMP(ref
, 0.0F
, 1.0F
);
606 if (ctx
->Driver
.AlphaFunc
)
607 ctx
->Driver
.AlphaFunc(ctx
, func
, ctx
->Color
.AlphaRef
);
611 _mesa_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
618 * Specify a logic pixel operation for color index rendering.
620 * \param opcode operation.
622 * Verifies that \p opcode is a valid enum and updates
623 gl_colorbuffer_attrib::LogicOp.
624 * On a change, flushes the vertices and notifies the driver via the
625 * dd_function_table::LogicOpcode callback.
628 _mesa_LogicOp( GLenum opcode
)
630 GET_CURRENT_CONTEXT(ctx
);
631 ASSERT_OUTSIDE_BEGIN_END(ctx
);
633 if (MESA_VERBOSE
& VERBOSE_API
)
634 _mesa_debug(ctx
, "glLogicOp(%s)\n", _mesa_lookup_enum_by_nr(opcode
));
640 case GL_COPY_INVERTED
:
650 case GL_AND_INVERTED
:
655 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLogicOp" );
659 if (ctx
->Color
.LogicOp
== opcode
)
662 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
663 ctx
->Color
.LogicOp
= opcode
;
665 if (ctx
->Driver
.LogicOpcode
)
666 ctx
->Driver
.LogicOpcode( ctx
, opcode
);
671 _mesa_IndexMask( GLuint mask
)
673 GET_CURRENT_CONTEXT(ctx
);
674 ASSERT_OUTSIDE_BEGIN_END(ctx
);
676 if (ctx
->Color
.IndexMask
== mask
)
679 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
680 ctx
->Color
.IndexMask
= mask
;
686 * Enable or disable writing of frame buffer color components.
688 * \param red whether to mask writing of the red color component.
689 * \param green whether to mask writing of the green color component.
690 * \param blue whether to mask writing of the blue color component.
691 * \param alpha whether to mask writing of the alpha color component.
695 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
696 * change, flushes the vertices and notifies the driver via the
697 * dd_function_table::ColorMask callback.
700 _mesa_ColorMask( GLboolean red
, GLboolean green
,
701 GLboolean blue
, GLboolean alpha
)
703 GET_CURRENT_CONTEXT(ctx
);
707 ASSERT_OUTSIDE_BEGIN_END(ctx
);
709 if (MESA_VERBOSE
& VERBOSE_API
)
710 _mesa_debug(ctx
, "glColorMask(%d, %d, %d, %d)\n",
711 red
, green
, blue
, alpha
);
713 /* Shouldn't have any information about channel depth in core mesa
714 * -- should probably store these as the native booleans:
716 tmp
[RCOMP
] = red
? 0xff : 0x0;
717 tmp
[GCOMP
] = green
? 0xff : 0x0;
718 tmp
[BCOMP
] = blue
? 0xff : 0x0;
719 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
722 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
723 if (!TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[i
])) {
725 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
728 COPY_4UBV(ctx
->Color
.ColorMask
[i
], tmp
);
732 if (ctx
->Driver
.ColorMask
)
733 ctx
->Driver
.ColorMask( ctx
, red
, green
, blue
, alpha
);
738 * For GL_EXT_draw_buffers2 and GL3
741 _mesa_ColorMaskIndexed( GLuint buf
, GLboolean red
, GLboolean green
,
742 GLboolean blue
, GLboolean alpha
)
745 GET_CURRENT_CONTEXT(ctx
);
746 ASSERT_OUTSIDE_BEGIN_END(ctx
);
748 if (MESA_VERBOSE
& VERBOSE_API
)
749 _mesa_debug(ctx
, "glColorMaskIndexed %u %d %d %d %d\n",
750 buf
, red
, green
, blue
, alpha
);
752 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
753 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorMaskIndexed(buf=%u)", buf
);
757 /* Shouldn't have any information about channel depth in core mesa
758 * -- should probably store these as the native booleans:
760 tmp
[RCOMP
] = red
? 0xff : 0x0;
761 tmp
[GCOMP
] = green
? 0xff : 0x0;
762 tmp
[BCOMP
] = blue
? 0xff : 0x0;
763 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
765 if (TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[buf
]))
768 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
769 COPY_4UBV(ctx
->Color
.ColorMask
[buf
], tmp
);
771 if (ctx
->Driver
.ColorMaskIndexed
)
772 ctx
->Driver
.ColorMaskIndexed(ctx
, buf
, red
, green
, blue
, alpha
);
777 _mesa_ClampColorARB(GLenum target
, GLenum clamp
)
779 GET_CURRENT_CONTEXT(ctx
);
781 ASSERT_OUTSIDE_BEGIN_END(ctx
);
783 if (clamp
!= GL_TRUE
&& clamp
!= GL_FALSE
&& clamp
!= GL_FIXED_ONLY_ARB
) {
784 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColorARB(clamp)");
789 case GL_CLAMP_VERTEX_COLOR_ARB
:
790 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
791 ctx
->Light
.ClampVertexColor
= clamp
;
793 case GL_CLAMP_FRAGMENT_COLOR_ARB
:
794 FLUSH_VERTICES(ctx
, _NEW_FRAG_CLAMP
);
795 ctx
->Color
.ClampFragmentColor
= clamp
;
797 case GL_CLAMP_READ_COLOR_ARB
:
798 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
799 ctx
->Color
.ClampReadColor
= clamp
;
802 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColorARB(target)");
810 /**********************************************************************/
811 /** \name Initialization */
815 * Initialization of the context's Color attribute group.
817 * \param ctx GL context.
819 * Initializes the related fields in the context color attribute group,
820 * __struct gl_contextRec::Color.
822 void _mesa_init_color( struct gl_context
* ctx
)
826 /* Color buffer group */
827 ctx
->Color
.IndexMask
= ~0u;
828 memset(ctx
->Color
.ColorMask
, 0xff, sizeof(ctx
->Color
.ColorMask
));
829 ctx
->Color
.ClearIndex
= 0;
830 ASSIGN_4V( ctx
->Color
.ClearColor
.f
, 0, 0, 0, 0 );
831 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
832 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
833 ctx
->Color
.AlphaRef
= 0;
834 ctx
->Color
.BlendEnabled
= 0x0;
835 for (i
= 0; i
< Elements(ctx
->Color
.Blend
); i
++) {
836 ctx
->Color
.Blend
[i
].SrcRGB
= GL_ONE
;
837 ctx
->Color
.Blend
[i
].DstRGB
= GL_ZERO
;
838 ctx
->Color
.Blend
[i
].SrcA
= GL_ONE
;
839 ctx
->Color
.Blend
[i
].DstA
= GL_ZERO
;
840 ctx
->Color
.Blend
[i
].EquationRGB
= GL_FUNC_ADD
;
841 ctx
->Color
.Blend
[i
].EquationA
= GL_FUNC_ADD
;
843 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
844 ASSIGN_4V( ctx
->Color
.BlendColorUnclamped
, 0.0, 0.0, 0.0, 0.0 );
845 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
846 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
847 ctx
->Color
.LogicOp
= GL_COPY
;
848 ctx
->Color
.DitherFlag
= GL_TRUE
;
850 if (ctx
->Visual
.doubleBufferMode
) {
851 ctx
->Color
.DrawBuffer
[0] = GL_BACK
;
854 ctx
->Color
.DrawBuffer
[0] = GL_FRONT
;
857 ctx
->Color
.ClampFragmentColor
= GL_FIXED_ONLY_ARB
;
858 ctx
->Color
._ClampFragmentColor
= GL_TRUE
;
859 ctx
->Color
.ClampReadColor
= GL_FIXED_ONLY_ARB
;
860 ctx
->Color
._ClampReadColor
= GL_TRUE
;