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_lookup_enum_by_nr(sfactorRGB
));
135 if (!legal_dst_factor(ctx
, dfactorRGB
)) {
136 _mesa_error(ctx
, GL_INVALID_ENUM
,
137 "%s(dfactorRGB = %s)", func
,
138 _mesa_lookup_enum_by_nr(dfactorRGB
));
142 if (sfactorA
!= sfactorRGB
&& !legal_src_factor(ctx
, sfactorA
)) {
143 _mesa_error(ctx
, GL_INVALID_ENUM
,
144 "%s(sfactorA = %s)", func
,
145 _mesa_lookup_enum_by_nr(sfactorA
));
149 if (dfactorA
!= dfactorRGB
&& !legal_dst_factor(ctx
, dfactorA
)) {
150 _mesa_error(ctx
, GL_INVALID_ENUM
,
151 "%s(dfactorA = %s)", func
,
152 _mesa_lookup_enum_by_nr(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_lookup_enum_by_nr(sfactorRGB
),
212 _mesa_lookup_enum_by_nr(dfactorRGB
),
213 _mesa_lookup_enum_by_nr(sfactorA
),
214 _mesa_lookup_enum_by_nr(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
;
307 if (ctx
->Driver
.BlendFuncSeparatei
) {
308 ctx
->Driver
.BlendFuncSeparatei(ctx
, buf
, sfactorRGB
, dfactorRGB
,
315 * Check if given blend equation is legal.
316 * \return GL_TRUE if legal, GL_FALSE otherwise.
319 legal_blend_equation(const struct gl_context
*ctx
, GLenum mode
)
323 case GL_FUNC_SUBTRACT
:
324 case GL_FUNC_REVERSE_SUBTRACT
:
328 return ctx
->Extensions
.EXT_blend_minmax
;
335 /* This is really an extension function! */
337 _mesa_BlendEquation( GLenum mode
)
339 GLuint buf
, numBuffers
;
341 GET_CURRENT_CONTEXT(ctx
);
343 if (MESA_VERBOSE
& VERBOSE_API
)
344 _mesa_debug(ctx
, "glBlendEquation(%s)\n",
345 _mesa_lookup_enum_by_nr(mode
));
347 if (!legal_blend_equation(ctx
, mode
)) {
348 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
352 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
353 ? ctx
->Const
.MaxDrawBuffers
: 1;
356 for (buf
= 0; buf
< numBuffers
; buf
++) {
357 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= mode
||
358 ctx
->Color
.Blend
[buf
].EquationA
!= mode
) {
366 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
367 for (buf
= 0; buf
< numBuffers
; buf
++) {
368 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
369 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
371 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
373 if (ctx
->Driver
.BlendEquationSeparate
)
374 (*ctx
->Driver
.BlendEquationSeparate
)( ctx
, mode
, mode
);
379 * Set blend equation for one color buffer/target.
382 _mesa_BlendEquationiARB(GLuint buf
, GLenum mode
)
384 GET_CURRENT_CONTEXT(ctx
);
386 if (MESA_VERBOSE
& VERBOSE_API
)
387 _mesa_debug(ctx
, "glBlendEquationi(%u, %s)\n",
388 buf
, _mesa_lookup_enum_by_nr(mode
));
390 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
391 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
396 if (!legal_blend_equation(ctx
, mode
)) {
397 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationi");
401 if (ctx
->Color
.Blend
[buf
].EquationRGB
== mode
&&
402 ctx
->Color
.Blend
[buf
].EquationA
== mode
)
403 return; /* no change */
405 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
406 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
407 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
408 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
410 if (ctx
->Driver
.BlendEquationSeparatei
)
411 ctx
->Driver
.BlendEquationSeparatei(ctx
, buf
, mode
, mode
);
416 _mesa_BlendEquationSeparate( GLenum modeRGB
, GLenum modeA
)
418 GLuint buf
, numBuffers
;
420 GET_CURRENT_CONTEXT(ctx
);
422 if (MESA_VERBOSE
& VERBOSE_API
)
423 _mesa_debug(ctx
, "glBlendEquationSeparateEXT(%s %s)\n",
424 _mesa_lookup_enum_by_nr(modeRGB
),
425 _mesa_lookup_enum_by_nr(modeA
));
427 if ( (modeRGB
!= modeA
) && !ctx
->Extensions
.EXT_blend_equation_separate
) {
428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
429 "glBlendEquationSeparateEXT not supported by driver");
433 if (!legal_blend_equation(ctx
, modeRGB
)) {
434 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeRGB)");
438 if (!legal_blend_equation(ctx
, modeA
)) {
439 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeA)");
443 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
444 ? ctx
->Const
.MaxDrawBuffers
: 1;
447 for (buf
= 0; buf
< numBuffers
; buf
++) {
448 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= modeRGB
||
449 ctx
->Color
.Blend
[buf
].EquationA
!= modeA
) {
457 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
458 for (buf
= 0; buf
< numBuffers
; buf
++) {
459 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
460 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
462 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
464 if (ctx
->Driver
.BlendEquationSeparate
)
465 ctx
->Driver
.BlendEquationSeparate(ctx
, modeRGB
, modeA
);
470 * Set separate blend equations for one color buffer/target.
473 _mesa_BlendEquationSeparateiARB(GLuint buf
, GLenum modeRGB
, GLenum modeA
)
475 GET_CURRENT_CONTEXT(ctx
);
477 if (MESA_VERBOSE
& VERBOSE_API
)
478 _mesa_debug(ctx
, "glBlendEquationSeparatei(%u, %s %s)\n", buf
,
479 _mesa_lookup_enum_by_nr(modeRGB
),
480 _mesa_lookup_enum_by_nr(modeA
));
482 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
483 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendEquationSeparatei(buffer=%u)",
488 if (!legal_blend_equation(ctx
, modeRGB
)) {
489 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeRGB)");
493 if (!legal_blend_equation(ctx
, modeA
)) {
494 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeA)");
498 if (ctx
->Color
.Blend
[buf
].EquationRGB
== modeRGB
&&
499 ctx
->Color
.Blend
[buf
].EquationA
== modeA
)
500 return; /* no change */
502 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
503 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
504 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
505 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
507 if (ctx
->Driver
.BlendEquationSeparatei
)
508 ctx
->Driver
.BlendEquationSeparatei(ctx
, buf
, modeRGB
, modeA
);
513 * Set the blending color.
515 * \param red red color component.
516 * \param green green color component.
517 * \param blue blue color component.
518 * \param alpha alpha color component.
520 * \sa glBlendColor().
522 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
523 * change, flushes the vertices and notifies the driver via
524 * dd_function_table::BlendColor callback.
527 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
530 GET_CURRENT_CONTEXT(ctx
);
537 if (TEST_EQ_4V(tmp
, ctx
->Color
.BlendColorUnclamped
))
540 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
541 COPY_4FV( ctx
->Color
.BlendColorUnclamped
, tmp
);
543 ctx
->Color
.BlendColor
[0] = CLAMP(tmp
[0], 0.0F
, 1.0F
);
544 ctx
->Color
.BlendColor
[1] = CLAMP(tmp
[1], 0.0F
, 1.0F
);
545 ctx
->Color
.BlendColor
[2] = CLAMP(tmp
[2], 0.0F
, 1.0F
);
546 ctx
->Color
.BlendColor
[3] = CLAMP(tmp
[3], 0.0F
, 1.0F
);
548 if (ctx
->Driver
.BlendColor
)
549 (*ctx
->Driver
.BlendColor
)(ctx
, ctx
->Color
.BlendColor
);
554 * Specify the alpha test function.
556 * \param func alpha comparison function.
557 * \param ref reference value.
559 * Verifies the parameters and updates gl_colorbuffer_attrib.
560 * On a change, flushes the vertices and notifies the driver via
561 * dd_function_table::AlphaFunc callback.
564 _mesa_AlphaFunc( GLenum func
, GLclampf ref
)
566 GET_CURRENT_CONTEXT(ctx
);
568 if (MESA_VERBOSE
& VERBOSE_API
)
569 _mesa_debug(ctx
, "glAlphaFunc(%s, %f)\n",
570 _mesa_lookup_enum_by_nr(func
), ref
);
581 if (ctx
->Color
.AlphaFunc
== func
&& ctx
->Color
.AlphaRefUnclamped
== ref
)
582 return; /* no change */
584 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
585 ctx
->Color
.AlphaFunc
= func
;
586 ctx
->Color
.AlphaRefUnclamped
= ref
;
587 ctx
->Color
.AlphaRef
= CLAMP(ref
, 0.0F
, 1.0F
);
589 if (ctx
->Driver
.AlphaFunc
)
590 ctx
->Driver
.AlphaFunc(ctx
, func
, ctx
->Color
.AlphaRef
);
594 _mesa_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
601 * Specify a logic pixel operation for color index rendering.
603 * \param opcode operation.
605 * Verifies that \p opcode is a valid enum and updates
606 gl_colorbuffer_attrib::LogicOp.
607 * On a change, flushes the vertices and notifies the driver via the
608 * dd_function_table::LogicOpcode callback.
611 _mesa_LogicOp( GLenum opcode
)
613 GET_CURRENT_CONTEXT(ctx
);
615 if (MESA_VERBOSE
& VERBOSE_API
)
616 _mesa_debug(ctx
, "glLogicOp(%s)\n", _mesa_lookup_enum_by_nr(opcode
));
622 case GL_COPY_INVERTED
:
632 case GL_AND_INVERTED
:
637 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLogicOp" );
641 if (ctx
->Color
.LogicOp
== opcode
)
644 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
645 ctx
->Color
.LogicOp
= opcode
;
647 if (ctx
->Driver
.LogicOpcode
)
648 ctx
->Driver
.LogicOpcode( ctx
, opcode
);
653 _mesa_IndexMask( GLuint mask
)
655 GET_CURRENT_CONTEXT(ctx
);
657 if (ctx
->Color
.IndexMask
== mask
)
660 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
661 ctx
->Color
.IndexMask
= mask
;
666 * Enable or disable writing of frame buffer color components.
668 * \param red whether to mask writing of the red color component.
669 * \param green whether to mask writing of the green color component.
670 * \param blue whether to mask writing of the blue color component.
671 * \param alpha whether to mask writing of the alpha color component.
675 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
676 * change, flushes the vertices and notifies the driver via the
677 * dd_function_table::ColorMask callback.
680 _mesa_ColorMask( GLboolean red
, GLboolean green
,
681 GLboolean blue
, GLboolean alpha
)
683 GET_CURRENT_CONTEXT(ctx
);
688 if (MESA_VERBOSE
& VERBOSE_API
)
689 _mesa_debug(ctx
, "glColorMask(%d, %d, %d, %d)\n",
690 red
, green
, blue
, alpha
);
692 /* Shouldn't have any information about channel depth in core mesa
693 * -- should probably store these as the native booleans:
695 tmp
[RCOMP
] = red
? 0xff : 0x0;
696 tmp
[GCOMP
] = green
? 0xff : 0x0;
697 tmp
[BCOMP
] = blue
? 0xff : 0x0;
698 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
701 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
702 if (!TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[i
])) {
704 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
707 COPY_4UBV(ctx
->Color
.ColorMask
[i
], tmp
);
711 if (ctx
->Driver
.ColorMask
)
712 ctx
->Driver
.ColorMask( ctx
, red
, green
, blue
, alpha
);
717 * For GL_EXT_draw_buffers2 and GL3
720 _mesa_ColorMaski( GLuint buf
, GLboolean red
, GLboolean green
,
721 GLboolean blue
, GLboolean alpha
)
724 GET_CURRENT_CONTEXT(ctx
);
726 if (MESA_VERBOSE
& VERBOSE_API
)
727 _mesa_debug(ctx
, "glColorMaskIndexed %u %d %d %d %d\n",
728 buf
, red
, green
, blue
, alpha
);
730 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
731 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorMaskIndexed(buf=%u)", buf
);
735 /* Shouldn't have any information about channel depth in core mesa
736 * -- should probably store these as the native booleans:
738 tmp
[RCOMP
] = red
? 0xff : 0x0;
739 tmp
[GCOMP
] = green
? 0xff : 0x0;
740 tmp
[BCOMP
] = blue
? 0xff : 0x0;
741 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
743 if (TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[buf
]))
746 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
747 COPY_4UBV(ctx
->Color
.ColorMask
[buf
], tmp
);
749 if (ctx
->Driver
.ColorMaskIndexed
)
750 ctx
->Driver
.ColorMaskIndexed(ctx
, buf
, red
, green
, blue
, alpha
);
755 _mesa_ClampColor(GLenum target
, GLenum clamp
)
757 GET_CURRENT_CONTEXT(ctx
);
759 if (clamp
!= GL_TRUE
&& clamp
!= GL_FALSE
&& clamp
!= GL_FIXED_ONLY_ARB
) {
760 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColorARB(clamp)");
765 case GL_CLAMP_VERTEX_COLOR_ARB
:
766 if (ctx
->API
== API_OPENGL_CORE
&&
767 !ctx
->Extensions
.ARB_color_buffer_float
) {
770 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
771 ctx
->Light
.ClampVertexColor
= clamp
;
772 _mesa_update_clamp_vertex_color(ctx
);
774 case GL_CLAMP_FRAGMENT_COLOR_ARB
:
775 if (ctx
->API
== API_OPENGL_CORE
&&
776 !ctx
->Extensions
.ARB_color_buffer_float
) {
779 FLUSH_VERTICES(ctx
, _NEW_FRAG_CLAMP
);
780 ctx
->Color
.ClampFragmentColor
= clamp
;
781 _mesa_update_clamp_fragment_color(ctx
);
783 case GL_CLAMP_READ_COLOR_ARB
:
784 ctx
->Color
.ClampReadColor
= clamp
;
792 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColor(%s)",
793 _mesa_lookup_enum_by_nr(target
));
797 get_clamp_color(const struct gl_framebuffer
*fb
, GLenum clamp
)
799 if (clamp
== GL_TRUE
|| clamp
== GL_FALSE
)
802 ASSERT(clamp
== GL_FIXED_ONLY
);
806 return fb
->_AllColorBuffersFixedPoint
;
810 _mesa_get_clamp_fragment_color(const struct gl_context
*ctx
)
812 return get_clamp_color(ctx
->DrawBuffer
,
813 ctx
->Color
.ClampFragmentColor
);
817 _mesa_get_clamp_vertex_color(const struct gl_context
*ctx
)
819 return get_clamp_color(ctx
->DrawBuffer
, ctx
->Light
.ClampVertexColor
);
823 _mesa_get_clamp_read_color(const struct gl_context
*ctx
)
825 return get_clamp_color(ctx
->ReadBuffer
, ctx
->Color
.ClampReadColor
);
829 * Update the ctx->Color._ClampFragmentColor field
832 _mesa_update_clamp_fragment_color(struct gl_context
*ctx
)
834 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
837 * - there is no colorbuffer
838 * - all colorbuffers are unsigned normalized, so clamping has no effect
839 * - there is an integer colorbuffer
841 if (!fb
|| !fb
->_HasSNormOrFloatColorBuffer
|| fb
->_IntegerColor
)
842 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
844 ctx
->Color
._ClampFragmentColor
= _mesa_get_clamp_fragment_color(ctx
);
848 * Update the ctx->Color._ClampVertexColor field
851 _mesa_update_clamp_vertex_color(struct gl_context
*ctx
)
853 ctx
->Light
._ClampVertexColor
= _mesa_get_clamp_vertex_color(ctx
);
857 * Returns an appropriate mesa_format for color rendering based on the
858 * GL_FRAMEBUFFER_SRGB state.
860 * Some drivers implement GL_FRAMEBUFFER_SRGB using a flag on the blend state
861 * (which GL_FRAMEBUFFER_SRGB maps to reasonably), but some have to do so by
862 * overriding the format of the surface. This is a helper for doing the
863 * surface format override variant.
866 _mesa_get_render_format(const struct gl_context
*ctx
, mesa_format format
)
868 if (ctx
->Color
.sRGBEnabled
)
871 return _mesa_get_srgb_format_linear(format
);
874 /**********************************************************************/
875 /** \name Initialization */
879 * Initialization of the context's Color attribute group.
881 * \param ctx GL context.
883 * Initializes the related fields in the context color attribute group,
884 * __struct gl_contextRec::Color.
886 void _mesa_init_color( struct gl_context
* ctx
)
890 /* Color buffer group */
891 ctx
->Color
.IndexMask
= ~0u;
892 memset(ctx
->Color
.ColorMask
, 0xff, sizeof(ctx
->Color
.ColorMask
));
893 ctx
->Color
.ClearIndex
= 0;
894 ASSIGN_4V( ctx
->Color
.ClearColor
.f
, 0, 0, 0, 0 );
895 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
896 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
897 ctx
->Color
.AlphaRef
= 0;
898 ctx
->Color
.BlendEnabled
= 0x0;
899 for (i
= 0; i
< Elements(ctx
->Color
.Blend
); i
++) {
900 ctx
->Color
.Blend
[i
].SrcRGB
= GL_ONE
;
901 ctx
->Color
.Blend
[i
].DstRGB
= GL_ZERO
;
902 ctx
->Color
.Blend
[i
].SrcA
= GL_ONE
;
903 ctx
->Color
.Blend
[i
].DstA
= GL_ZERO
;
904 ctx
->Color
.Blend
[i
].EquationRGB
= GL_FUNC_ADD
;
905 ctx
->Color
.Blend
[i
].EquationA
= GL_FUNC_ADD
;
907 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
908 ASSIGN_4V( ctx
->Color
.BlendColorUnclamped
, 0.0, 0.0, 0.0, 0.0 );
909 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
910 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
911 ctx
->Color
.LogicOp
= GL_COPY
;
912 ctx
->Color
.DitherFlag
= GL_TRUE
;
914 /* GL_FRONT is not possible on GLES. Instead GL_BACK will render to either
915 * the front or the back buffer depending on the config */
916 if (ctx
->Visual
.doubleBufferMode
|| _mesa_is_gles(ctx
)) {
917 ctx
->Color
.DrawBuffer
[0] = GL_BACK
;
920 ctx
->Color
.DrawBuffer
[0] = GL_FRONT
;
923 ctx
->Color
.ClampFragmentColor
= ctx
->API
== API_OPENGL_COMPAT
?
924 GL_FIXED_ONLY_ARB
: GL_FALSE
;
925 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
926 ctx
->Color
.ClampReadColor
= GL_FIXED_ONLY_ARB
;
928 if (ctx
->API
== API_OPENGLES2
) {
929 /* GLES 3 behaves as though GL_FRAMEBUFFER_SRGB is always enabled. */
930 ctx
->Color
.sRGBEnabled
= GL_TRUE
;
932 ctx
->Color
.sRGBEnabled
= GL_FALSE
;