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
:
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_BlendFuncSeparate(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_BlendFuncSeparate( GLenum sfactorRGB
, GLenum dfactorRGB
,
205 GLenum sfactorA
, GLenum dfactorA
)
207 GLuint buf
, numBuffers
;
209 GET_CURRENT_CONTEXT(ctx
);
211 if (MESA_VERBOSE
& VERBOSE_API
)
212 _mesa_debug(ctx
, "glBlendFuncSeparate %s %s %s %s\n",
213 _mesa_lookup_enum_by_nr(sfactorRGB
),
214 _mesa_lookup_enum_by_nr(dfactorRGB
),
215 _mesa_lookup_enum_by_nr(sfactorA
),
216 _mesa_lookup_enum_by_nr(dfactorA
));
218 if (!validate_blend_factors(ctx
, "glBlendFuncSeparate",
219 sfactorRGB
, dfactorRGB
,
220 sfactorA
, dfactorA
)) {
224 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
225 ? ctx
->Const
.MaxDrawBuffers
: 1;
228 for (buf
= 0; buf
< numBuffers
; buf
++) {
229 if (ctx
->Color
.Blend
[buf
].SrcRGB
!= sfactorRGB
||
230 ctx
->Color
.Blend
[buf
].DstRGB
!= dfactorRGB
||
231 ctx
->Color
.Blend
[buf
].SrcA
!= sfactorA
||
232 ctx
->Color
.Blend
[buf
].DstA
!= dfactorA
) {
240 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
242 for (buf
= 0; buf
< numBuffers
; buf
++) {
243 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
244 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
245 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
246 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
247 update_uses_dual_src(ctx
, buf
);
249 ctx
->Color
._BlendFuncPerBuffer
= GL_FALSE
;
251 if (ctx
->Driver
.BlendFuncSeparate
) {
252 ctx
->Driver
.BlendFuncSeparate(ctx
, sfactorRGB
, dfactorRGB
,
259 * Set blend source/dest factors for one color buffer/target.
262 _mesa_BlendFunciARB(GLuint buf
, GLenum sfactor
, GLenum dfactor
)
264 _mesa_BlendFuncSeparateiARB(buf
, sfactor
, dfactor
, sfactor
, dfactor
);
269 * Set separate blend source/dest factors for one color buffer/target.
272 _mesa_BlendFuncSeparateiARB(GLuint buf
, GLenum sfactorRGB
, GLenum dfactorRGB
,
273 GLenum sfactorA
, GLenum dfactorA
)
275 GET_CURRENT_CONTEXT(ctx
);
277 if (!ctx
->Extensions
.ARB_draw_buffers_blend
) {
278 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlendFunc[Separate]i()");
282 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
283 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
288 if (!validate_blend_factors(ctx
, "glBlendFuncSeparatei",
289 sfactorRGB
, dfactorRGB
,
290 sfactorA
, dfactorA
)) {
294 if (ctx
->Color
.Blend
[buf
].SrcRGB
== sfactorRGB
&&
295 ctx
->Color
.Blend
[buf
].DstRGB
== dfactorRGB
&&
296 ctx
->Color
.Blend
[buf
].SrcA
== sfactorA
&&
297 ctx
->Color
.Blend
[buf
].DstA
== dfactorA
)
298 return; /* no change */
300 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
302 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
303 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
304 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
305 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
306 update_uses_dual_src(ctx
, buf
);
307 ctx
->Color
._BlendFuncPerBuffer
= GL_TRUE
;
309 if (ctx
->Driver
.BlendFuncSeparatei
) {
310 ctx
->Driver
.BlendFuncSeparatei(ctx
, buf
, sfactorRGB
, dfactorRGB
,
317 * Check if given blend equation is legal.
318 * \return GL_TRUE if legal, GL_FALSE otherwise.
321 legal_blend_equation(const struct gl_context
*ctx
, GLenum mode
)
325 case GL_FUNC_SUBTRACT
:
326 case GL_FUNC_REVERSE_SUBTRACT
:
330 return ctx
->Extensions
.EXT_blend_minmax
;
337 /* This is really an extension function! */
339 _mesa_BlendEquation( GLenum mode
)
341 GLuint buf
, numBuffers
;
343 GET_CURRENT_CONTEXT(ctx
);
345 if (MESA_VERBOSE
& VERBOSE_API
)
346 _mesa_debug(ctx
, "glBlendEquation(%s)\n",
347 _mesa_lookup_enum_by_nr(mode
));
349 if (!legal_blend_equation(ctx
, mode
)) {
350 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
354 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
355 ? ctx
->Const
.MaxDrawBuffers
: 1;
358 for (buf
= 0; buf
< numBuffers
; buf
++) {
359 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= mode
||
360 ctx
->Color
.Blend
[buf
].EquationA
!= mode
) {
368 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
369 for (buf
= 0; buf
< numBuffers
; buf
++) {
370 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
371 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
373 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
375 if (ctx
->Driver
.BlendEquationSeparate
)
376 (*ctx
->Driver
.BlendEquationSeparate
)( ctx
, mode
, mode
);
381 * Set blend equation for one color buffer/target.
384 _mesa_BlendEquationiARB(GLuint buf
, GLenum mode
)
386 GET_CURRENT_CONTEXT(ctx
);
388 if (MESA_VERBOSE
& VERBOSE_API
)
389 _mesa_debug(ctx
, "glBlendEquationi(%u, %s)\n",
390 buf
, _mesa_lookup_enum_by_nr(mode
));
392 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
393 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
398 if (!legal_blend_equation(ctx
, mode
)) {
399 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationi");
403 if (ctx
->Color
.Blend
[buf
].EquationRGB
== mode
&&
404 ctx
->Color
.Blend
[buf
].EquationA
== mode
)
405 return; /* no change */
407 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
408 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
409 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
410 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
412 if (ctx
->Driver
.BlendEquationSeparatei
)
413 ctx
->Driver
.BlendEquationSeparatei(ctx
, buf
, mode
, mode
);
418 _mesa_BlendEquationSeparate( GLenum modeRGB
, GLenum modeA
)
420 GLuint buf
, numBuffers
;
422 GET_CURRENT_CONTEXT(ctx
);
424 if (MESA_VERBOSE
& VERBOSE_API
)
425 _mesa_debug(ctx
, "glBlendEquationSeparateEXT(%s %s)\n",
426 _mesa_lookup_enum_by_nr(modeRGB
),
427 _mesa_lookup_enum_by_nr(modeA
));
429 if ( (modeRGB
!= modeA
) && !ctx
->Extensions
.EXT_blend_equation_separate
) {
430 _mesa_error(ctx
, GL_INVALID_OPERATION
,
431 "glBlendEquationSeparateEXT not supported by driver");
435 if (!legal_blend_equation(ctx
, modeRGB
)) {
436 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeRGB)");
440 if (!legal_blend_equation(ctx
, modeA
)) {
441 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeA)");
445 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
446 ? ctx
->Const
.MaxDrawBuffers
: 1;
449 for (buf
= 0; buf
< numBuffers
; buf
++) {
450 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= modeRGB
||
451 ctx
->Color
.Blend
[buf
].EquationA
!= modeA
) {
459 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
460 for (buf
= 0; buf
< numBuffers
; buf
++) {
461 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
462 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
464 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
466 if (ctx
->Driver
.BlendEquationSeparate
)
467 ctx
->Driver
.BlendEquationSeparate(ctx
, modeRGB
, modeA
);
472 * Set separate blend equations for one color buffer/target.
475 _mesa_BlendEquationSeparateiARB(GLuint buf
, GLenum modeRGB
, GLenum modeA
)
477 GET_CURRENT_CONTEXT(ctx
);
479 if (MESA_VERBOSE
& VERBOSE_API
)
480 _mesa_debug(ctx
, "glBlendEquationSeparatei(%u, %s %s)\n", buf
,
481 _mesa_lookup_enum_by_nr(modeRGB
),
482 _mesa_lookup_enum_by_nr(modeA
));
484 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
485 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendEquationSeparatei(buffer=%u)",
490 if (!legal_blend_equation(ctx
, modeRGB
)) {
491 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeRGB)");
495 if (!legal_blend_equation(ctx
, modeA
)) {
496 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeA)");
500 if (ctx
->Color
.Blend
[buf
].EquationRGB
== modeRGB
&&
501 ctx
->Color
.Blend
[buf
].EquationA
== modeA
)
502 return; /* no change */
504 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
505 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
506 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
507 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
509 if (ctx
->Driver
.BlendEquationSeparatei
)
510 ctx
->Driver
.BlendEquationSeparatei(ctx
, buf
, modeRGB
, modeA
);
515 * Set the blending color.
517 * \param red red color component.
518 * \param green green color component.
519 * \param blue blue color component.
520 * \param alpha alpha color component.
522 * \sa glBlendColor().
524 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
525 * change, flushes the vertices and notifies the driver via
526 * dd_function_table::BlendColor callback.
529 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
532 GET_CURRENT_CONTEXT(ctx
);
539 if (TEST_EQ_4V(tmp
, ctx
->Color
.BlendColorUnclamped
))
542 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
543 COPY_4FV( ctx
->Color
.BlendColorUnclamped
, tmp
);
545 ctx
->Color
.BlendColor
[0] = CLAMP(tmp
[0], 0.0F
, 1.0F
);
546 ctx
->Color
.BlendColor
[1] = CLAMP(tmp
[1], 0.0F
, 1.0F
);
547 ctx
->Color
.BlendColor
[2] = CLAMP(tmp
[2], 0.0F
, 1.0F
);
548 ctx
->Color
.BlendColor
[3] = CLAMP(tmp
[3], 0.0F
, 1.0F
);
550 if (ctx
->Driver
.BlendColor
)
551 (*ctx
->Driver
.BlendColor
)(ctx
, ctx
->Color
.BlendColor
);
556 * Specify the alpha test function.
558 * \param func alpha comparison function.
559 * \param ref reference value.
561 * Verifies the parameters and updates gl_colorbuffer_attrib.
562 * On a change, flushes the vertices and notifies the driver via
563 * dd_function_table::AlphaFunc callback.
566 _mesa_AlphaFunc( GLenum func
, GLclampf ref
)
568 GET_CURRENT_CONTEXT(ctx
);
570 if (MESA_VERBOSE
& VERBOSE_API
)
571 _mesa_debug(ctx
, "glAlphaFunc(%s, %f)\n",
572 _mesa_lookup_enum_by_nr(func
), ref
);
583 if (ctx
->Color
.AlphaFunc
== func
&& ctx
->Color
.AlphaRefUnclamped
== ref
)
584 return; /* no change */
586 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
587 ctx
->Color
.AlphaFunc
= func
;
588 ctx
->Color
.AlphaRefUnclamped
= ref
;
589 ctx
->Color
.AlphaRef
= CLAMP(ref
, 0.0F
, 1.0F
);
591 if (ctx
->Driver
.AlphaFunc
)
592 ctx
->Driver
.AlphaFunc(ctx
, func
, ctx
->Color
.AlphaRef
);
596 _mesa_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
603 * Specify a logic pixel operation for color index rendering.
605 * \param opcode operation.
607 * Verifies that \p opcode is a valid enum and updates
608 gl_colorbuffer_attrib::LogicOp.
609 * On a change, flushes the vertices and notifies the driver via the
610 * dd_function_table::LogicOpcode callback.
613 _mesa_LogicOp( GLenum opcode
)
615 GET_CURRENT_CONTEXT(ctx
);
617 if (MESA_VERBOSE
& VERBOSE_API
)
618 _mesa_debug(ctx
, "glLogicOp(%s)\n", _mesa_lookup_enum_by_nr(opcode
));
624 case GL_COPY_INVERTED
:
634 case GL_AND_INVERTED
:
639 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLogicOp" );
643 if (ctx
->Color
.LogicOp
== opcode
)
646 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
647 ctx
->Color
.LogicOp
= opcode
;
649 if (ctx
->Driver
.LogicOpcode
)
650 ctx
->Driver
.LogicOpcode( ctx
, opcode
);
655 _mesa_IndexMask( GLuint mask
)
657 GET_CURRENT_CONTEXT(ctx
);
659 if (ctx
->Color
.IndexMask
== mask
)
662 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
663 ctx
->Color
.IndexMask
= mask
;
668 * Enable or disable writing of frame buffer color components.
670 * \param red whether to mask writing of the red color component.
671 * \param green whether to mask writing of the green color component.
672 * \param blue whether to mask writing of the blue color component.
673 * \param alpha whether to mask writing of the alpha color component.
677 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
678 * change, flushes the vertices and notifies the driver via the
679 * dd_function_table::ColorMask callback.
682 _mesa_ColorMask( GLboolean red
, GLboolean green
,
683 GLboolean blue
, GLboolean alpha
)
685 GET_CURRENT_CONTEXT(ctx
);
690 if (MESA_VERBOSE
& VERBOSE_API
)
691 _mesa_debug(ctx
, "glColorMask(%d, %d, %d, %d)\n",
692 red
, green
, blue
, alpha
);
694 /* Shouldn't have any information about channel depth in core mesa
695 * -- should probably store these as the native booleans:
697 tmp
[RCOMP
] = red
? 0xff : 0x0;
698 tmp
[GCOMP
] = green
? 0xff : 0x0;
699 tmp
[BCOMP
] = blue
? 0xff : 0x0;
700 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
703 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
704 if (!TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[i
])) {
706 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
709 COPY_4UBV(ctx
->Color
.ColorMask
[i
], tmp
);
713 if (ctx
->Driver
.ColorMask
)
714 ctx
->Driver
.ColorMask( ctx
, red
, green
, blue
, alpha
);
719 * For GL_EXT_draw_buffers2 and GL3
722 _mesa_ColorMaski( GLuint buf
, GLboolean red
, GLboolean green
,
723 GLboolean blue
, GLboolean alpha
)
726 GET_CURRENT_CONTEXT(ctx
);
728 if (MESA_VERBOSE
& VERBOSE_API
)
729 _mesa_debug(ctx
, "glColorMaskIndexed %u %d %d %d %d\n",
730 buf
, red
, green
, blue
, alpha
);
732 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
733 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorMaskIndexed(buf=%u)", buf
);
737 /* Shouldn't have any information about channel depth in core mesa
738 * -- should probably store these as the native booleans:
740 tmp
[RCOMP
] = red
? 0xff : 0x0;
741 tmp
[GCOMP
] = green
? 0xff : 0x0;
742 tmp
[BCOMP
] = blue
? 0xff : 0x0;
743 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
745 if (TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[buf
]))
748 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
749 COPY_4UBV(ctx
->Color
.ColorMask
[buf
], tmp
);
751 if (ctx
->Driver
.ColorMaskIndexed
)
752 ctx
->Driver
.ColorMaskIndexed(ctx
, buf
, red
, green
, blue
, alpha
);
757 _mesa_ClampColor(GLenum target
, GLenum clamp
)
759 GET_CURRENT_CONTEXT(ctx
);
761 if (clamp
!= GL_TRUE
&& clamp
!= GL_FALSE
&& clamp
!= GL_FIXED_ONLY_ARB
) {
762 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColorARB(clamp)");
767 case GL_CLAMP_VERTEX_COLOR_ARB
:
768 if (ctx
->API
== API_OPENGL_CORE
&&
769 !ctx
->Extensions
.ARB_color_buffer_float
) {
772 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
773 ctx
->Light
.ClampVertexColor
= clamp
;
774 _mesa_update_clamp_vertex_color(ctx
);
776 case GL_CLAMP_FRAGMENT_COLOR_ARB
:
777 if (ctx
->API
== API_OPENGL_CORE
&&
778 !ctx
->Extensions
.ARB_color_buffer_float
) {
781 FLUSH_VERTICES(ctx
, _NEW_FRAG_CLAMP
);
782 ctx
->Color
.ClampFragmentColor
= clamp
;
783 _mesa_update_clamp_fragment_color(ctx
);
785 case GL_CLAMP_READ_COLOR_ARB
:
786 ctx
->Color
.ClampReadColor
= clamp
;
794 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColor(%s)",
795 _mesa_lookup_enum_by_nr(target
));
799 get_clamp_color(const struct gl_framebuffer
*fb
, GLenum clamp
)
801 if (clamp
== GL_TRUE
|| clamp
== GL_FALSE
)
804 ASSERT(clamp
== GL_FIXED_ONLY
);
808 return fb
->_AllColorBuffersFixedPoint
;
812 _mesa_get_clamp_fragment_color(const struct gl_context
*ctx
)
814 return get_clamp_color(ctx
->DrawBuffer
,
815 ctx
->Color
.ClampFragmentColor
);
819 _mesa_get_clamp_vertex_color(const struct gl_context
*ctx
)
821 return get_clamp_color(ctx
->DrawBuffer
, ctx
->Light
.ClampVertexColor
);
825 _mesa_get_clamp_read_color(const struct gl_context
*ctx
)
827 return get_clamp_color(ctx
->ReadBuffer
, ctx
->Color
.ClampReadColor
);
831 * Update the ctx->Color._ClampFragmentColor field
834 _mesa_update_clamp_fragment_color(struct gl_context
*ctx
)
836 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
839 * - there is no colorbuffer
840 * - all colorbuffers are unsigned normalized, so clamping has no effect
841 * - there is an integer colorbuffer
843 if (!fb
|| !fb
->_HasSNormOrFloatColorBuffer
|| fb
->_IntegerColor
)
844 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
846 ctx
->Color
._ClampFragmentColor
= _mesa_get_clamp_fragment_color(ctx
);
850 * Update the ctx->Color._ClampVertexColor field
853 _mesa_update_clamp_vertex_color(struct gl_context
*ctx
)
855 ctx
->Light
._ClampVertexColor
= _mesa_get_clamp_vertex_color(ctx
);
859 * Returns an appropriate gl_format for color rendering based on the
860 * GL_FRAMEBUFFER_SRGB state.
862 * Some drivers implement GL_FRAMEBUFFER_SRGB using a flag on the blend state
863 * (which GL_FRAMEBUFFER_SRGB maps to reasonably), but some have to do so by
864 * overriding the format of the surface. This is a helper for doing the
865 * surface format override variant.
868 _mesa_get_render_format(const struct gl_context
*ctx
, gl_format format
)
870 if (ctx
->Color
.sRGBEnabled
)
873 return _mesa_get_srgb_format_linear(format
);
876 /**********************************************************************/
877 /** \name Initialization */
881 * Initialization of the context's Color attribute group.
883 * \param ctx GL context.
885 * Initializes the related fields in the context color attribute group,
886 * __struct gl_contextRec::Color.
888 void _mesa_init_color( struct gl_context
* ctx
)
892 /* Color buffer group */
893 ctx
->Color
.IndexMask
= ~0u;
894 memset(ctx
->Color
.ColorMask
, 0xff, sizeof(ctx
->Color
.ColorMask
));
895 ctx
->Color
.ClearIndex
= 0;
896 ASSIGN_4V( ctx
->Color
.ClearColor
.f
, 0, 0, 0, 0 );
897 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
898 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
899 ctx
->Color
.AlphaRef
= 0;
900 ctx
->Color
.BlendEnabled
= 0x0;
901 for (i
= 0; i
< Elements(ctx
->Color
.Blend
); i
++) {
902 ctx
->Color
.Blend
[i
].SrcRGB
= GL_ONE
;
903 ctx
->Color
.Blend
[i
].DstRGB
= GL_ZERO
;
904 ctx
->Color
.Blend
[i
].SrcA
= GL_ONE
;
905 ctx
->Color
.Blend
[i
].DstA
= GL_ZERO
;
906 ctx
->Color
.Blend
[i
].EquationRGB
= GL_FUNC_ADD
;
907 ctx
->Color
.Blend
[i
].EquationA
= GL_FUNC_ADD
;
909 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
910 ASSIGN_4V( ctx
->Color
.BlendColorUnclamped
, 0.0, 0.0, 0.0, 0.0 );
911 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
912 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
913 ctx
->Color
.LogicOp
= GL_COPY
;
914 ctx
->Color
.DitherFlag
= GL_TRUE
;
916 if (ctx
->Visual
.doubleBufferMode
) {
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
;