7 * Mesa 3-D graphics library
10 * Copyright (C) 1999-2004 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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 * Specify the blending operation.
44 * \param sfactor source factor operator.
45 * \param dfactor destination factor operator.
47 * \sa glBlendFunc, glBlendFuncSeparateEXT
49 * Swizzles the inputs and calls \c glBlendFuncSeparateEXT. This is done
50 * using the \c CurrentDispatch table in the context, so this same function
51 * can be used while compiling display lists. Therefore, there is no need
52 * for the display list code to save and restore this function.
55 _mesa_BlendFunc( GLenum sfactor
, GLenum dfactor
)
57 GET_CURRENT_CONTEXT(ctx
);
59 (*ctx
->CurrentDispatch
->BlendFuncSeparateEXT
)( sfactor
, dfactor
,
65 * Process GL_EXT_blend_func_separate().
67 * \param sfactorRGB RGB source factor operator.
68 * \param dfactorRGB RGB destination factor operator.
69 * \param sfactorA alpha source factor operator.
70 * \param dfactorA alpha destination factor operator.
72 * Verifies the parameters and updates gl_colorbuffer_attrib.
73 * On a change, flush the vertices and notify the driver via
74 * dd_function_table::BlendFuncSeparate.
77 _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB
, GLenum dfactorRGB
,
78 GLenum sfactorA
, GLenum dfactorA
)
80 GET_CURRENT_CONTEXT(ctx
);
81 ASSERT_OUTSIDE_BEGIN_END(ctx
);
83 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
84 _mesa_debug(ctx
, "glBlendFuncSeparate %s %s %s %s\n",
85 _mesa_lookup_enum_by_nr(sfactorRGB
),
86 _mesa_lookup_enum_by_nr(dfactorRGB
),
87 _mesa_lookup_enum_by_nr(sfactorA
),
88 _mesa_lookup_enum_by_nr(dfactorA
));
92 case GL_ONE_MINUS_SRC_COLOR
:
93 if (!ctx
->Extensions
.NV_blend_square
) {
94 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendFunc or glBlendFuncSeparate (sfactorRGB)");
101 case GL_ONE_MINUS_DST_COLOR
:
103 case GL_ONE_MINUS_SRC_ALPHA
:
105 case GL_ONE_MINUS_DST_ALPHA
:
106 case GL_SRC_ALPHA_SATURATE
:
107 case GL_CONSTANT_COLOR
:
108 case GL_ONE_MINUS_CONSTANT_COLOR
:
109 case GL_CONSTANT_ALPHA
:
110 case GL_ONE_MINUS_CONSTANT_ALPHA
:
113 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendFunc or glBlendFuncSeparate (sfactorRGB)");
117 switch (dfactorRGB
) {
119 case GL_ONE_MINUS_DST_COLOR
:
120 if (!ctx
->Extensions
.NV_blend_square
) {
121 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendFunc or glBlendFuncSeparate (dfactorRGB)");
128 case GL_ONE_MINUS_SRC_COLOR
:
130 case GL_ONE_MINUS_SRC_ALPHA
:
132 case GL_ONE_MINUS_DST_ALPHA
:
133 case GL_CONSTANT_COLOR
:
134 case GL_ONE_MINUS_CONSTANT_COLOR
:
135 case GL_CONSTANT_ALPHA
:
136 case GL_ONE_MINUS_CONSTANT_ALPHA
:
139 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendFunc or glBlendFuncSeparate (dfactorRGB)");
145 case GL_ONE_MINUS_SRC_COLOR
:
146 if (!ctx
->Extensions
.NV_blend_square
) {
147 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendFunc or glBlendFuncSeparate (sfactorA)");
154 case GL_ONE_MINUS_DST_COLOR
:
156 case GL_ONE_MINUS_SRC_ALPHA
:
158 case GL_ONE_MINUS_DST_ALPHA
:
159 case GL_SRC_ALPHA_SATURATE
:
160 case GL_CONSTANT_COLOR
:
161 case GL_ONE_MINUS_CONSTANT_COLOR
:
162 case GL_CONSTANT_ALPHA
:
163 case GL_ONE_MINUS_CONSTANT_ALPHA
:
166 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendFunc or glBlendFuncSeparate (sfactorA)");
172 case GL_ONE_MINUS_DST_COLOR
:
173 if (!ctx
->Extensions
.NV_blend_square
) {
174 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendFunc or glBlendFuncSeparate (dfactorA)");
181 case GL_ONE_MINUS_SRC_COLOR
:
183 case GL_ONE_MINUS_SRC_ALPHA
:
185 case GL_ONE_MINUS_DST_ALPHA
:
186 case GL_CONSTANT_COLOR
:
187 case GL_ONE_MINUS_CONSTANT_COLOR
:
188 case GL_CONSTANT_ALPHA
:
189 case GL_ONE_MINUS_CONSTANT_ALPHA
:
192 _mesa_error( ctx
, GL_INVALID_ENUM
, "glBlendFunc or glBlendFuncSeparate (dfactorA)" );
196 if (ctx
->Color
.BlendSrcRGB
== sfactorRGB
&&
197 ctx
->Color
.BlendDstRGB
== dfactorRGB
&&
198 ctx
->Color
.BlendSrcA
== sfactorA
&&
199 ctx
->Color
.BlendDstA
== dfactorA
)
202 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
204 ctx
->Color
.BlendSrcRGB
= sfactorRGB
;
205 ctx
->Color
.BlendDstRGB
= dfactorRGB
;
206 ctx
->Color
.BlendSrcA
= sfactorA
;
207 ctx
->Color
.BlendDstA
= dfactorA
;
209 if (ctx
->Driver
.BlendFuncSeparate
) {
210 (*ctx
->Driver
.BlendFuncSeparate
)( ctx
, sfactorRGB
, dfactorRGB
,
211 sfactorA
, dfactorA
);
219 _mesa_validate_blend_equation( GLcontext
*ctx
,
220 GLenum mode
, GLboolean is_separate
)
227 if (!ctx
->Extensions
.EXT_blend_minmax
&&
228 !ctx
->Extensions
.ARB_imaging
) {
232 /* glBlendEquationSeparate cannot take GL_LOGIC_OP as a parameter.
235 if (!ctx
->Extensions
.EXT_blend_logic_op
|| is_separate
) {
239 case GL_FUNC_SUBTRACT
:
240 case GL_FUNC_REVERSE_SUBTRACT
:
241 if (!ctx
->Extensions
.EXT_blend_subtract
&&
242 !ctx
->Extensions
.ARB_imaging
) {
254 /* This is really an extension function! */
256 _mesa_BlendEquation( GLenum mode
)
258 GET_CURRENT_CONTEXT(ctx
);
259 ASSERT_OUTSIDE_BEGIN_END(ctx
);
261 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
262 _mesa_debug(ctx
, "glBlendEquation %s\n",
263 _mesa_lookup_enum_by_nr(mode
));
265 if ( ! _mesa_validate_blend_equation( ctx
, mode
, GL_FALSE
) ) {
266 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquation");
270 if ( (ctx
->Color
.BlendEquationRGB
== mode
) &&
271 (ctx
->Color
.BlendEquationA
== mode
) )
274 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
275 ctx
->Color
.BlendEquationRGB
= mode
;
276 ctx
->Color
.BlendEquationA
= mode
;
278 /* This is needed to support 1.1's RGB logic ops AND
279 * 1.0's blending logicops.
281 ctx
->Color
._LogicOpEnabled
= (ctx
->Color
.ColorLogicOpEnabled
||
282 (ctx
->Color
.BlendEnabled
&&
283 mode
== GL_LOGIC_OP
));
285 if (ctx
->Driver
.BlendEquationSeparate
)
286 (*ctx
->Driver
.BlendEquationSeparate
)( ctx
, mode
, mode
);
291 _mesa_BlendEquationSeparateEXT( GLenum modeRGB
, GLenum modeA
)
293 GET_CURRENT_CONTEXT(ctx
);
294 ASSERT_OUTSIDE_BEGIN_END(ctx
);
296 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
297 _mesa_debug(ctx
, "glBlendEquationSeparateEXT %s %s\n",
298 _mesa_lookup_enum_by_nr(modeRGB
),
299 _mesa_lookup_enum_by_nr(modeA
));
301 if ( (modeRGB
!= modeA
) && !ctx
->Extensions
.EXT_blend_equation_separate
) {
302 _mesa_error(ctx
, GL_INVALID_OPERATION
,
303 "glBlendEquationSeparateEXT not supported by driver");
307 if ( ! _mesa_validate_blend_equation( ctx
, modeRGB
, GL_TRUE
) ) {
308 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeRGB)");
312 if ( ! _mesa_validate_blend_equation( ctx
, modeA
, GL_TRUE
) ) {
313 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBlendEquationSeparateEXT(modeA)");
318 if ( (ctx
->Color
.BlendEquationRGB
== modeRGB
) &&
319 (ctx
->Color
.BlendEquationA
== modeA
) )
322 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
323 ctx
->Color
.BlendEquationRGB
= modeRGB
;
324 ctx
->Color
.BlendEquationA
= modeA
;
326 /* This is needed to support 1.1's RGB logic ops AND
327 * 1.0's blending logicops. This test is simplified over glBlendEquation
328 * because modeRGB cannot be GL_LOGIC_OP.
330 ctx
->Color
._LogicOpEnabled
= (ctx
->Color
.ColorLogicOpEnabled
);
332 if (ctx
->Driver
.BlendEquationSeparate
)
333 (*ctx
->Driver
.BlendEquationSeparate
)( ctx
, modeRGB
, modeA
);
339 * Set the blending color.
341 * \param red red color component.
342 * \param green green color component.
343 * \param blue blue color component.
344 * \param alpha alpha color component.
346 * \sa glBlendColor().
348 * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a
349 * change, flushes the vertices and notifies the driver via
350 * dd_function_table::BlendColor callback.
353 _mesa_BlendColor( GLclampf red
, GLclampf green
, GLclampf blue
, GLclampf alpha
)
356 GET_CURRENT_CONTEXT(ctx
);
357 ASSERT_OUTSIDE_BEGIN_END(ctx
);
359 tmp
[0] = CLAMP( red
, 0.0F
, 1.0F
);
360 tmp
[1] = CLAMP( green
, 0.0F
, 1.0F
);
361 tmp
[2] = CLAMP( blue
, 0.0F
, 1.0F
);
362 tmp
[3] = CLAMP( alpha
, 0.0F
, 1.0F
);
364 if (TEST_EQ_4V(tmp
, ctx
->Color
.BlendColor
))
367 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
368 COPY_4FV( ctx
->Color
.BlendColor
, tmp
);
370 if (ctx
->Driver
.BlendColor
)
371 (*ctx
->Driver
.BlendColor
)(ctx
, tmp
);
376 * Specify the alpha test function.
378 * \param func alpha comparison function.
379 * \param ref reference value.
381 * Verifies the parameters and updates gl_colorbuffer_attrib.
382 * On a change, flushes the vertices and notifies the driver via
383 * dd_function_table::AlphaFunc callback.
386 _mesa_AlphaFunc( GLenum func
, GLclampf ref
)
388 GET_CURRENT_CONTEXT(ctx
);
389 ASSERT_OUTSIDE_BEGIN_END(ctx
);
400 ref
= CLAMP(ref
, 0.0F
, 1.0F
);
402 if (ctx
->Color
.AlphaFunc
== func
&& ctx
->Color
.AlphaRef
== ref
)
403 return; /* no change */
405 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
406 ctx
->Color
.AlphaFunc
= func
;
407 ctx
->Color
.AlphaRef
= ref
;
409 if (ctx
->Driver
.AlphaFunc
)
410 ctx
->Driver
.AlphaFunc(ctx
, func
, ref
);
414 _mesa_error( ctx
, GL_INVALID_ENUM
, "glAlphaFunc(func)" );
421 * Specify a logic pixel operation for color index rendering.
423 * \param opcode operation.
425 * Verifies that \p opcode is a valid enum and updates
426 gl_colorbuffer_attrib::LogicOp.
427 * On a change, flushes the vertices and notifies the driver via the
428 * dd_function_table::LogicOpcode callback.
431 _mesa_LogicOp( GLenum opcode
)
433 GET_CURRENT_CONTEXT(ctx
);
434 ASSERT_OUTSIDE_BEGIN_END(ctx
);
440 case GL_COPY_INVERTED
:
450 case GL_AND_INVERTED
:
455 _mesa_error( ctx
, GL_INVALID_ENUM
, "glLogicOp" );
459 if (ctx
->Color
.LogicOp
== opcode
)
462 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
463 ctx
->Color
.LogicOp
= opcode
;
465 if (ctx
->Driver
.LogicOpcode
)
466 ctx
->Driver
.LogicOpcode( ctx
, opcode
);
471 _mesa_IndexMask( GLuint mask
)
473 GET_CURRENT_CONTEXT(ctx
);
474 ASSERT_OUTSIDE_BEGIN_END(ctx
);
476 if (ctx
->Color
.IndexMask
== mask
)
479 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
480 ctx
->Color
.IndexMask
= mask
;
482 if (ctx
->Driver
.IndexMask
)
483 ctx
->Driver
.IndexMask( ctx
, mask
);
489 * Enable or disable writing of frame buffer color components.
491 * \param red whether to mask writing of the red color component.
492 * \param green whether to mask writing of the green color component.
493 * \param blue whether to mask writing of the blue color component.
494 * \param alpha whether to mask writing of the alpha color component.
498 * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a
499 * change, flushes the vertices and notifies the driver via the
500 * dd_function_table::ColorMask callback.
503 _mesa_ColorMask( GLboolean red
, GLboolean green
,
504 GLboolean blue
, GLboolean alpha
)
506 GET_CURRENT_CONTEXT(ctx
);
508 ASSERT_OUTSIDE_BEGIN_END(ctx
);
510 if (MESA_VERBOSE
& VERBOSE_API
)
511 _mesa_debug(ctx
, "glColorMask %d %d %d %d\n", red
, green
, blue
, alpha
);
513 /* Shouldn't have any information about channel depth in core mesa
514 * -- should probably store these as the native booleans:
516 tmp
[RCOMP
] = red
? 0xff : 0x0;
517 tmp
[GCOMP
] = green
? 0xff : 0x0;
518 tmp
[BCOMP
] = blue
? 0xff : 0x0;
519 tmp
[ACOMP
] = alpha
? 0xff : 0x0;
521 if (TEST_EQ_4UBV(tmp
, ctx
->Color
.ColorMask
))
524 FLUSH_VERTICES(ctx
, _NEW_COLOR
);
525 COPY_4UBV(ctx
->Color
.ColorMask
, tmp
);
527 if (ctx
->Driver
.ColorMask
)
528 ctx
->Driver
.ColorMask( ctx
, red
, green
, blue
, alpha
);
532 /**********************************************************************/
533 /** \name Initialization */
537 * Initialization of the context's Color attribute group.
539 * \param ctx GL context.
541 * Initializes the related fields in the context color attribute group,
542 * __GLcontextRec::Color.
544 void _mesa_init_color( GLcontext
* ctx
)
546 /* Color buffer group */
547 ctx
->Color
.IndexMask
= ~0u;
548 ctx
->Color
.ColorMask
[0] = 0xff;
549 ctx
->Color
.ColorMask
[1] = 0xff;
550 ctx
->Color
.ColorMask
[2] = 0xff;
551 ctx
->Color
.ColorMask
[3] = 0xff;
552 ctx
->Color
.ClearIndex
= 0;
553 ASSIGN_4V( ctx
->Color
.ClearColor
, 0, 0, 0, 0 );
554 ctx
->Color
.AlphaEnabled
= GL_FALSE
;
555 ctx
->Color
.AlphaFunc
= GL_ALWAYS
;
556 ctx
->Color
.AlphaRef
= 0;
557 ctx
->Color
.BlendEnabled
= GL_FALSE
;
558 ctx
->Color
.BlendSrcRGB
= GL_ONE
;
559 ctx
->Color
.BlendDstRGB
= GL_ZERO
;
560 ctx
->Color
.BlendSrcA
= GL_ONE
;
561 ctx
->Color
.BlendDstA
= GL_ZERO
;
562 ctx
->Color
.BlendEquationRGB
= GL_FUNC_ADD
;
563 ctx
->Color
.BlendEquationA
= GL_FUNC_ADD
;
564 ASSIGN_4V( ctx
->Color
.BlendColor
, 0.0, 0.0, 0.0, 0.0 );
565 ctx
->Color
.IndexLogicOpEnabled
= GL_FALSE
;
566 ctx
->Color
.ColorLogicOpEnabled
= GL_FALSE
;
567 ctx
->Color
._LogicOpEnabled
= GL_FALSE
;
568 ctx
->Color
.LogicOp
= GL_COPY
;
569 ctx
->Color
.DitherFlag
= GL_TRUE
;
571 if (ctx
->Visual
.doubleBufferMode
) {
572 ctx
->Color
.DrawBuffer
[0] = GL_BACK
;
575 ctx
->Color
.DrawBuffer
[0] = GL_FRONT
;