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
;
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 if (!validate_blend_factors(ctx
, "glBlendFuncSeparate",
217 sfactorRGB
, dfactorRGB
,
218 sfactorA
, dfactorA
)) {
222 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
223 ? ctx
->Const
.MaxDrawBuffers
: 1;
226 for (buf
= 0; buf
< numBuffers
; buf
++) {
227 if (ctx
->Color
.Blend
[buf
].SrcRGB
!= sfactorRGB
||
228 ctx
->Color
.Blend
[buf
].DstRGB
!= dfactorRGB
||
229 ctx
->Color
.Blend
[buf
].SrcA
!= sfactorA
||
230 ctx
->Color
.Blend
[buf
].DstA
!= dfactorA
) {
238 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
240 for (buf
= 0; buf
< numBuffers
; buf
++) {
241 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
242 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
243 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
244 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
245 update_uses_dual_src(ctx
, buf
);
247 ctx
->Color
._BlendFuncPerBuffer
= GL_FALSE
;
249 if (ctx
->Driver
.BlendFuncSeparate
) {
250 ctx
->Driver
.BlendFuncSeparate(ctx
, sfactorRGB
, dfactorRGB
,
257 * Set blend source/dest factors for one color buffer/target.
260 _mesa_BlendFunciARB(GLuint buf
, GLenum sfactor
, GLenum dfactor
)
262 _mesa_BlendFuncSeparateiARB(buf
, sfactor
, dfactor
, sfactor
, dfactor
);
267 * Set separate blend source/dest factors for one color buffer/target.
270 _mesa_BlendFuncSeparateiARB(GLuint buf
, GLenum sfactorRGB
, GLenum dfactorRGB
,
271 GLenum sfactorA
, GLenum dfactorA
)
273 GET_CURRENT_CONTEXT(ctx
);
275 if (!ctx
->Extensions
.ARB_draw_buffers_blend
) {
276 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlendFunc[Separate]i()");
280 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
281 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
286 if (!validate_blend_factors(ctx
, "glBlendFuncSeparatei",
287 sfactorRGB
, dfactorRGB
,
288 sfactorA
, dfactorA
)) {
292 if (ctx
->Color
.Blend
[buf
].SrcRGB
== sfactorRGB
&&
293 ctx
->Color
.Blend
[buf
].DstRGB
== dfactorRGB
&&
294 ctx
->Color
.Blend
[buf
].SrcA
== sfactorA
&&
295 ctx
->Color
.Blend
[buf
].DstA
== dfactorA
)
296 return; /* no change */
298 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
300 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
301 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
302 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
303 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
304 update_uses_dual_src(ctx
, buf
);
305 ctx
->Color
._BlendFuncPerBuffer
= GL_TRUE
;
310 * Check if given blend equation is legal.
311 * \return GL_TRUE if legal, GL_FALSE otherwise.
314 legal_blend_equation(const struct gl_context
*ctx
, GLenum mode
)
318 case GL_FUNC_SUBTRACT
:
319 case GL_FUNC_REVERSE_SUBTRACT
:
323 return ctx
->Extensions
.EXT_blend_minmax
;
330 /* This is really an extension function! */
332 _mesa_BlendEquation( GLenum mode
)
334 GLuint buf
, numBuffers
;
336 GET_CURRENT_CONTEXT(ctx
);
338 if (MESA_VERBOSE
& VERBOSE_API
)
339 _mesa_debug(ctx
, "glBlendEquation(%s)\n",
340 _mesa_enum_to_string(mode
));
342 if (!legal_blend_equation(ctx
, mode
)) {
343 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
347 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
348 ? ctx
->Const
.MaxDrawBuffers
: 1;
351 for (buf
= 0; buf
< numBuffers
; buf
++) {
352 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= mode
||
353 ctx
->Color
.Blend
[buf
].EquationA
!= mode
) {
361 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
362 for (buf
= 0; buf
< numBuffers
; buf
++) {
363 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
364 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
366 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
368 if (ctx
->Driver
.BlendEquationSeparate
)
369 (*ctx
->Driver
.BlendEquationSeparate
)( ctx
, mode
, mode
);
374 * Set blend equation for one color buffer/target.
377 _mesa_BlendEquationiARB(GLuint buf
, GLenum mode
)
379 GET_CURRENT_CONTEXT(ctx
);
381 if (MESA_VERBOSE
& VERBOSE_API
)
382 _mesa_debug(ctx
, "glBlendEquationi(%u, %s)\n",
383 buf
, _mesa_enum_to_string(mode
));
385 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
386 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
391 if (!legal_blend_equation(ctx
, mode
)) {
392 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationi");
396 if (ctx
->Color
.Blend
[buf
].EquationRGB
== mode
&&
397 ctx
->Color
.Blend
[buf
].EquationA
== mode
)
398 return; /* no change */
400 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
401 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
402 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
403 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
408 _mesa_BlendEquationSeparate( GLenum modeRGB
, GLenum modeA
)
410 GLuint buf
, numBuffers
;
412 GET_CURRENT_CONTEXT(ctx
);
414 if (MESA_VERBOSE
& VERBOSE_API
)
415 _mesa_debug(ctx
, "glBlendEquationSeparateEXT(%s %s)\n",
416 _mesa_enum_to_string(modeRGB
),
417 _mesa_enum_to_string(modeA
));
419 if ( (modeRGB
!= modeA
) && !ctx
->Extensions
.EXT_blend_equation_separate
) {
420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
421 "glBlendEquationSeparateEXT not supported by driver");
425 if (!legal_blend_equation(ctx
, modeRGB
)) {
426 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeRGB)");
430 if (!legal_blend_equation(ctx
, modeA
)) {
431 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeA)");
435 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
436 ? ctx
->Const
.MaxDrawBuffers
: 1;
439 for (buf
= 0; buf
< numBuffers
; buf
++) {
440 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= modeRGB
||
441 ctx
->Color
.Blend
[buf
].EquationA
!= modeA
) {
449 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
450 for (buf
= 0; buf
< numBuffers
; buf
++) {
451 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
452 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
454 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
456 if (ctx
->Driver
.BlendEquationSeparate
)
457 ctx
->Driver
.BlendEquationSeparate(ctx
, modeRGB
, modeA
);
462 * Set separate blend equations for one color buffer/target.
465 _mesa_BlendEquationSeparateiARB(GLuint buf
, GLenum modeRGB
, GLenum modeA
)
467 GET_CURRENT_CONTEXT(ctx
);
469 if (MESA_VERBOSE
& VERBOSE_API
)
470 _mesa_debug(ctx
, "glBlendEquationSeparatei(%u, %s %s)\n", buf
,
471 _mesa_enum_to_string(modeRGB
),
472 _mesa_enum_to_string(modeA
));
474 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
475 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendEquationSeparatei(buffer=%u)",
480 if (!legal_blend_equation(ctx
, modeRGB
)) {
481 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeRGB)");
485 if (!legal_blend_equation(ctx
, modeA
)) {
486 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeA)");
490 if (ctx
->Color
.Blend
[buf
].EquationRGB
== modeRGB
&&
491 ctx
->Color
.Blend
[buf
].EquationA
== modeA
)
492 return; /* no change */
494 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
495 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
496 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
497 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
502 * Set the blending color.
504 * \param red red color component.
505 * \param green green color component.
506 * \param blue blue color component.
507 * \param alpha alpha color component.
509 * \sa glBlendColor().
511 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
512 * change, flushes the vertices and notifies the driver via
513 * dd_function_table::BlendColor callback.
516 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
519 GET_CURRENT_CONTEXT(ctx
);
526 if (TEST_EQ_4V(tmp
, ctx
->Color
.BlendColorUnclamped
))
529 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
530 COPY_4FV( ctx
->Color
.BlendColorUnclamped
, tmp
);
532 ctx
->Color
.BlendColor
[0] = CLAMP(tmp
[0], 0.0F
, 1.0F
);
533 ctx
->Color
.BlendColor
[1] = CLAMP(tmp
[1], 0.0F
, 1.0F
);
534 ctx
->Color
.BlendColor
[2] = CLAMP(tmp
[2], 0.0F
, 1.0F
);
535 ctx
->Color
.BlendColor
[3] = CLAMP(tmp
[3], 0.0F
, 1.0F
);
537 if (ctx
->Driver
.BlendColor
)
538 (*ctx
->Driver
.BlendColor
)(ctx
, ctx
->Color
.BlendColor
);
543 * Specify the alpha test function.
545 * \param func alpha comparison function.
546 * \param ref reference value.
548 * Verifies the parameters and updates gl_colorbuffer_attrib.
549 * On a change, flushes the vertices and notifies the driver via
550 * dd_function_table::AlphaFunc callback.
553 _mesa_AlphaFunc( GLenum func
, GLclampf ref
)
555 GET_CURRENT_CONTEXT(ctx
);
557 if (MESA_VERBOSE
& VERBOSE_API
)
558 _mesa_debug(ctx
, "glAlphaFunc(%s, %f)\n",
559 _mesa_enum_to_string(func
), ref
);
561 if (ctx
->Color
.AlphaFunc
== func
&& ctx
->Color
.AlphaRefUnclamped
== ref
)
562 return; /* no change */
573 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
574 ctx
->Color
.AlphaFunc
= func
;
575 ctx
->Color
.AlphaRefUnclamped
= ref
;
576 ctx
->Color
.AlphaRef
= CLAMP(ref
, 0.0F
, 1.0F
);
578 if (ctx
->Driver
.AlphaFunc
)
579 ctx
->Driver
.AlphaFunc(ctx
, func
, ctx
->Color
.AlphaRef
);
583 _mesa_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
590 * Specify a logic pixel operation for color index rendering.
592 * \param opcode operation.
594 * Verifies that \p opcode is a valid enum and updates
595 gl_colorbuffer_attrib::LogicOp.
596 * On a change, flushes the vertices and notifies the driver via the
597 * dd_function_table::LogicOpcode callback.
600 _mesa_LogicOp( GLenum opcode
)
602 GET_CURRENT_CONTEXT(ctx
);
604 if (MESA_VERBOSE
& VERBOSE_API
)
605 _mesa_debug(ctx
, "glLogicOp(%s)\n", _mesa_enum_to_string(opcode
));
611 case GL_COPY_INVERTED
:
621 case GL_AND_INVERTED
:
626 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLogicOp" );
630 if (ctx
->Color
.LogicOp
== opcode
)
633 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
634 ctx
->Color
.LogicOp
= opcode
;
636 if (ctx
->Driver
.LogicOpcode
)
637 ctx
->Driver
.LogicOpcode( ctx
, opcode
);
642 _mesa_IndexMask( GLuint mask
)
644 GET_CURRENT_CONTEXT(ctx
);
646 if (ctx
->Color
.IndexMask
== mask
)
649 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
650 ctx
->Color
.IndexMask
= mask
;
655 * Enable or disable writing of frame buffer color components.
657 * \param red whether to mask writing of the red color component.
658 * \param green whether to mask writing of the green color component.
659 * \param blue whether to mask writing of the blue color component.
660 * \param alpha whether to mask writing of the alpha color component.
664 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
665 * change, flushes the vertices and notifies the driver via the
666 * dd_function_table::ColorMask callback.
669 _mesa_ColorMask( GLboolean red
, GLboolean green
,
670 GLboolean blue
, GLboolean alpha
)
672 GET_CURRENT_CONTEXT(ctx
);
677 if (MESA_VERBOSE
& VERBOSE_API
)
678 _mesa_debug(ctx
, "glColorMask(%d, %d, %d, %d)\n",
679 red
, green
, blue
, alpha
);
681 /* Shouldn't have any information about channel depth in core mesa
682 * -- should probably store these as the native booleans:
684 tmp
[RCOMP
] = red
? 0xff : 0x0;
685 tmp
[GCOMP
] = green
? 0xff : 0x0;
686 tmp
[BCOMP
] = blue
? 0xff : 0x0;
687 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
690 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
691 if (!TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[i
])) {
693 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
696 COPY_4UBV(ctx
->Color
.ColorMask
[i
], tmp
);
700 if (ctx
->Driver
.ColorMask
)
701 ctx
->Driver
.ColorMask( ctx
, red
, green
, blue
, alpha
);
706 * For GL_EXT_draw_buffers2 and GL3
709 _mesa_ColorMaski( GLuint buf
, GLboolean red
, GLboolean green
,
710 GLboolean blue
, GLboolean alpha
)
713 GET_CURRENT_CONTEXT(ctx
);
715 if (MESA_VERBOSE
& VERBOSE_API
)
716 _mesa_debug(ctx
, "glColorMaskIndexed %u %d %d %d %d\n",
717 buf
, red
, green
, blue
, alpha
);
719 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
720 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorMaskIndexed(buf=%u)", buf
);
724 /* Shouldn't have any information about channel depth in core mesa
725 * -- should probably store these as the native booleans:
727 tmp
[RCOMP
] = red
? 0xff : 0x0;
728 tmp
[GCOMP
] = green
? 0xff : 0x0;
729 tmp
[BCOMP
] = blue
? 0xff : 0x0;
730 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
732 if (TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[buf
]))
735 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
736 COPY_4UBV(ctx
->Color
.ColorMask
[buf
], tmp
);
738 if (ctx
->Driver
.ColorMaskIndexed
)
739 ctx
->Driver
.ColorMaskIndexed(ctx
, buf
, red
, green
, blue
, alpha
);
744 _mesa_ClampColor(GLenum target
, GLenum clamp
)
746 GET_CURRENT_CONTEXT(ctx
);
748 if (clamp
!= GL_TRUE
&& clamp
!= GL_FALSE
&& clamp
!= GL_FIXED_ONLY_ARB
) {
749 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColorARB(clamp)");
754 case GL_CLAMP_VERTEX_COLOR_ARB
:
755 if (ctx
->API
== API_OPENGL_CORE
&&
756 !ctx
->Extensions
.ARB_color_buffer_float
) {
759 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
760 ctx
->Light
.ClampVertexColor
= clamp
;
761 _mesa_update_clamp_vertex_color(ctx
, ctx
->DrawBuffer
);
763 case GL_CLAMP_FRAGMENT_COLOR_ARB
:
764 if (ctx
->API
== API_OPENGL_CORE
&&
765 !ctx
->Extensions
.ARB_color_buffer_float
) {
768 FLUSH_VERTICES(ctx
, _NEW_FRAG_CLAMP
);
769 ctx
->Color
.ClampFragmentColor
= clamp
;
770 _mesa_update_clamp_fragment_color(ctx
, ctx
->DrawBuffer
);
772 case GL_CLAMP_READ_COLOR_ARB
:
773 ctx
->Color
.ClampReadColor
= clamp
;
781 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColor(%s)",
782 _mesa_enum_to_string(target
));
786 get_clamp_color(const struct gl_framebuffer
*fb
, GLenum clamp
)
788 if (clamp
== GL_TRUE
|| clamp
== GL_FALSE
)
791 assert(clamp
== GL_FIXED_ONLY
);
795 return fb
->_AllColorBuffersFixedPoint
;
799 _mesa_get_clamp_fragment_color(const struct gl_context
*ctx
,
800 const struct gl_framebuffer
*drawFb
)
802 return get_clamp_color(drawFb
, ctx
->Color
.ClampFragmentColor
);
806 _mesa_get_clamp_vertex_color(const struct gl_context
*ctx
,
807 const struct gl_framebuffer
*drawFb
)
809 return get_clamp_color(drawFb
, ctx
->Light
.ClampVertexColor
);
813 _mesa_get_clamp_read_color(const struct gl_context
*ctx
,
814 const struct gl_framebuffer
*readFb
)
816 return get_clamp_color(readFb
, ctx
->Color
.ClampReadColor
);
820 * Update the ctx->Color._ClampFragmentColor field
823 _mesa_update_clamp_fragment_color(struct gl_context
*ctx
,
824 const struct gl_framebuffer
*drawFb
)
827 * - there is no colorbuffer
828 * - all colorbuffers are unsigned normalized, so clamping has no effect
829 * - there is an integer colorbuffer
831 if (!drawFb
|| !drawFb
->_HasSNormOrFloatColorBuffer
||
832 drawFb
->_IntegerColor
)
833 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
835 ctx
->Color
._ClampFragmentColor
=
836 _mesa_get_clamp_fragment_color(ctx
, drawFb
);
840 * Update the ctx->Color._ClampVertexColor field
843 _mesa_update_clamp_vertex_color(struct gl_context
*ctx
,
844 const struct gl_framebuffer
*drawFb
)
846 ctx
->Light
._ClampVertexColor
=
847 _mesa_get_clamp_vertex_color(ctx
, drawFb
);
851 * Returns an appropriate mesa_format for color rendering based on the
852 * GL_FRAMEBUFFER_SRGB state.
854 * Some drivers implement GL_FRAMEBUFFER_SRGB using a flag on the blend state
855 * (which GL_FRAMEBUFFER_SRGB maps to reasonably), but some have to do so by
856 * overriding the format of the surface. This is a helper for doing the
857 * surface format override variant.
860 _mesa_get_render_format(const struct gl_context
*ctx
, mesa_format format
)
862 if (ctx
->Color
.sRGBEnabled
)
865 return _mesa_get_srgb_format_linear(format
);
868 /**********************************************************************/
869 /** \name Initialization */
873 * Initialization of the context's Color attribute group.
875 * \param ctx GL context.
877 * Initializes the related fields in the context color attribute group,
878 * __struct gl_contextRec::Color.
880 void _mesa_init_color( struct gl_context
* ctx
)
884 /* Color buffer group */
885 ctx
->Color
.IndexMask
= ~0u;
886 memset(ctx
->Color
.ColorMask
, 0xff, sizeof(ctx
->Color
.ColorMask
));
887 ctx
->Color
.ClearIndex
= 0;
888 ASSIGN_4V( ctx
->Color
.ClearColor
.f
, 0, 0, 0, 0 );
889 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
890 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
891 ctx
->Color
.AlphaRef
= 0;
892 ctx
->Color
.BlendEnabled
= 0x0;
893 for (i
= 0; i
< ARRAY_SIZE(ctx
->Color
.Blend
); i
++) {
894 ctx
->Color
.Blend
[i
].SrcRGB
= GL_ONE
;
895 ctx
->Color
.Blend
[i
].DstRGB
= GL_ZERO
;
896 ctx
->Color
.Blend
[i
].SrcA
= GL_ONE
;
897 ctx
->Color
.Blend
[i
].DstA
= GL_ZERO
;
898 ctx
->Color
.Blend
[i
].EquationRGB
= GL_FUNC_ADD
;
899 ctx
->Color
.Blend
[i
].EquationA
= GL_FUNC_ADD
;
901 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
902 ASSIGN_4V( ctx
->Color
.BlendColorUnclamped
, 0.0, 0.0, 0.0, 0.0 );
903 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
904 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
905 ctx
->Color
.LogicOp
= GL_COPY
;
906 ctx
->Color
.DitherFlag
= GL_TRUE
;
908 /* GL_FRONT is not possible on GLES. Instead GL_BACK will render to either
909 * the front or the back buffer depending on the config */
910 if (ctx
->Visual
.doubleBufferMode
|| _mesa_is_gles(ctx
)) {
911 ctx
->Color
.DrawBuffer
[0] = GL_BACK
;
914 ctx
->Color
.DrawBuffer
[0] = GL_FRONT
;
917 ctx
->Color
.ClampFragmentColor
= ctx
->API
== API_OPENGL_COMPAT
?
918 GL_FIXED_ONLY_ARB
: GL_FALSE
;
919 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
920 ctx
->Color
.ClampReadColor
= GL_FIXED_ONLY_ARB
;
922 /* GLES 1/2/3 behaves as though GL_FRAMEBUFFER_SRGB is always enabled
923 * if EGL_KHR_gl_colorspace has been used to request sRGB.
925 ctx
->Color
.sRGBEnabled
= _mesa_is_gles(ctx
);