7 * Mesa 3-D graphics library
10 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
26 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
27 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28 * OTHER DEALINGS IN THE SOFTWARE.
43 * Check if given blend source factor is legal.
44 * \return GL_TRUE if legal, GL_FALSE otherwise.
47 legal_src_factor(const struct gl_context
*ctx
, GLenum factor
)
51 case GL_ONE_MINUS_SRC_COLOR
:
52 return ctx
->Extensions
.NV_blend_square
;
56 case GL_ONE_MINUS_DST_COLOR
:
58 case GL_ONE_MINUS_SRC_ALPHA
:
60 case GL_ONE_MINUS_DST_ALPHA
:
61 case GL_SRC_ALPHA_SATURATE
:
63 case GL_CONSTANT_COLOR
:
64 case GL_ONE_MINUS_CONSTANT_COLOR
:
65 case GL_CONSTANT_ALPHA
:
66 case GL_ONE_MINUS_CONSTANT_ALPHA
:
67 return _mesa_is_desktop_gl(ctx
) || ctx
->API
== API_OPENGLES2
;
70 case GL_ONE_MINUS_SRC1_COLOR
:
71 case GL_ONE_MINUS_SRC1_ALPHA
:
72 return _mesa_is_desktop_gl(ctx
)
73 && ctx
->Extensions
.ARB_blend_func_extended
;
81 * Check if given blend destination factor is legal.
82 * \return GL_TRUE if legal, GL_FALSE otherwise.
85 legal_dst_factor(const struct gl_context
*ctx
, GLenum factor
)
89 case GL_ONE_MINUS_DST_COLOR
:
90 return ctx
->Extensions
.NV_blend_square
;
94 case GL_ONE_MINUS_SRC_COLOR
:
96 case GL_ONE_MINUS_SRC_ALPHA
:
98 case GL_ONE_MINUS_DST_ALPHA
:
100 case GL_CONSTANT_COLOR
:
101 case GL_ONE_MINUS_CONSTANT_COLOR
:
102 case GL_CONSTANT_ALPHA
:
103 case GL_ONE_MINUS_CONSTANT_ALPHA
:
104 return _mesa_is_desktop_gl(ctx
) || ctx
->API
== API_OPENGLES2
;
105 case GL_SRC_ALPHA_SATURATE
:
106 return (_mesa_is_desktop_gl(ctx
)
107 && ctx
->Extensions
.ARB_blend_func_extended
)
108 || _mesa_is_gles3(ctx
);
111 case GL_ONE_MINUS_SRC1_COLOR
:
112 case GL_ONE_MINUS_SRC1_ALPHA
:
113 return _mesa_is_desktop_gl(ctx
)
114 && ctx
->Extensions
.ARB_blend_func_extended
;
122 * Check if src/dest RGB/A blend factors are legal. If not generate
124 * \return GL_TRUE if factors are legal, GL_FALSE otherwise.
127 validate_blend_factors(struct gl_context
*ctx
, const char *func
,
128 GLenum sfactorRGB
, GLenum dfactorRGB
,
129 GLenum sfactorA
, GLenum dfactorA
)
131 if (!legal_src_factor(ctx
, sfactorRGB
)) {
132 _mesa_error(ctx
, GL_INVALID_ENUM
,
133 "%s(sfactorRGB = %s)", func
,
134 _mesa_lookup_enum_by_nr(sfactorRGB
));
138 if (!legal_dst_factor(ctx
, dfactorRGB
)) {
139 _mesa_error(ctx
, GL_INVALID_ENUM
,
140 "%s(dfactorRGB = %s)", func
,
141 _mesa_lookup_enum_by_nr(dfactorRGB
));
145 if (sfactorA
!= sfactorRGB
&& !legal_src_factor(ctx
, sfactorA
)) {
146 _mesa_error(ctx
, GL_INVALID_ENUM
,
147 "%s(sfactorA = %s)", func
,
148 _mesa_lookup_enum_by_nr(sfactorA
));
152 if (dfactorA
!= dfactorRGB
&& !legal_dst_factor(ctx
, dfactorA
)) {
153 _mesa_error(ctx
, GL_INVALID_ENUM
,
154 "%s(dfactorA = %s)", func
,
155 _mesa_lookup_enum_by_nr(dfactorA
));
164 * Specify the blending operation.
166 * \param sfactor source factor operator.
167 * \param dfactor destination factor operator.
169 * \sa glBlendFunc, glBlendFuncSeparateEXT
172 _mesa_BlendFunc( GLenum sfactor
, GLenum dfactor
)
174 _mesa_BlendFuncSeparate(sfactor
, dfactor
, sfactor
, dfactor
);
178 blend_factor_is_dual_src(GLenum factor
)
180 return (factor
== GL_SRC1_COLOR
||
181 factor
== GL_SRC1_ALPHA
||
182 factor
== GL_ONE_MINUS_SRC1_COLOR
||
183 factor
== GL_ONE_MINUS_SRC1_ALPHA
);
187 update_uses_dual_src(struct gl_context
*ctx
, int buf
)
189 ctx
->Color
.Blend
[buf
]._UsesDualSrc
=
190 (blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].SrcRGB
) ||
191 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].DstRGB
) ||
192 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].SrcA
) ||
193 blend_factor_is_dual_src(ctx
->Color
.Blend
[buf
].DstA
));
197 * Set the separate blend source/dest factors for all draw buffers.
199 * \param sfactorRGB RGB source factor operator.
200 * \param dfactorRGB RGB destination factor operator.
201 * \param sfactorA alpha source factor operator.
202 * \param dfactorA alpha destination factor operator.
205 _mesa_BlendFuncSeparate( GLenum sfactorRGB
, GLenum dfactorRGB
,
206 GLenum sfactorA
, GLenum dfactorA
)
208 GLuint buf
, numBuffers
;
210 GET_CURRENT_CONTEXT(ctx
);
212 if (MESA_VERBOSE
& VERBOSE_API
)
213 _mesa_debug(ctx
, "glBlendFuncSeparate %s %s %s %s\n",
214 _mesa_lookup_enum_by_nr(sfactorRGB
),
215 _mesa_lookup_enum_by_nr(dfactorRGB
),
216 _mesa_lookup_enum_by_nr(sfactorA
),
217 _mesa_lookup_enum_by_nr(dfactorA
));
219 if (!validate_blend_factors(ctx
, "glBlendFuncSeparate",
220 sfactorRGB
, dfactorRGB
,
221 sfactorA
, dfactorA
)) {
225 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
226 ? ctx
->Const
.MaxDrawBuffers
: 1;
229 for (buf
= 0; buf
< numBuffers
; buf
++) {
230 if (ctx
->Color
.Blend
[buf
].SrcRGB
!= sfactorRGB
||
231 ctx
->Color
.Blend
[buf
].DstRGB
!= dfactorRGB
||
232 ctx
->Color
.Blend
[buf
].SrcA
!= sfactorA
||
233 ctx
->Color
.Blend
[buf
].DstA
!= dfactorA
) {
241 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
243 for (buf
= 0; buf
< numBuffers
; buf
++) {
244 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
245 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
246 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
247 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
248 update_uses_dual_src(ctx
, buf
);
250 ctx
->Color
._BlendFuncPerBuffer
= GL_FALSE
;
252 if (ctx
->Driver
.BlendFuncSeparate
) {
253 ctx
->Driver
.BlendFuncSeparate(ctx
, sfactorRGB
, dfactorRGB
,
260 * Set blend source/dest factors for one color buffer/target.
263 _mesa_BlendFunciARB(GLuint buf
, GLenum sfactor
, GLenum dfactor
)
265 _mesa_BlendFuncSeparateiARB(buf
, sfactor
, dfactor
, sfactor
, dfactor
);
270 * Set separate blend source/dest factors for one color buffer/target.
273 _mesa_BlendFuncSeparateiARB(GLuint buf
, GLenum sfactorRGB
, GLenum dfactorRGB
,
274 GLenum sfactorA
, GLenum dfactorA
)
276 GET_CURRENT_CONTEXT(ctx
);
278 if (!ctx
->Extensions
.ARB_draw_buffers_blend
) {
279 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBlendFunc[Separate]i()");
283 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
284 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
289 if (!validate_blend_factors(ctx
, "glBlendFuncSeparatei",
290 sfactorRGB
, dfactorRGB
,
291 sfactorA
, dfactorA
)) {
295 if (ctx
->Color
.Blend
[buf
].SrcRGB
== sfactorRGB
&&
296 ctx
->Color
.Blend
[buf
].DstRGB
== dfactorRGB
&&
297 ctx
->Color
.Blend
[buf
].SrcA
== sfactorA
&&
298 ctx
->Color
.Blend
[buf
].DstA
== dfactorA
)
299 return; /* no change */
301 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
303 ctx
->Color
.Blend
[buf
].SrcRGB
= sfactorRGB
;
304 ctx
->Color
.Blend
[buf
].DstRGB
= dfactorRGB
;
305 ctx
->Color
.Blend
[buf
].SrcA
= sfactorA
;
306 ctx
->Color
.Blend
[buf
].DstA
= dfactorA
;
307 update_uses_dual_src(ctx
, buf
);
308 ctx
->Color
._BlendFuncPerBuffer
= GL_TRUE
;
310 if (ctx
->Driver
.BlendFuncSeparatei
) {
311 ctx
->Driver
.BlendFuncSeparatei(ctx
, buf
, sfactorRGB
, dfactorRGB
,
318 * Check if given blend equation is legal.
319 * \return GL_TRUE if legal, GL_FALSE otherwise.
322 legal_blend_equation(const struct gl_context
*ctx
, GLenum mode
)
326 case GL_FUNC_SUBTRACT
:
327 case GL_FUNC_REVERSE_SUBTRACT
:
331 return ctx
->Extensions
.EXT_blend_minmax
;
338 /* This is really an extension function! */
340 _mesa_BlendEquation( GLenum mode
)
342 GLuint buf
, numBuffers
;
344 GET_CURRENT_CONTEXT(ctx
);
346 if (MESA_VERBOSE
& VERBOSE_API
)
347 _mesa_debug(ctx
, "glBlendEquation(%s)\n",
348 _mesa_lookup_enum_by_nr(mode
));
350 if (!legal_blend_equation(ctx
, mode
)) {
351 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
355 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
356 ? ctx
->Const
.MaxDrawBuffers
: 1;
359 for (buf
= 0; buf
< numBuffers
; buf
++) {
360 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= mode
||
361 ctx
->Color
.Blend
[buf
].EquationA
!= mode
) {
369 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
370 for (buf
= 0; buf
< numBuffers
; buf
++) {
371 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
372 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
374 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
376 if (ctx
->Driver
.BlendEquationSeparate
)
377 (*ctx
->Driver
.BlendEquationSeparate
)( ctx
, mode
, mode
);
382 * Set blend equation for one color buffer/target.
385 _mesa_BlendEquationiARB(GLuint buf
, GLenum mode
)
387 GET_CURRENT_CONTEXT(ctx
);
389 if (MESA_VERBOSE
& VERBOSE_API
)
390 _mesa_debug(ctx
, "glBlendEquationi(%u, %s)\n",
391 buf
, _mesa_lookup_enum_by_nr(mode
));
393 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
394 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendFuncSeparatei(buffer=%u)",
399 if (!legal_blend_equation(ctx
, mode
)) {
400 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationi");
404 if (ctx
->Color
.Blend
[buf
].EquationRGB
== mode
&&
405 ctx
->Color
.Blend
[buf
].EquationA
== mode
)
406 return; /* no change */
408 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
409 ctx
->Color
.Blend
[buf
].EquationRGB
= mode
;
410 ctx
->Color
.Blend
[buf
].EquationA
= mode
;
411 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
413 if (ctx
->Driver
.BlendEquationSeparatei
)
414 ctx
->Driver
.BlendEquationSeparatei(ctx
, buf
, mode
, mode
);
419 _mesa_BlendEquationSeparate( GLenum modeRGB
, GLenum modeA
)
421 GLuint buf
, numBuffers
;
423 GET_CURRENT_CONTEXT(ctx
);
425 if (MESA_VERBOSE
& VERBOSE_API
)
426 _mesa_debug(ctx
, "glBlendEquationSeparateEXT(%s %s)\n",
427 _mesa_lookup_enum_by_nr(modeRGB
),
428 _mesa_lookup_enum_by_nr(modeA
));
430 if ( (modeRGB
!= modeA
) && !ctx
->Extensions
.EXT_blend_equation_separate
) {
431 _mesa_error(ctx
, GL_INVALID_OPERATION
,
432 "glBlendEquationSeparateEXT not supported by driver");
436 if (!legal_blend_equation(ctx
, modeRGB
)) {
437 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeRGB)");
441 if (!legal_blend_equation(ctx
, modeA
)) {
442 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeA)");
446 numBuffers
= ctx
->Extensions
.ARB_draw_buffers_blend
447 ? ctx
->Const
.MaxDrawBuffers
: 1;
450 for (buf
= 0; buf
< numBuffers
; buf
++) {
451 if (ctx
->Color
.Blend
[buf
].EquationRGB
!= modeRGB
||
452 ctx
->Color
.Blend
[buf
].EquationA
!= modeA
) {
460 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
461 for (buf
= 0; buf
< numBuffers
; buf
++) {
462 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
463 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
465 ctx
->Color
._BlendEquationPerBuffer
= GL_FALSE
;
467 if (ctx
->Driver
.BlendEquationSeparate
)
468 ctx
->Driver
.BlendEquationSeparate(ctx
, modeRGB
, modeA
);
473 * Set separate blend equations for one color buffer/target.
476 _mesa_BlendEquationSeparateiARB(GLuint buf
, GLenum modeRGB
, GLenum modeA
)
478 GET_CURRENT_CONTEXT(ctx
);
480 if (MESA_VERBOSE
& VERBOSE_API
)
481 _mesa_debug(ctx
, "glBlendEquationSeparatei(%u, %s %s)\n", buf
,
482 _mesa_lookup_enum_by_nr(modeRGB
),
483 _mesa_lookup_enum_by_nr(modeA
));
485 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
486 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBlendEquationSeparatei(buffer=%u)",
491 if (!legal_blend_equation(ctx
, modeRGB
)) {
492 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeRGB)");
496 if (!legal_blend_equation(ctx
, modeA
)) {
497 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparatei(modeA)");
501 if (ctx
->Color
.Blend
[buf
].EquationRGB
== modeRGB
&&
502 ctx
->Color
.Blend
[buf
].EquationA
== modeA
)
503 return; /* no change */
505 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
506 ctx
->Color
.Blend
[buf
].EquationRGB
= modeRGB
;
507 ctx
->Color
.Blend
[buf
].EquationA
= modeA
;
508 ctx
->Color
._BlendEquationPerBuffer
= GL_TRUE
;
510 if (ctx
->Driver
.BlendEquationSeparatei
)
511 ctx
->Driver
.BlendEquationSeparatei(ctx
, buf
, modeRGB
, modeA
);
516 * Set the blending color.
518 * \param red red color component.
519 * \param green green color component.
520 * \param blue blue color component.
521 * \param alpha alpha color component.
523 * \sa glBlendColor().
525 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
526 * change, flushes the vertices and notifies the driver via
527 * dd_function_table::BlendColor callback.
530 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
533 GET_CURRENT_CONTEXT(ctx
);
540 if (TEST_EQ_4V(tmp
, ctx
->Color
.BlendColorUnclamped
))
543 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
544 COPY_4FV( ctx
->Color
.BlendColorUnclamped
, tmp
);
546 ctx
->Color
.BlendColor
[0] = CLAMP(tmp
[0], 0.0F
, 1.0F
);
547 ctx
->Color
.BlendColor
[1] = CLAMP(tmp
[1], 0.0F
, 1.0F
);
548 ctx
->Color
.BlendColor
[2] = CLAMP(tmp
[2], 0.0F
, 1.0F
);
549 ctx
->Color
.BlendColor
[3] = CLAMP(tmp
[3], 0.0F
, 1.0F
);
551 if (ctx
->Driver
.BlendColor
)
552 (*ctx
->Driver
.BlendColor
)(ctx
, ctx
->Color
.BlendColor
);
557 * Specify the alpha test function.
559 * \param func alpha comparison function.
560 * \param ref reference value.
562 * Verifies the parameters and updates gl_colorbuffer_attrib.
563 * On a change, flushes the vertices and notifies the driver via
564 * dd_function_table::AlphaFunc callback.
567 _mesa_AlphaFunc( GLenum func
, GLclampf ref
)
569 GET_CURRENT_CONTEXT(ctx
);
571 if (MESA_VERBOSE
& VERBOSE_API
)
572 _mesa_debug(ctx
, "glAlphaFunc(%s, %f)\n",
573 _mesa_lookup_enum_by_nr(func
), ref
);
584 if (ctx
->Color
.AlphaFunc
== func
&& ctx
->Color
.AlphaRefUnclamped
== ref
)
585 return; /* no change */
587 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
588 ctx
->Color
.AlphaFunc
= func
;
589 ctx
->Color
.AlphaRefUnclamped
= ref
;
590 ctx
->Color
.AlphaRef
= CLAMP(ref
, 0.0F
, 1.0F
);
592 if (ctx
->Driver
.AlphaFunc
)
593 ctx
->Driver
.AlphaFunc(ctx
, func
, ctx
->Color
.AlphaRef
);
597 _mesa_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
604 * Specify a logic pixel operation for color index rendering.
606 * \param opcode operation.
608 * Verifies that \p opcode is a valid enum and updates
609 gl_colorbuffer_attrib::LogicOp.
610 * On a change, flushes the vertices and notifies the driver via the
611 * dd_function_table::LogicOpcode callback.
614 _mesa_LogicOp( GLenum opcode
)
616 GET_CURRENT_CONTEXT(ctx
);
618 if (MESA_VERBOSE
& VERBOSE_API
)
619 _mesa_debug(ctx
, "glLogicOp(%s)\n", _mesa_lookup_enum_by_nr(opcode
));
625 case GL_COPY_INVERTED
:
635 case GL_AND_INVERTED
:
640 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLogicOp" );
644 if (ctx
->Color
.LogicOp
== opcode
)
647 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
648 ctx
->Color
.LogicOp
= opcode
;
650 if (ctx
->Driver
.LogicOpcode
)
651 ctx
->Driver
.LogicOpcode( ctx
, opcode
);
656 _mesa_IndexMask( GLuint mask
)
658 GET_CURRENT_CONTEXT(ctx
);
660 if (ctx
->Color
.IndexMask
== mask
)
663 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
664 ctx
->Color
.IndexMask
= mask
;
669 * Enable or disable writing of frame buffer color components.
671 * \param red whether to mask writing of the red color component.
672 * \param green whether to mask writing of the green color component.
673 * \param blue whether to mask writing of the blue color component.
674 * \param alpha whether to mask writing of the alpha color component.
678 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
679 * change, flushes the vertices and notifies the driver via the
680 * dd_function_table::ColorMask callback.
683 _mesa_ColorMask( GLboolean red
, GLboolean green
,
684 GLboolean blue
, GLboolean alpha
)
686 GET_CURRENT_CONTEXT(ctx
);
691 if (MESA_VERBOSE
& VERBOSE_API
)
692 _mesa_debug(ctx
, "glColorMask(%d, %d, %d, %d)\n",
693 red
, green
, blue
, alpha
);
695 /* Shouldn't have any information about channel depth in core mesa
696 * -- should probably store these as the native booleans:
698 tmp
[RCOMP
] = red
? 0xff : 0x0;
699 tmp
[GCOMP
] = green
? 0xff : 0x0;
700 tmp
[BCOMP
] = blue
? 0xff : 0x0;
701 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
704 for (i
= 0; i
< ctx
->Const
.MaxDrawBuffers
; i
++) {
705 if (!TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[i
])) {
707 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
710 COPY_4UBV(ctx
->Color
.ColorMask
[i
], tmp
);
714 if (ctx
->Driver
.ColorMask
)
715 ctx
->Driver
.ColorMask( ctx
, red
, green
, blue
, alpha
);
720 * For GL_EXT_draw_buffers2 and GL3
723 _mesa_ColorMaski( GLuint buf
, GLboolean red
, GLboolean green
,
724 GLboolean blue
, GLboolean alpha
)
727 GET_CURRENT_CONTEXT(ctx
);
729 if (MESA_VERBOSE
& VERBOSE_API
)
730 _mesa_debug(ctx
, "glColorMaskIndexed %u %d %d %d %d\n",
731 buf
, red
, green
, blue
, alpha
);
733 if (buf
>= ctx
->Const
.MaxDrawBuffers
) {
734 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorMaskIndexed(buf=%u)", buf
);
738 /* Shouldn't have any information about channel depth in core mesa
739 * -- should probably store these as the native booleans:
741 tmp
[RCOMP
] = red
? 0xff : 0x0;
742 tmp
[GCOMP
] = green
? 0xff : 0x0;
743 tmp
[BCOMP
] = blue
? 0xff : 0x0;
744 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
746 if (TEST_EQ_4V(tmp
, ctx
->Color
.ColorMask
[buf
]))
749 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
750 COPY_4UBV(ctx
->Color
.ColorMask
[buf
], tmp
);
752 if (ctx
->Driver
.ColorMaskIndexed
)
753 ctx
->Driver
.ColorMaskIndexed(ctx
, buf
, red
, green
, blue
, alpha
);
758 _mesa_ClampColor(GLenum target
, GLenum clamp
)
760 GET_CURRENT_CONTEXT(ctx
);
762 if (clamp
!= GL_TRUE
&& clamp
!= GL_FALSE
&& clamp
!= GL_FIXED_ONLY_ARB
) {
763 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColorARB(clamp)");
768 case GL_CLAMP_VERTEX_COLOR_ARB
:
769 if (ctx
->API
== API_OPENGL_CORE
&&
770 !ctx
->Extensions
.ARB_color_buffer_float
) {
773 FLUSH_VERTICES(ctx
, _NEW_LIGHT
);
774 ctx
->Light
.ClampVertexColor
= clamp
;
775 _mesa_update_clamp_vertex_color(ctx
);
777 case GL_CLAMP_FRAGMENT_COLOR_ARB
:
778 if (ctx
->API
== API_OPENGL_CORE
&&
779 !ctx
->Extensions
.ARB_color_buffer_float
) {
782 FLUSH_VERTICES(ctx
, _NEW_FRAG_CLAMP
);
783 ctx
->Color
.ClampFragmentColor
= clamp
;
784 _mesa_update_clamp_fragment_color(ctx
);
786 case GL_CLAMP_READ_COLOR_ARB
:
787 ctx
->Color
.ClampReadColor
= clamp
;
795 _mesa_error(ctx
, GL_INVALID_ENUM
, "glClampColor(%s)",
796 _mesa_lookup_enum_by_nr(target
));
800 get_clamp_color(const struct gl_framebuffer
*fb
, GLenum clamp
)
802 if (clamp
== GL_TRUE
|| clamp
== GL_FALSE
)
805 ASSERT(clamp
== GL_FIXED_ONLY
);
809 return fb
->_AllColorBuffersFixedPoint
;
813 _mesa_get_clamp_fragment_color(const struct gl_context
*ctx
)
815 return get_clamp_color(ctx
->DrawBuffer
,
816 ctx
->Color
.ClampFragmentColor
);
820 _mesa_get_clamp_vertex_color(const struct gl_context
*ctx
)
822 return get_clamp_color(ctx
->DrawBuffer
, ctx
->Light
.ClampVertexColor
);
826 _mesa_get_clamp_read_color(const struct gl_context
*ctx
)
828 return get_clamp_color(ctx
->ReadBuffer
, ctx
->Color
.ClampReadColor
);
832 * Update the ctx->Color._ClampFragmentColor field
835 _mesa_update_clamp_fragment_color(struct gl_context
*ctx
)
837 struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
840 * - there is no colorbuffer
841 * - all colorbuffers are unsigned normalized, so clamping has no effect
842 * - there is an integer colorbuffer
844 if (!fb
|| !fb
->_HasSNormOrFloatColorBuffer
|| fb
->_IntegerColor
)
845 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
847 ctx
->Color
._ClampFragmentColor
= _mesa_get_clamp_fragment_color(ctx
);
851 * Update the ctx->Color._ClampVertexColor field
854 _mesa_update_clamp_vertex_color(struct gl_context
*ctx
)
856 ctx
->Light
._ClampVertexColor
= _mesa_get_clamp_vertex_color(ctx
);
860 /**********************************************************************/
861 /** \name Initialization */
865 * Initialization of the context's Color attribute group.
867 * \param ctx GL context.
869 * Initializes the related fields in the context color attribute group,
870 * __struct gl_contextRec::Color.
872 void _mesa_init_color( struct gl_context
* ctx
)
876 /* Color buffer group */
877 ctx
->Color
.IndexMask
= ~0u;
878 memset(ctx
->Color
.ColorMask
, 0xff, sizeof(ctx
->Color
.ColorMask
));
879 ctx
->Color
.ClearIndex
= 0;
880 ASSIGN_4V( ctx
->Color
.ClearColor
.f
, 0, 0, 0, 0 );
881 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
882 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
883 ctx
->Color
.AlphaRef
= 0;
884 ctx
->Color
.BlendEnabled
= 0x0;
885 for (i
= 0; i
< Elements(ctx
->Color
.Blend
); i
++) {
886 ctx
->Color
.Blend
[i
].SrcRGB
= GL_ONE
;
887 ctx
->Color
.Blend
[i
].DstRGB
= GL_ZERO
;
888 ctx
->Color
.Blend
[i
].SrcA
= GL_ONE
;
889 ctx
->Color
.Blend
[i
].DstA
= GL_ZERO
;
890 ctx
->Color
.Blend
[i
].EquationRGB
= GL_FUNC_ADD
;
891 ctx
->Color
.Blend
[i
].EquationA
= GL_FUNC_ADD
;
893 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
894 ASSIGN_4V( ctx
->Color
.BlendColorUnclamped
, 0.0, 0.0, 0.0, 0.0 );
895 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
896 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
897 ctx
->Color
.LogicOp
= GL_COPY
;
898 ctx
->Color
.DitherFlag
= GL_TRUE
;
900 if (ctx
->Visual
.doubleBufferMode
) {
901 ctx
->Color
.DrawBuffer
[0] = GL_BACK
;
904 ctx
->Color
.DrawBuffer
[0] = GL_FRONT
;
907 ctx
->Color
.ClampFragmentColor
= ctx
->API
== API_OPENGL_COMPAT
?
908 GL_FIXED_ONLY_ARB
: GL_FALSE
;
909 ctx
->Color
._ClampFragmentColor
= GL_FALSE
;
910 ctx
->Color
.ClampReadColor
= GL_FIXED_ONLY_ARB
;
912 if (ctx
->API
== API_OPENGLES2
) {
913 /* GLES 3 behaves as though GL_FRAMEBUFFER_SRGB is always enabled. */
914 ctx
->Color
.sRGBEnabled
= GL_TRUE
;
916 ctx
->Color
.sRGBEnabled
= GL_FALSE
;