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
;
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 if ( (modeRGB
!= modeA
) && !ctx
->Extensions
.EXT_blend_equation_separate
) {
444 _mesa_error(ctx
, GL_INVALID_OPERATION
,
445 "glBlendEquationSeparateEXT not supported by driver");
449 if (!legal_blend_equation(ctx
, modeRGB
)) {
450 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeRGB)");
454 if (!legal_blend_equation(ctx
, modeA
)) {
455 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeA)");
459 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
460 ? ctx
->Const
.MaxDrawBuffers
: 1;
463 for (buf
= 0; buf
< numBuffers
; buf
++) {
464 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= modeRGB
||
465 ctx
->Color
.Blend
[buf
].EquationA
!= modeA
) {
473 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
474 for (buf
= 0; buf
< numBuffers
; buf
++) {
475 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
476 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
478 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
480 if (ctx
->Driver
.BlendEquationSeparate
)
481 ctx
->Driver
.BlendEquationSeparate(ctx
, modeRGB
, modeA
);
486 * Set separate blend equations for one color buffer/target.
489 _mesa_BlendEquationSeparateiARB(GLuint buf
, GLenum modeRGB
, GLenum modeA
)
491 GET_CURRENT_CONTEXT(ctx
);
493 if (MESA_VERBOSE
& VERBOSE_API
)
494 _mesa_debug(ctx
, "glBlendEquationSeparatei(%u, %s %s)\n", buf
,
495 _mesa_enum_to_string(modeRGB
),
496 _mesa_enum_to_string(modeA
));
498 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
499 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendEquationSeparatei(buffer=%u)",
504 if (!legal_blend_equation(ctx
, modeRGB
)) {
505 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeRGB)");
509 if (!legal_blend_equation(ctx
, modeA
)) {
510 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeA)");
514 if (ctx
->Color
.Blend
[buf
].EquationRGB
== modeRGB
&&
515 ctx
->Color
.Blend
[buf
].EquationA
== modeA
)
516 return; /* no change */
518 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
519 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
520 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
521 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
526 * Set the blending color.
528 * \param red red color component.
529 * \param green green color component.
530 * \param blue blue color component.
531 * \param alpha alpha color component.
533 * \sa glBlendColor().
535 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
536 * change, flushes the vertices and notifies the driver via
537 * dd_function_table::BlendColor callback.
540 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
543 GET_CURRENT_CONTEXT(ctx
);
550 if (TEST_EQ_4V(tmp
, ctx
->Color
.BlendColorUnclamped
))
553 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
554 COPY_4FV( ctx
->Color
.BlendColorUnclamped
, tmp
);
556 ctx
->Color
.BlendColor
[0] = CLAMP(tmp
[0], 0.0F
, 1.0F
);
557 ctx
->Color
.BlendColor
[1] = CLAMP(tmp
[1], 0.0F
, 1.0F
);
558 ctx
->Color
.BlendColor
[2] = CLAMP(tmp
[2], 0.0F
, 1.0F
);
559 ctx
->Color
.BlendColor
[3] = CLAMP(tmp
[3], 0.0F
, 1.0F
);
561 if (ctx
->Driver
.BlendColor
)
562 (*ctx
->Driver
.BlendColor
)(ctx
, ctx
->Color
.BlendColor
);
567 * Specify the alpha test function.
569 * \param func alpha comparison function.
570 * \param ref reference value.
572 * Verifies the parameters and updates gl_colorbuffer_attrib.
573 * On a change, flushes the vertices and notifies the driver via
574 * dd_function_table::AlphaFunc callback.
577 _mesa_AlphaFunc( GLenum func
, GLclampf ref
)
579 GET_CURRENT_CONTEXT(ctx
);
581 if (MESA_VERBOSE
& VERBOSE_API
)
582 _mesa_debug(ctx
, "glAlphaFunc(%s, %f)\n",
583 _mesa_enum_to_string(func
), ref
);
585 if (ctx
->Color
.AlphaFunc
== func
&& ctx
->Color
.AlphaRefUnclamped
== ref
)
586 return; /* no change */
597 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
598 ctx
->Color
.AlphaFunc
= func
;
599 ctx
->Color
.AlphaRefUnclamped
= ref
;
600 ctx
->Color
.AlphaRef
= CLAMP(ref
, 0.0F
, 1.0F
);
602 if (ctx
->Driver
.AlphaFunc
)
603 ctx
->Driver
.AlphaFunc(ctx
, func
, ctx
->Color
.AlphaRef
);
607 _mesa_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
614 * Specify a logic pixel operation for color index rendering.
616 * \param opcode operation.
618 * Verifies that \p opcode is a valid enum and updates
619 gl_colorbuffer_attrib::LogicOp.
620 * On a change, flushes the vertices and notifies the driver via the
621 * dd_function_table::LogicOpcode callback.
624 _mesa_LogicOp( GLenum opcode
)
626 GET_CURRENT_CONTEXT(ctx
);
628 if (MESA_VERBOSE
& VERBOSE_API
)
629 _mesa_debug(ctx
, "glLogicOp(%s)\n", _mesa_enum_to_string(opcode
));
635 case GL_COPY_INVERTED
:
645 case GL_AND_INVERTED
:
650 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLogicOp" );
654 if (ctx
->Color
.LogicOp
== opcode
)
657 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
658 ctx
->Color
.LogicOp
= opcode
;
660 if (ctx
->Driver
.LogicOpcode
)
661 ctx
->Driver
.LogicOpcode( ctx
, opcode
);
666 _mesa_IndexMask( GLuint mask
)
668 GET_CURRENT_CONTEXT(ctx
);
670 if (ctx
->Color
.IndexMask
== mask
)
673 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
674 ctx
->Color
.IndexMask
= mask
;
679 * Enable or disable writing of frame buffer color components.
681 * \param red whether to mask writing of the red color component.
682 * \param green whether to mask writing of the green color component.
683 * \param blue whether to mask writing of the blue color component.
684 * \param alpha whether to mask writing of the alpha color component.
688 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
689 * change, flushes the vertices and notifies the driver via the
690 * dd_function_table::ColorMask callback.
693 _mesa_ColorMask( GLboolean red
, GLboolean green
,
694 GLboolean blue
, GLboolean alpha
)
696 GET_CURRENT_CONTEXT(ctx
);
701 if (MESA_VERBOSE
& VERBOSE_API
)
702 _mesa_debug(ctx
, "glColorMask(%d, %d, %d, %d)\n",
703 red
, green
, blue
, alpha
);
705 /* Shouldn't have any information about channel depth in core mesa
706 * -- should probably store these as the native booleans:
708 tmp
[RCOMP
] = red
? 0xff : 0x0;
709 tmp
[GCOMP
] = green
? 0xff : 0x0;
710 tmp
[BCOMP
] = blue
? 0xff : 0x0;
711 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
714 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
715 if (!TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[i
])) {
717 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
720 COPY_4UBV(ctx
->Color
.ColorMask
[i
], tmp
);
724 if (ctx
->Driver
.ColorMask
)
725 ctx
->Driver
.ColorMask( ctx
, red
, green
, blue
, alpha
);
730 * For GL_EXT_draw_buffers2 and GL3
733 _mesa_ColorMaski( GLuint buf
, GLboolean red
, GLboolean green
,
734 GLboolean blue
, GLboolean alpha
)
737 GET_CURRENT_CONTEXT(ctx
);
739 if (MESA_VERBOSE
& VERBOSE_API
)
740 _mesa_debug(ctx
, "glColorMaskIndexed %u %d %d %d %d\n",
741 buf
, red
, green
, blue
, alpha
);
743 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
744 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorMaskIndexed(buf=%u)", buf
);
748 /* Shouldn't have any information about channel depth in core mesa
749 * -- should probably store these as the native booleans:
751 tmp
[RCOMP
] = red
? 0xff : 0x0;
752 tmp
[GCOMP
] = green
? 0xff : 0x0;
753 tmp
[BCOMP
] = blue
? 0xff : 0x0;
754 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
756 if (TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[buf
]))
759 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
760 COPY_4UBV(ctx
->Color
.ColorMask
[buf
], tmp
);
765 _mesa_ClampColor(GLenum target
, GLenum clamp
)
767 GET_CURRENT_CONTEXT(ctx
);
769 if (clamp
!= GL_TRUE
&& clamp
!= GL_FALSE
&& clamp
!= GL_FIXED_ONLY_ARB
) {
770 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColorARB(clamp)");
775 case GL_CLAMP_VERTEX_COLOR_ARB
:
776 if (ctx
->API
== API_OPENGL_CORE
&&
777 !ctx
->Extensions
.ARB_color_buffer_float
) {
780 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
781 ctx
->Light
.ClampVertexColor
= clamp
;
782 _mesa_update_clamp_vertex_color(ctx
, ctx
->DrawBuffer
);
784 case GL_CLAMP_FRAGMENT_COLOR_ARB
:
785 if (ctx
->API
== API_OPENGL_CORE
&&
786 !ctx
->Extensions
.ARB_color_buffer_float
) {
789 FLUSH_VERTICES(ctx
, _NEW_FRAG_CLAMP
);
790 ctx
->Color
.ClampFragmentColor
= clamp
;
791 _mesa_update_clamp_fragment_color(ctx
, ctx
->DrawBuffer
);
793 case GL_CLAMP_READ_COLOR_ARB
:
794 ctx
->Color
.ClampReadColor
= clamp
;
802 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColor(%s)",
803 _mesa_enum_to_string(target
));
807 get_clamp_color(const struct gl_framebuffer
*fb
, GLenum clamp
)
809 if (clamp
== GL_TRUE
|| clamp
== GL_FALSE
)
812 assert(clamp
== GL_FIXED_ONLY
);
816 return fb
->_AllColorBuffersFixedPoint
;
820 _mesa_get_clamp_fragment_color(const struct gl_context
*ctx
,
821 const struct gl_framebuffer
*drawFb
)
823 return get_clamp_color(drawFb
, ctx
->Color
.ClampFragmentColor
);
827 _mesa_get_clamp_vertex_color(const struct gl_context
*ctx
,
828 const struct gl_framebuffer
*drawFb
)
830 return get_clamp_color(drawFb
, ctx
->Light
.ClampVertexColor
);
834 _mesa_get_clamp_read_color(const struct gl_context
*ctx
,
835 const struct gl_framebuffer
*readFb
)
837 return get_clamp_color(readFb
, ctx
->Color
.ClampReadColor
);
841 * Update the ctx->Color._ClampFragmentColor field
844 _mesa_update_clamp_fragment_color(struct gl_context
*ctx
,
845 const struct gl_framebuffer
*drawFb
)
848 * - there is no colorbuffer
849 * - all colorbuffers are unsigned normalized, so clamping has no effect
850 * - there is an integer colorbuffer
852 if (!drawFb
|| !drawFb
->_HasSNormOrFloatColorBuffer
||
853 drawFb
->_IntegerColor
)
854 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
856 ctx
->Color
._ClampFragmentColor
=
857 _mesa_get_clamp_fragment_color(ctx
, drawFb
);
861 * Update the ctx->Color._ClampVertexColor field
864 _mesa_update_clamp_vertex_color(struct gl_context
*ctx
,
865 const struct gl_framebuffer
*drawFb
)
867 ctx
->Light
._ClampVertexColor
=
868 _mesa_get_clamp_vertex_color(ctx
, drawFb
);
872 * Returns an appropriate mesa_format for color rendering based on the
873 * GL_FRAMEBUFFER_SRGB state.
875 * Some drivers implement GL_FRAMEBUFFER_SRGB using a flag on the blend state
876 * (which GL_FRAMEBUFFER_SRGB maps to reasonably), but some have to do so by
877 * overriding the format of the surface. This is a helper for doing the
878 * surface format override variant.
881 _mesa_get_render_format(const struct gl_context
*ctx
, mesa_format format
)
883 if (ctx
->Color
.sRGBEnabled
)
886 return _mesa_get_srgb_format_linear(format
);
889 /**********************************************************************/
890 /** \name Initialization */
894 * Initialization of the context's Color attribute group.
896 * \param ctx GL context.
898 * Initializes the related fields in the context color attribute group,
899 * __struct gl_contextRec::Color.
901 void _mesa_init_color( struct gl_context
* ctx
)
905 /* Color buffer group */
906 ctx
->Color
.IndexMask
= ~0u;
907 memset(ctx
->Color
.ColorMask
, 0xff, sizeof(ctx
->Color
.ColorMask
));
908 ctx
->Color
.ClearIndex
= 0;
909 ASSIGN_4V( ctx
->Color
.ClearColor
.f
, 0, 0, 0, 0 );
910 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
911 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
912 ctx
->Color
.AlphaRef
= 0;
913 ctx
->Color
.BlendEnabled
= 0x0;
914 for (i
= 0; i
< ARRAY_SIZE(ctx
->Color
.Blend
); i
++) {
915 ctx
->Color
.Blend
[i
].SrcRGB
= GL_ONE
;
916 ctx
->Color
.Blend
[i
].DstRGB
= GL_ZERO
;
917 ctx
->Color
.Blend
[i
].SrcA
= GL_ONE
;
918 ctx
->Color
.Blend
[i
].DstA
= GL_ZERO
;
919 ctx
->Color
.Blend
[i
].EquationRGB
= GL_FUNC_ADD
;
920 ctx
->Color
.Blend
[i
].EquationA
= GL_FUNC_ADD
;
922 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
923 ASSIGN_4V( ctx
->Color
.BlendColorUnclamped
, 0.0, 0.0, 0.0, 0.0 );
924 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
925 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
926 ctx
->Color
.LogicOp
= GL_COPY
;
927 ctx
->Color
.DitherFlag
= GL_TRUE
;
929 /* GL_FRONT is not possible on GLES. Instead GL_BACK will render to either
930 * the front or the back buffer depending on the config */
931 if (ctx
->Visual
.doubleBufferMode
|| _mesa_is_gles(ctx
)) {
932 ctx
->Color
.DrawBuffer
[0] = GL_BACK
;
935 ctx
->Color
.DrawBuffer
[0] = GL_FRONT
;
938 ctx
->Color
.ClampFragmentColor
= ctx
->API
== API_OPENGL_COMPAT
?
939 GL_FIXED_ONLY_ARB
: GL_FALSE
;
940 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
941 ctx
->Color
.ClampReadColor
= GL_FIXED_ONLY_ARB
;
943 /* GLES 1/2/3 behaves as though GL_FRAMEBUFFER_SRGB is always enabled
944 * if EGL_KHR_gl_colorspace has been used to request sRGB.
946 ctx
->Color
.sRGBEnabled
= _mesa_is_gles(ctx
);