7 * Mesa 3-D graphics library
9 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * 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
:
54 case GL_ONE_MINUS_DST_COLOR
:
56 case GL_ONE_MINUS_SRC_ALPHA
:
58 case GL_ONE_MINUS_DST_ALPHA
:
59 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 _mesa_is_desktop_gl(ctx
) || ctx
->API
== API_OPENGLES2
;
68 case GL_ONE_MINUS_SRC1_COLOR
:
69 case GL_ONE_MINUS_SRC1_ALPHA
:
70 return _mesa_is_desktop_gl(ctx
)
71 && ctx
->Extensions
.ARB_blend_func_extended
;
79 * Check if given blend destination factor is legal.
80 * \return GL_TRUE if legal, GL_FALSE otherwise.
83 legal_dst_factor(const struct gl_context
*ctx
, GLenum factor
)
87 case GL_ONE_MINUS_DST_COLOR
:
91 case GL_ONE_MINUS_SRC_COLOR
:
93 case GL_ONE_MINUS_SRC_ALPHA
:
95 case GL_ONE_MINUS_DST_ALPHA
:
97 case GL_CONSTANT_COLOR
:
98 case GL_ONE_MINUS_CONSTANT_COLOR
:
99 case GL_CONSTANT_ALPHA
:
100 case GL_ONE_MINUS_CONSTANT_ALPHA
:
101 return _mesa_is_desktop_gl(ctx
) || ctx
->API
== API_OPENGLES2
;
102 case GL_SRC_ALPHA_SATURATE
:
103 return (_mesa_is_desktop_gl(ctx
)
104 && ctx
->Extensions
.ARB_blend_func_extended
)
105 || _mesa_is_gles3(ctx
);
108 case GL_ONE_MINUS_SRC1_COLOR
:
109 case GL_ONE_MINUS_SRC1_ALPHA
:
110 return _mesa_is_desktop_gl(ctx
)
111 && ctx
->Extensions
.ARB_blend_func_extended
;
119 * Check if src/dest RGB/A blend factors are legal. If not generate
121 * \return GL_TRUE if factors are legal, GL_FALSE otherwise.
124 validate_blend_factors(struct gl_context
*ctx
, const char *func
,
125 GLenum sfactorRGB
, GLenum dfactorRGB
,
126 GLenum sfactorA
, GLenum dfactorA
)
128 if (!legal_src_factor(ctx
, sfactorRGB
)) {
129 _mesa_error(ctx
, GL_INVALID_ENUM
,
130 "%s(sfactorRGB = %s)", func
,
131 _mesa_enum_to_string(sfactorRGB
));
135 if (!legal_dst_factor(ctx
, dfactorRGB
)) {
136 _mesa_error(ctx
, GL_INVALID_ENUM
,
137 "%s(dfactorRGB = %s)", func
,
138 _mesa_enum_to_string(dfactorRGB
));
142 if (sfactorA
!= sfactorRGB
&& !legal_src_factor(ctx
, sfactorA
)) {
143 _mesa_error(ctx
, GL_INVALID_ENUM
,
144 "%s(sfactorA = %s)", func
,
145 _mesa_enum_to_string(sfactorA
));
149 if (dfactorA
!= dfactorRGB
&& !legal_dst_factor(ctx
, dfactorA
)) {
150 _mesa_error(ctx
, GL_INVALID_ENUM
,
151 "%s(dfactorA = %s)", func
,
152 _mesa_enum_to_string(dfactorA
));
161 * Specify the blending operation.
163 * \param sfactor source factor operator.
164 * \param dfactor destination factor operator.
166 * \sa glBlendFunc, glBlendFuncSeparateEXT
169 _mesa_BlendFunc( GLenum sfactor
, GLenum dfactor
)
171 _mesa_BlendFuncSeparate(sfactor
, dfactor
, sfactor
, dfactor
);
175 blend_factor_is_dual_src(GLenum factor
)
177 return (factor
== GL_SRC1_COLOR
||
178 factor
== GL_SRC1_ALPHA
||
179 factor
== GL_ONE_MINUS_SRC1_COLOR
||
180 factor
== GL_ONE_MINUS_SRC1_ALPHA
);
184 update_uses_dual_src(struct gl_context
*ctx
, int buf
)
186 ctx
->Color
.Blend
[buf
]._UsesDualSrc
=
187 (blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].SrcRGB
) ||
188 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].DstRGB
) ||
189 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].SrcA
) ||
190 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].DstA
));
194 * Set the separate blend source/dest factors for all draw buffers.
196 * \param sfactorRGB RGB source factor operator.
197 * \param dfactorRGB RGB destination factor operator.
198 * \param sfactorA alpha source factor operator.
199 * \param dfactorA alpha destination factor operator.
202 _mesa_BlendFuncSeparate( GLenum sfactorRGB
, GLenum dfactorRGB
,
203 GLenum sfactorA
, GLenum dfactorA
)
205 GLuint buf
, numBuffers
;
206 bool changed
= false;
207 GET_CURRENT_CONTEXT(ctx
);
209 if (MESA_VERBOSE
& VERBOSE_API
)
210 _mesa_debug(ctx
, "glBlendFuncSeparate %s %s %s %s\n",
211 _mesa_enum_to_string(sfactorRGB
),
212 _mesa_enum_to_string(dfactorRGB
),
213 _mesa_enum_to_string(sfactorA
),
214 _mesa_enum_to_string(dfactorA
));
216 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
217 ? ctx
->Const
.MaxDrawBuffers
: 1;
219 /* Check if we're really changing any state. If not, return early. */
220 if (ctx
->Color
._BlendFuncPerBuffer
) {
221 /* Check all per-buffer states */
222 for (buf
= 0; buf
< numBuffers
; buf
++) {
223 if (ctx
->Color
.Blend
[buf
].SrcRGB
!= sfactorRGB
||
224 ctx
->Color
.Blend
[buf
].DstRGB
!= dfactorRGB
||
225 ctx
->Color
.Blend
[buf
].SrcA
!= sfactorA
||
226 ctx
->Color
.Blend
[buf
].DstA
!= dfactorA
) {
233 /* only need to check 0th per-buffer state */
234 if (ctx
->Color
.Blend
[0].SrcRGB
!= sfactorRGB
||
235 ctx
->Color
.Blend
[0].DstRGB
!= dfactorRGB
||
236 ctx
->Color
.Blend
[0].SrcA
!= sfactorA
||
237 ctx
->Color
.Blend
[0].DstA
!= dfactorA
) {
245 if (!validate_blend_factors(ctx
, "glBlendFuncSeparate",
246 sfactorRGB
, dfactorRGB
,
247 sfactorA
, dfactorA
)) {
251 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
253 for (buf
= 0; buf
< numBuffers
; buf
++) {
254 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
255 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
256 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
257 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
258 update_uses_dual_src(ctx
, buf
);
260 ctx
->Color
._BlendFuncPerBuffer
= GL_FALSE
;
262 if (ctx
->Driver
.BlendFuncSeparate
) {
263 ctx
->Driver
.BlendFuncSeparate(ctx
, sfactorRGB
, dfactorRGB
,
270 * Set blend source/dest factors for one color buffer/target.
273 _mesa_BlendFunciARB(GLuint buf
, GLenum sfactor
, GLenum dfactor
)
275 _mesa_BlendFuncSeparateiARB(buf
, sfactor
, dfactor
, sfactor
, dfactor
);
280 * Set separate blend source/dest factors for one color buffer/target.
283 _mesa_BlendFuncSeparateiARB(GLuint buf
, GLenum sfactorRGB
, GLenum dfactorRGB
,
284 GLenum sfactorA
, GLenum dfactorA
)
286 GET_CURRENT_CONTEXT(ctx
);
288 if (!ctx
->Extensions
.ARB_draw_buffers_blend
) {
289 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlendFunc[Separate]i()");
293 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
294 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
299 if (!validate_blend_factors(ctx
, "glBlendFuncSeparatei",
300 sfactorRGB
, dfactorRGB
,
301 sfactorA
, dfactorA
)) {
305 if (ctx
->Color
.Blend
[buf
].SrcRGB
== sfactorRGB
&&
306 ctx
->Color
.Blend
[buf
].DstRGB
== dfactorRGB
&&
307 ctx
->Color
.Blend
[buf
].SrcA
== sfactorA
&&
308 ctx
->Color
.Blend
[buf
].DstA
== dfactorA
)
309 return; /* no change */
311 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
313 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
314 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
315 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
316 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
317 update_uses_dual_src(ctx
, buf
);
318 ctx
->Color
._BlendFuncPerBuffer
= GL_TRUE
;
323 * Check if given blend equation is legal.
324 * \return GL_TRUE if legal, GL_FALSE otherwise.
327 legal_blend_equation(const struct gl_context
*ctx
, GLenum mode
)
331 case GL_FUNC_SUBTRACT
:
332 case GL_FUNC_REVERSE_SUBTRACT
:
336 return ctx
->Extensions
.EXT_blend_minmax
;
343 /* This is really an extension function! */
345 _mesa_BlendEquation( GLenum mode
)
347 GLuint buf
, numBuffers
;
348 bool changed
= false;
349 GET_CURRENT_CONTEXT(ctx
);
351 if (MESA_VERBOSE
& VERBOSE_API
)
352 _mesa_debug(ctx
, "glBlendEquation(%s)\n",
353 _mesa_enum_to_string(mode
));
355 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
356 ? ctx
->Const
.MaxDrawBuffers
: 1;
358 if (ctx
->Color
._BlendEquationPerBuffer
) {
359 /* Check all per-buffer states */
360 for (buf
= 0; buf
< numBuffers
; buf
++) {
361 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= mode
||
362 ctx
->Color
.Blend
[buf
].EquationA
!= mode
) {
369 /* only need to check 0th per-buffer state */
370 if (ctx
->Color
.Blend
[0].EquationRGB
!= mode
||
371 ctx
->Color
.Blend
[0].EquationA
!= mode
) {
379 if (!legal_blend_equation(ctx
, mode
)) {
380 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
384 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
386 for (buf
= 0; buf
< numBuffers
; buf
++) {
387 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
388 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
390 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
392 if (ctx
->Driver
.BlendEquationSeparate
)
393 (*ctx
->Driver
.BlendEquationSeparate
)( ctx
, mode
, mode
);
398 * Set blend equation for one color buffer/target.
401 _mesa_BlendEquationiARB(GLuint buf
, GLenum mode
)
403 GET_CURRENT_CONTEXT(ctx
);
405 if (MESA_VERBOSE
& VERBOSE_API
)
406 _mesa_debug(ctx
, "glBlendEquationi(%u, %s)\n",
407 buf
, _mesa_enum_to_string(mode
));
409 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
410 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
415 if (!legal_blend_equation(ctx
, mode
)) {
416 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationi");
420 if (ctx
->Color
.Blend
[buf
].EquationRGB
== mode
&&
421 ctx
->Color
.Blend
[buf
].EquationA
== mode
)
422 return; /* no change */
424 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
425 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
426 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
427 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
432 _mesa_BlendEquationSeparate( GLenum modeRGB
, GLenum modeA
)
434 GLuint buf
, numBuffers
;
435 bool changed
= false;
436 GET_CURRENT_CONTEXT(ctx
);
438 if (MESA_VERBOSE
& VERBOSE_API
)
439 _mesa_debug(ctx
, "glBlendEquationSeparateEXT(%s %s)\n",
440 _mesa_enum_to_string(modeRGB
),
441 _mesa_enum_to_string(modeA
));
443 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
444 ? ctx
->Const
.MaxDrawBuffers
: 1;
446 if (ctx
->Color
._BlendEquationPerBuffer
) {
447 /* Check all per-buffer states */
448 for (buf
= 0; buf
< numBuffers
; buf
++) {
449 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= modeRGB
||
450 ctx
->Color
.Blend
[buf
].EquationA
!= modeA
) {
457 /* only need to check 0th per-buffer state */
458 if (ctx
->Color
.Blend
[0].EquationRGB
!= modeRGB
||
459 ctx
->Color
.Blend
[0].EquationA
!= modeA
) {
467 if ( (modeRGB
!= modeA
) && !ctx
->Extensions
.EXT_blend_equation_separate
) {
468 _mesa_error(ctx
, GL_INVALID_OPERATION
,
469 "glBlendEquationSeparateEXT not supported by driver");
473 if (!legal_blend_equation(ctx
, modeRGB
)) {
474 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeRGB)");
478 if (!legal_blend_equation(ctx
, modeA
)) {
479 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeA)");
483 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
485 for (buf
= 0; buf
< numBuffers
; buf
++) {
486 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
487 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
489 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
491 if (ctx
->Driver
.BlendEquationSeparate
)
492 ctx
->Driver
.BlendEquationSeparate(ctx
, modeRGB
, modeA
);
497 * Set separate blend equations for one color buffer/target.
500 _mesa_BlendEquationSeparateiARB(GLuint buf
, GLenum modeRGB
, GLenum modeA
)
502 GET_CURRENT_CONTEXT(ctx
);
504 if (MESA_VERBOSE
& VERBOSE_API
)
505 _mesa_debug(ctx
, "glBlendEquationSeparatei(%u, %s %s)\n", buf
,
506 _mesa_enum_to_string(modeRGB
),
507 _mesa_enum_to_string(modeA
));
509 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
510 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendEquationSeparatei(buffer=%u)",
515 if (!legal_blend_equation(ctx
, modeRGB
)) {
516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeRGB)");
520 if (!legal_blend_equation(ctx
, modeA
)) {
521 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeA)");
525 if (ctx
->Color
.Blend
[buf
].EquationRGB
== modeRGB
&&
526 ctx
->Color
.Blend
[buf
].EquationA
== modeA
)
527 return; /* no change */
529 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
530 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
531 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
532 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
537 * Set the blending color.
539 * \param red red color component.
540 * \param green green color component.
541 * \param blue blue color component.
542 * \param alpha alpha color component.
544 * \sa glBlendColor().
546 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
547 * change, flushes the vertices and notifies the driver via
548 * dd_function_table::BlendColor callback.
551 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
554 GET_CURRENT_CONTEXT(ctx
);
561 if (TEST_EQ_4V(tmp
, ctx
->Color
.BlendColorUnclamped
))
564 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
565 COPY_4FV( ctx
->Color
.BlendColorUnclamped
, tmp
);
567 ctx
->Color
.BlendColor
[0] = CLAMP(tmp
[0], 0.0F
, 1.0F
);
568 ctx
->Color
.BlendColor
[1] = CLAMP(tmp
[1], 0.0F
, 1.0F
);
569 ctx
->Color
.BlendColor
[2] = CLAMP(tmp
[2], 0.0F
, 1.0F
);
570 ctx
->Color
.BlendColor
[3] = CLAMP(tmp
[3], 0.0F
, 1.0F
);
572 if (ctx
->Driver
.BlendColor
)
573 (*ctx
->Driver
.BlendColor
)(ctx
, ctx
->Color
.BlendColor
);
578 * Specify the alpha test function.
580 * \param func alpha comparison function.
581 * \param ref reference value.
583 * Verifies the parameters and updates gl_colorbuffer_attrib.
584 * On a change, flushes the vertices and notifies the driver via
585 * dd_function_table::AlphaFunc callback.
588 _mesa_AlphaFunc( GLenum func
, GLclampf ref
)
590 GET_CURRENT_CONTEXT(ctx
);
592 if (MESA_VERBOSE
& VERBOSE_API
)
593 _mesa_debug(ctx
, "glAlphaFunc(%s, %f)\n",
594 _mesa_enum_to_string(func
), ref
);
596 if (ctx
->Color
.AlphaFunc
== func
&& ctx
->Color
.AlphaRefUnclamped
== ref
)
597 return; /* no change */
608 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
609 ctx
->Color
.AlphaFunc
= func
;
610 ctx
->Color
.AlphaRefUnclamped
= ref
;
611 ctx
->Color
.AlphaRef
= CLAMP(ref
, 0.0F
, 1.0F
);
613 if (ctx
->Driver
.AlphaFunc
)
614 ctx
->Driver
.AlphaFunc(ctx
, func
, ctx
->Color
.AlphaRef
);
618 _mesa_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
625 * Specify a logic pixel operation for color index rendering.
627 * \param opcode operation.
629 * Verifies that \p opcode is a valid enum and updates
630 gl_colorbuffer_attrib::LogicOp.
631 * On a change, flushes the vertices and notifies the driver via the
632 * dd_function_table::LogicOpcode callback.
635 _mesa_LogicOp( GLenum opcode
)
637 GET_CURRENT_CONTEXT(ctx
);
639 if (MESA_VERBOSE
& VERBOSE_API
)
640 _mesa_debug(ctx
, "glLogicOp(%s)\n", _mesa_enum_to_string(opcode
));
646 case GL_COPY_INVERTED
:
656 case GL_AND_INVERTED
:
661 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLogicOp" );
665 if (ctx
->Color
.LogicOp
== opcode
)
668 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
669 ctx
->Color
.LogicOp
= opcode
;
671 if (ctx
->Driver
.LogicOpcode
)
672 ctx
->Driver
.LogicOpcode( ctx
, opcode
);
677 _mesa_IndexMask( GLuint mask
)
679 GET_CURRENT_CONTEXT(ctx
);
681 if (ctx
->Color
.IndexMask
== mask
)
684 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
685 ctx
->Color
.IndexMask
= mask
;
690 * Enable or disable writing of frame buffer color components.
692 * \param red whether to mask writing of the red color component.
693 * \param green whether to mask writing of the green color component.
694 * \param blue whether to mask writing of the blue color component.
695 * \param alpha whether to mask writing of the alpha color component.
699 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
700 * change, flushes the vertices and notifies the driver via the
701 * dd_function_table::ColorMask callback.
704 _mesa_ColorMask( GLboolean red
, GLboolean green
,
705 GLboolean blue
, GLboolean alpha
)
707 GET_CURRENT_CONTEXT(ctx
);
712 if (MESA_VERBOSE
& VERBOSE_API
)
713 _mesa_debug(ctx
, "glColorMask(%d, %d, %d, %d)\n",
714 red
, green
, blue
, alpha
);
716 /* Shouldn't have any information about channel depth in core mesa
717 * -- should probably store these as the native booleans:
719 tmp
[RCOMP
] = red
? 0xff : 0x0;
720 tmp
[GCOMP
] = green
? 0xff : 0x0;
721 tmp
[BCOMP
] = blue
? 0xff : 0x0;
722 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
725 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
726 if (!TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[i
])) {
728 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
731 COPY_4UBV(ctx
->Color
.ColorMask
[i
], tmp
);
735 if (ctx
->Driver
.ColorMask
)
736 ctx
->Driver
.ColorMask( ctx
, red
, green
, blue
, alpha
);
741 * For GL_EXT_draw_buffers2 and GL3
744 _mesa_ColorMaski( GLuint buf
, GLboolean red
, GLboolean green
,
745 GLboolean blue
, GLboolean alpha
)
748 GET_CURRENT_CONTEXT(ctx
);
750 if (MESA_VERBOSE
& VERBOSE_API
)
751 _mesa_debug(ctx
, "glColorMaskIndexed %u %d %d %d %d\n",
752 buf
, red
, green
, blue
, alpha
);
754 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
755 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorMaskIndexed(buf=%u)", buf
);
759 /* Shouldn't have any information about channel depth in core mesa
760 * -- should probably store these as the native booleans:
762 tmp
[RCOMP
] = red
? 0xff : 0x0;
763 tmp
[GCOMP
] = green
? 0xff : 0x0;
764 tmp
[BCOMP
] = blue
? 0xff : 0x0;
765 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
767 if (TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[buf
]))
770 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
771 COPY_4UBV(ctx
->Color
.ColorMask
[buf
], tmp
);
776 _mesa_ClampColor(GLenum target
, GLenum clamp
)
778 GET_CURRENT_CONTEXT(ctx
);
780 if (clamp
!= GL_TRUE
&& clamp
!= GL_FALSE
&& clamp
!= GL_FIXED_ONLY_ARB
) {
781 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColorARB(clamp)");
786 case GL_CLAMP_VERTEX_COLOR_ARB
:
787 if (ctx
->API
== API_OPENGL_CORE
&&
788 !ctx
->Extensions
.ARB_color_buffer_float
) {
791 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
792 ctx
->Light
.ClampVertexColor
= clamp
;
793 _mesa_update_clamp_vertex_color(ctx
, ctx
->DrawBuffer
);
795 case GL_CLAMP_FRAGMENT_COLOR_ARB
:
796 if (ctx
->API
== API_OPENGL_CORE
&&
797 !ctx
->Extensions
.ARB_color_buffer_float
) {
800 FLUSH_VERTICES(ctx
, _NEW_FRAG_CLAMP
);
801 ctx
->Color
.ClampFragmentColor
= clamp
;
802 _mesa_update_clamp_fragment_color(ctx
, ctx
->DrawBuffer
);
804 case GL_CLAMP_READ_COLOR_ARB
:
805 ctx
->Color
.ClampReadColor
= clamp
;
813 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColor(%s)",
814 _mesa_enum_to_string(target
));
818 get_clamp_color(const struct gl_framebuffer
*fb
, GLenum clamp
)
820 if (clamp
== GL_TRUE
|| clamp
== GL_FALSE
)
823 assert(clamp
== GL_FIXED_ONLY
);
827 return fb
->_AllColorBuffersFixedPoint
;
831 _mesa_get_clamp_fragment_color(const struct gl_context
*ctx
,
832 const struct gl_framebuffer
*drawFb
)
834 return get_clamp_color(drawFb
, ctx
->Color
.ClampFragmentColor
);
838 _mesa_get_clamp_vertex_color(const struct gl_context
*ctx
,
839 const struct gl_framebuffer
*drawFb
)
841 return get_clamp_color(drawFb
, ctx
->Light
.ClampVertexColor
);
845 _mesa_get_clamp_read_color(const struct gl_context
*ctx
,
846 const struct gl_framebuffer
*readFb
)
848 return get_clamp_color(readFb
, ctx
->Color
.ClampReadColor
);
852 * Update the ctx->Color._ClampFragmentColor field
855 _mesa_update_clamp_fragment_color(struct gl_context
*ctx
,
856 const struct gl_framebuffer
*drawFb
)
859 * - there is no colorbuffer
860 * - all colorbuffers are unsigned normalized, so clamping has no effect
861 * - there is an integer colorbuffer
863 if (!drawFb
|| !drawFb
->_HasSNormOrFloatColorBuffer
||
864 drawFb
->_IntegerColor
)
865 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
867 ctx
->Color
._ClampFragmentColor
=
868 _mesa_get_clamp_fragment_color(ctx
, drawFb
);
872 * Update the ctx->Color._ClampVertexColor field
875 _mesa_update_clamp_vertex_color(struct gl_context
*ctx
,
876 const struct gl_framebuffer
*drawFb
)
878 ctx
->Light
._ClampVertexColor
=
879 _mesa_get_clamp_vertex_color(ctx
, drawFb
);
883 * Returns an appropriate mesa_format for color rendering based on the
884 * GL_FRAMEBUFFER_SRGB state.
886 * Some drivers implement GL_FRAMEBUFFER_SRGB using a flag on the blend state
887 * (which GL_FRAMEBUFFER_SRGB maps to reasonably), but some have to do so by
888 * overriding the format of the surface. This is a helper for doing the
889 * surface format override variant.
892 _mesa_get_render_format(const struct gl_context
*ctx
, mesa_format format
)
894 if (ctx
->Color
.sRGBEnabled
)
897 return _mesa_get_srgb_format_linear(format
);
900 /**********************************************************************/
901 /** \name Initialization */
905 * Initialization of the context's Color attribute group.
907 * \param ctx GL context.
909 * Initializes the related fields in the context color attribute group,
910 * __struct gl_contextRec::Color.
912 void _mesa_init_color( struct gl_context
* ctx
)
916 /* Color buffer group */
917 ctx
->Color
.IndexMask
= ~0u;
918 memset(ctx
->Color
.ColorMask
, 0xff, sizeof(ctx
->Color
.ColorMask
));
919 ctx
->Color
.ClearIndex
= 0;
920 ASSIGN_4V( ctx
->Color
.ClearColor
.f
, 0, 0, 0, 0 );
921 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
922 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
923 ctx
->Color
.AlphaRef
= 0;
924 ctx
->Color
.BlendEnabled
= 0x0;
925 for (i
= 0; i
< ARRAY_SIZE(ctx
->Color
.Blend
); i
++) {
926 ctx
->Color
.Blend
[i
].SrcRGB
= GL_ONE
;
927 ctx
->Color
.Blend
[i
].DstRGB
= GL_ZERO
;
928 ctx
->Color
.Blend
[i
].SrcA
= GL_ONE
;
929 ctx
->Color
.Blend
[i
].DstA
= GL_ZERO
;
930 ctx
->Color
.Blend
[i
].EquationRGB
= GL_FUNC_ADD
;
931 ctx
->Color
.Blend
[i
].EquationA
= GL_FUNC_ADD
;
933 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
934 ASSIGN_4V( ctx
->Color
.BlendColorUnclamped
, 0.0, 0.0, 0.0, 0.0 );
935 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
936 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
937 ctx
->Color
.LogicOp
= GL_COPY
;
938 ctx
->Color
.DitherFlag
= GL_TRUE
;
940 /* GL_FRONT is not possible on GLES. Instead GL_BACK will render to either
941 * the front or the back buffer depending on the config */
942 if (ctx
->Visual
.doubleBufferMode
|| _mesa_is_gles(ctx
)) {
943 ctx
->Color
.DrawBuffer
[0] = GL_BACK
;
946 ctx
->Color
.DrawBuffer
[0] = GL_FRONT
;
949 ctx
->Color
.ClampFragmentColor
= ctx
->API
== API_OPENGL_COMPAT
?
950 GL_FIXED_ONLY_ARB
: GL_FALSE
;
951 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
952 ctx
->Color
.ClampReadColor
= GL_FIXED_ONLY_ARB
;
954 /* GLES 1/2/3 behaves as though GL_FRAMEBUFFER_SRGB is always enabled
955 * if EGL_KHR_gl_colorspace has been used to request sRGB.
957 ctx
->Color
.sRGBEnabled
= _mesa_is_gles(ctx
);