Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file blend.c |
| 3 | * Blending operations. |
| 4 | */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 5 | |
| 6 | /* |
| 7 | * Mesa 3-D graphics library |
Brian Paul | 813e56d | 2006-07-18 19:15:40 +0000 | [diff] [blame] | 8 | * Version: 6.5.1 |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 9 | * |
Brian Paul | 813e56d | 2006-07-18 19:15:40 +0000 | [diff] [blame] | 10 | * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 11 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 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: |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 18 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 19 | * The above copyright notice and this permission notice shall be included |
| 20 | * in all copies or substantial portions of the Software. |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 21 | * |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 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. |
| 28 | */ |
| 29 | |
| 30 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 31 | |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 32 | #include "glheader.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 33 | #include "blend.h" |
| 34 | #include "context.h" |
| 35 | #include "enums.h" |
| 36 | #include "macros.h" |
Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 37 | #include "mtypes.h" |
Brian Paul | 2dbc515 | 2008-06-13 16:45:15 -0600 | [diff] [blame] | 38 | #include "glapi/glapitable.h" |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 39 | |
| 40 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 41 | /** |
| 42 | * Specify the blending operation. |
| 43 | * |
| 44 | * \param sfactor source factor operator. |
| 45 | * \param dfactor destination factor operator. |
| 46 | * |
Ian Romanick | 20a17e4 | 2004-01-21 16:08:43 +0000 | [diff] [blame] | 47 | * \sa glBlendFunc, glBlendFuncSeparateEXT |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 48 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 49 | void GLAPIENTRY |
Brian Paul | b34024b | 2000-02-02 22:08:26 +0000 | [diff] [blame] | 50 | _mesa_BlendFunc( GLenum sfactor, GLenum dfactor ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 51 | { |
Brian Paul | 3a4bed8 | 2008-06-20 11:05:00 -0600 | [diff] [blame] | 52 | _mesa_BlendFuncSeparateEXT(sfactor, dfactor, sfactor, dfactor); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 56 | /** |
| 57 | * Process GL_EXT_blend_func_separate(). |
| 58 | * |
| 59 | * \param sfactorRGB RGB source factor operator. |
| 60 | * \param dfactorRGB RGB destination factor operator. |
| 61 | * \param sfactorA alpha source factor operator. |
| 62 | * \param dfactorA alpha destination factor operator. |
| 63 | * |
| 64 | * Verifies the parameters and updates gl_colorbuffer_attrib. |
| 65 | * On a change, flush the vertices and notify the driver via |
| 66 | * dd_function_table::BlendFuncSeparate. |
| 67 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 68 | void GLAPIENTRY |
Brian Paul | ead285a | 2000-02-24 22:04:03 +0000 | [diff] [blame] | 69 | _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB, |
| 70 | GLenum sfactorA, GLenum dfactorA ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 71 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 72 | GET_CURRENT_CONTEXT(ctx); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 73 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 74 | |
Brian Paul | d66965c | 2009-10-23 13:06:13 -0600 | [diff] [blame] | 75 | if (MESA_VERBOSE & VERBOSE_API) |
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 76 | _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n", |
| 77 | _mesa_lookup_enum_by_nr(sfactorRGB), |
| 78 | _mesa_lookup_enum_by_nr(dfactorRGB), |
| 79 | _mesa_lookup_enum_by_nr(sfactorA), |
| 80 | _mesa_lookup_enum_by_nr(dfactorA)); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 81 | |
| 82 | switch (sfactorRGB) { |
Brian Paul | ad68f17 | 2000-05-30 02:28:03 +0000 | [diff] [blame] | 83 | case GL_SRC_COLOR: |
| 84 | case GL_ONE_MINUS_SRC_COLOR: |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 85 | if (!ctx->Extensions.NV_blend_square) { |
Ian Romanick | ff2cc41 | 2004-01-23 07:57:32 +0000 | [diff] [blame] | 86 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (sfactorRGB)"); |
Brian Paul | ad68f17 | 2000-05-30 02:28:03 +0000 | [diff] [blame] | 87 | return; |
| 88 | } |
| 89 | /* fall-through */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 90 | case GL_ZERO: |
| 91 | case GL_ONE: |
| 92 | case GL_DST_COLOR: |
| 93 | case GL_ONE_MINUS_DST_COLOR: |
| 94 | case GL_SRC_ALPHA: |
| 95 | case GL_ONE_MINUS_SRC_ALPHA: |
| 96 | case GL_DST_ALPHA: |
| 97 | case GL_ONE_MINUS_DST_ALPHA: |
| 98 | case GL_SRC_ALPHA_SATURATE: |
| 99 | case GL_CONSTANT_COLOR: |
| 100 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 101 | case GL_CONSTANT_ALPHA: |
| 102 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 103 | break; |
| 104 | default: |
Ian Romanick | ff2cc41 | 2004-01-23 07:57:32 +0000 | [diff] [blame] | 105 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (sfactorRGB)"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 106 | return; |
| 107 | } |
| 108 | |
| 109 | switch (dfactorRGB) { |
Brian Paul | ad68f17 | 2000-05-30 02:28:03 +0000 | [diff] [blame] | 110 | case GL_DST_COLOR: |
| 111 | case GL_ONE_MINUS_DST_COLOR: |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 112 | if (!ctx->Extensions.NV_blend_square) { |
Ian Romanick | ff2cc41 | 2004-01-23 07:57:32 +0000 | [diff] [blame] | 113 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (dfactorRGB)"); |
Brian Paul | ad68f17 | 2000-05-30 02:28:03 +0000 | [diff] [blame] | 114 | return; |
| 115 | } |
| 116 | /* fall-through */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 117 | case GL_ZERO: |
| 118 | case GL_ONE: |
| 119 | case GL_SRC_COLOR: |
| 120 | case GL_ONE_MINUS_SRC_COLOR: |
| 121 | case GL_SRC_ALPHA: |
| 122 | case GL_ONE_MINUS_SRC_ALPHA: |
| 123 | case GL_DST_ALPHA: |
| 124 | case GL_ONE_MINUS_DST_ALPHA: |
| 125 | case GL_CONSTANT_COLOR: |
| 126 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 127 | case GL_CONSTANT_ALPHA: |
| 128 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 129 | break; |
| 130 | default: |
Ian Romanick | ff2cc41 | 2004-01-23 07:57:32 +0000 | [diff] [blame] | 131 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (dfactorRGB)"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 132 | return; |
| 133 | } |
| 134 | |
| 135 | switch (sfactorA) { |
Brian Paul | ad68f17 | 2000-05-30 02:28:03 +0000 | [diff] [blame] | 136 | case GL_SRC_COLOR: |
| 137 | case GL_ONE_MINUS_SRC_COLOR: |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 138 | if (!ctx->Extensions.NV_blend_square) { |
Ian Romanick | ff2cc41 | 2004-01-23 07:57:32 +0000 | [diff] [blame] | 139 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (sfactorA)"); |
Brian Paul | ad68f17 | 2000-05-30 02:28:03 +0000 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | /* fall-through */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 143 | case GL_ZERO: |
| 144 | case GL_ONE: |
| 145 | case GL_DST_COLOR: |
| 146 | case GL_ONE_MINUS_DST_COLOR: |
| 147 | case GL_SRC_ALPHA: |
| 148 | case GL_ONE_MINUS_SRC_ALPHA: |
| 149 | case GL_DST_ALPHA: |
| 150 | case GL_ONE_MINUS_DST_ALPHA: |
| 151 | case GL_SRC_ALPHA_SATURATE: |
| 152 | case GL_CONSTANT_COLOR: |
| 153 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 154 | case GL_CONSTANT_ALPHA: |
| 155 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 156 | break; |
| 157 | default: |
Ian Romanick | ff2cc41 | 2004-01-23 07:57:32 +0000 | [diff] [blame] | 158 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (sfactorA)"); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | |
| 162 | switch (dfactorA) { |
Brian Paul | ad68f17 | 2000-05-30 02:28:03 +0000 | [diff] [blame] | 163 | case GL_DST_COLOR: |
| 164 | case GL_ONE_MINUS_DST_COLOR: |
Keith Whitwell | a96308c | 2000-10-30 13:31:59 +0000 | [diff] [blame] | 165 | if (!ctx->Extensions.NV_blend_square) { |
Ian Romanick | ff2cc41 | 2004-01-23 07:57:32 +0000 | [diff] [blame] | 166 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (dfactorA)"); |
Brian Paul | ad68f17 | 2000-05-30 02:28:03 +0000 | [diff] [blame] | 167 | return; |
| 168 | } |
| 169 | /* fall-through */ |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 170 | case GL_ZERO: |
| 171 | case GL_ONE: |
| 172 | case GL_SRC_COLOR: |
| 173 | case GL_ONE_MINUS_SRC_COLOR: |
| 174 | case GL_SRC_ALPHA: |
| 175 | case GL_ONE_MINUS_SRC_ALPHA: |
| 176 | case GL_DST_ALPHA: |
| 177 | case GL_ONE_MINUS_DST_ALPHA: |
| 178 | case GL_CONSTANT_COLOR: |
| 179 | case GL_ONE_MINUS_CONSTANT_COLOR: |
| 180 | case GL_CONSTANT_ALPHA: |
| 181 | case GL_ONE_MINUS_CONSTANT_ALPHA: |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 182 | break; |
| 183 | default: |
Ian Romanick | ff2cc41 | 2004-01-23 07:57:32 +0000 | [diff] [blame] | 184 | _mesa_error( ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (dfactorA)" ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 185 | return; |
| 186 | } |
| 187 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 188 | if (ctx->Color.BlendSrcRGB == sfactorRGB && |
| 189 | ctx->Color.BlendDstRGB == dfactorRGB && |
| 190 | ctx->Color.BlendSrcA == sfactorA && |
| 191 | ctx->Color.BlendDstA == dfactorA) |
| 192 | return; |
| 193 | |
| 194 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
| 195 | |
| 196 | ctx->Color.BlendSrcRGB = sfactorRGB; |
| 197 | ctx->Color.BlendDstRGB = dfactorRGB; |
| 198 | ctx->Color.BlendSrcA = sfactorA; |
| 199 | ctx->Color.BlendDstA = dfactorA; |
Keith Whitwell | 69cfdb2 | 1999-09-30 11:18:21 +0000 | [diff] [blame] | 200 | |
| 201 | if (ctx->Driver.BlendFuncSeparate) { |
| 202 | (*ctx->Driver.BlendFuncSeparate)( ctx, sfactorRGB, dfactorRGB, |
| 203 | sfactorA, dfactorA ); |
| 204 | } |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | |
Ian Romanick | 20a17e4 | 2004-01-21 16:08:43 +0000 | [diff] [blame] | 208 | #if _HAVE_FULL_GL |
| 209 | |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 210 | static GLboolean |
| 211 | _mesa_validate_blend_equation( GLcontext *ctx, |
| 212 | GLenum mode, GLboolean is_separate ) |
| 213 | { |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 214 | switch (mode) { |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 215 | case GL_FUNC_ADD: |
| 216 | break; |
| 217 | case GL_MIN: |
| 218 | case GL_MAX: |
| 219 | if (!ctx->Extensions.EXT_blend_minmax && |
| 220 | !ctx->Extensions.ARB_imaging) { |
| 221 | return GL_FALSE; |
| 222 | } |
| 223 | break; |
| 224 | /* glBlendEquationSeparate cannot take GL_LOGIC_OP as a parameter. |
| 225 | */ |
| 226 | case GL_LOGIC_OP: |
| 227 | if (!ctx->Extensions.EXT_blend_logic_op || is_separate) { |
| 228 | return GL_FALSE; |
| 229 | } |
| 230 | break; |
| 231 | case GL_FUNC_SUBTRACT: |
| 232 | case GL_FUNC_REVERSE_SUBTRACT: |
| 233 | if (!ctx->Extensions.EXT_blend_subtract && |
| 234 | !ctx->Extensions.ARB_imaging) { |
| 235 | return GL_FALSE; |
| 236 | } |
| 237 | break; |
| 238 | default: |
| 239 | return GL_FALSE; |
| 240 | } |
| 241 | |
| 242 | return GL_TRUE; |
| 243 | } |
| 244 | |
| 245 | |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 246 | /* This is really an extension function! */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 247 | void GLAPIENTRY |
Brian Paul | ead285a | 2000-02-24 22:04:03 +0000 | [diff] [blame] | 248 | _mesa_BlendEquation( GLenum mode ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 249 | { |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 250 | GET_CURRENT_CONTEXT(ctx); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 251 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 252 | |
Brian Paul | d66965c | 2009-10-23 13:06:13 -0600 | [diff] [blame] | 253 | if (MESA_VERBOSE & VERBOSE_API) |
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 254 | _mesa_debug(ctx, "glBlendEquation %s\n", |
| 255 | _mesa_lookup_enum_by_nr(mode)); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 256 | |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 257 | if ( ! _mesa_validate_blend_equation( ctx, mode, GL_FALSE ) ) { |
| 258 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquation"); |
| 259 | return; |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 262 | if ( (ctx->Color.BlendEquationRGB == mode) && |
| 263 | (ctx->Color.BlendEquationA == mode) ) |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 264 | return; |
Brian Paul | be3d539 | 2001-03-07 00:21:32 +0000 | [diff] [blame] | 265 | |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 266 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 267 | ctx->Color.BlendEquationRGB = mode; |
| 268 | ctx->Color.BlendEquationA = mode; |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 269 | |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 270 | if (ctx->Driver.BlendEquationSeparate) |
| 271 | (*ctx->Driver.BlendEquationSeparate)( ctx, mode, mode ); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 274 | |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 275 | void GLAPIENTRY |
| 276 | _mesa_BlendEquationSeparateEXT( GLenum modeRGB, GLenum modeA ) |
| 277 | { |
| 278 | GET_CURRENT_CONTEXT(ctx); |
| 279 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 280 | |
Brian Paul | d66965c | 2009-10-23 13:06:13 -0600 | [diff] [blame] | 281 | if (MESA_VERBOSE & VERBOSE_API) |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 282 | _mesa_debug(ctx, "glBlendEquationSeparateEXT %s %s\n", |
| 283 | _mesa_lookup_enum_by_nr(modeRGB), |
| 284 | _mesa_lookup_enum_by_nr(modeA)); |
| 285 | |
| 286 | if ( (modeRGB != modeA) && !ctx->Extensions.EXT_blend_equation_separate ) { |
| 287 | _mesa_error(ctx, GL_INVALID_OPERATION, |
| 288 | "glBlendEquationSeparateEXT not supported by driver"); |
| 289 | return; |
| 290 | } |
| 291 | |
| 292 | if ( ! _mesa_validate_blend_equation( ctx, modeRGB, GL_TRUE ) ) { |
| 293 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeRGB)"); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | if ( ! _mesa_validate_blend_equation( ctx, modeA, GL_TRUE ) ) { |
| 298 | _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeA)"); |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | |
| 303 | if ( (ctx->Color.BlendEquationRGB == modeRGB) && |
| 304 | (ctx->Color.BlendEquationA == modeA) ) |
| 305 | return; |
| 306 | |
| 307 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
| 308 | ctx->Color.BlendEquationRGB = modeRGB; |
| 309 | ctx->Color.BlendEquationA = modeA; |
| 310 | |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 311 | if (ctx->Driver.BlendEquationSeparate) |
| 312 | (*ctx->Driver.BlendEquationSeparate)( ctx, modeRGB, modeA ); |
| 313 | } |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 314 | #endif |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 315 | |
| 316 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 317 | /** |
| 318 | * Set the blending color. |
| 319 | * |
| 320 | * \param red red color component. |
| 321 | * \param green green color component. |
| 322 | * \param blue blue color component. |
| 323 | * \param alpha alpha color component. |
| 324 | * |
| 325 | * \sa glBlendColor(). |
| 326 | * |
| 327 | * Clamps the parameters and updates gl_colorbuffer_attrib::BlendColor. On a |
| 328 | * change, flushes the vertices and notifies the driver via |
| 329 | * dd_function_table::BlendColor callback. |
| 330 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 331 | void GLAPIENTRY |
Brian Paul | ead285a | 2000-02-24 22:04:03 +0000 | [diff] [blame] | 332 | _mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha ) |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 333 | { |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 334 | GLfloat tmp[4]; |
Brian Paul | fbd8f21 | 1999-11-11 01:22:25 +0000 | [diff] [blame] | 335 | GET_CURRENT_CONTEXT(ctx); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 336 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 337 | |
Brian Paul | 7c27632 | 2001-09-14 21:36:43 +0000 | [diff] [blame] | 338 | tmp[0] = CLAMP( red, 0.0F, 1.0F ); |
| 339 | tmp[1] = CLAMP( green, 0.0F, 1.0F ); |
| 340 | tmp[2] = CLAMP( blue, 0.0F, 1.0F ); |
| 341 | tmp[3] = CLAMP( alpha, 0.0F, 1.0F ); |
Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 342 | |
| 343 | if (TEST_EQ_4V(tmp, ctx->Color.BlendColor)) |
| 344 | return; |
| 345 | |
| 346 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
| 347 | COPY_4FV( ctx->Color.BlendColor, tmp ); |
Brian Paul | be3d539 | 2001-03-07 00:21:32 +0000 | [diff] [blame] | 348 | |
| 349 | if (ctx->Driver.BlendColor) |
| 350 | (*ctx->Driver.BlendColor)(ctx, tmp); |
jtg | afb833d | 1999-08-19 00:55:39 +0000 | [diff] [blame] | 351 | } |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 352 | |
| 353 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 354 | /** |
| 355 | * Specify the alpha test function. |
| 356 | * |
| 357 | * \param func alpha comparison function. |
| 358 | * \param ref reference value. |
| 359 | * |
| 360 | * Verifies the parameters and updates gl_colorbuffer_attrib. |
| 361 | * On a change, flushes the vertices and notifies the driver via |
| 362 | * dd_function_table::AlphaFunc callback. |
| 363 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 364 | void GLAPIENTRY |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 365 | _mesa_AlphaFunc( GLenum func, GLclampf ref ) |
| 366 | { |
| 367 | GET_CURRENT_CONTEXT(ctx); |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 368 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 369 | |
| 370 | switch (func) { |
| 371 | case GL_NEVER: |
| 372 | case GL_LESS: |
| 373 | case GL_EQUAL: |
| 374 | case GL_LEQUAL: |
| 375 | case GL_GREATER: |
| 376 | case GL_NOTEQUAL: |
| 377 | case GL_GEQUAL: |
| 378 | case GL_ALWAYS: |
Brian Paul | fc80ad6 | 2002-10-04 19:10:06 +0000 | [diff] [blame] | 379 | ref = CLAMP(ref, 0.0F, 1.0F); |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 380 | |
Brian Paul | fc80ad6 | 2002-10-04 19:10:06 +0000 | [diff] [blame] | 381 | if (ctx->Color.AlphaFunc == func && ctx->Color.AlphaRef == ref) |
| 382 | return; /* no change */ |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 383 | |
| 384 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
| 385 | ctx->Color.AlphaFunc = func; |
Brian Paul | fc80ad6 | 2002-10-04 19:10:06 +0000 | [diff] [blame] | 386 | ctx->Color.AlphaRef = ref; |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 387 | |
| 388 | if (ctx->Driver.AlphaFunc) |
Brian Paul | fc80ad6 | 2002-10-04 19:10:06 +0000 | [diff] [blame] | 389 | ctx->Driver.AlphaFunc(ctx, func, ref); |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 390 | return; |
| 391 | |
| 392 | default: |
| 393 | _mesa_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" ); |
| 394 | return; |
| 395 | } |
| 396 | } |
| 397 | |
| 398 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 399 | /** |
| 400 | * Specify a logic pixel operation for color index rendering. |
| 401 | * |
| 402 | * \param opcode operation. |
| 403 | * |
| 404 | * Verifies that \p opcode is a valid enum and updates |
| 405 | gl_colorbuffer_attrib::LogicOp. |
| 406 | * On a change, flushes the vertices and notifies the driver via the |
| 407 | * dd_function_table::LogicOpcode callback. |
| 408 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 409 | void GLAPIENTRY |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 410 | _mesa_LogicOp( GLenum opcode ) |
| 411 | { |
| 412 | GET_CURRENT_CONTEXT(ctx); |
| 413 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 414 | |
| 415 | switch (opcode) { |
| 416 | case GL_CLEAR: |
| 417 | case GL_SET: |
| 418 | case GL_COPY: |
| 419 | case GL_COPY_INVERTED: |
| 420 | case GL_NOOP: |
| 421 | case GL_INVERT: |
| 422 | case GL_AND: |
| 423 | case GL_NAND: |
| 424 | case GL_OR: |
| 425 | case GL_NOR: |
| 426 | case GL_XOR: |
| 427 | case GL_EQUIV: |
| 428 | case GL_AND_REVERSE: |
| 429 | case GL_AND_INVERTED: |
| 430 | case GL_OR_REVERSE: |
| 431 | case GL_OR_INVERTED: |
| 432 | break; |
| 433 | default: |
| 434 | _mesa_error( ctx, GL_INVALID_ENUM, "glLogicOp" ); |
| 435 | return; |
| 436 | } |
| 437 | |
| 438 | if (ctx->Color.LogicOp == opcode) |
| 439 | return; |
| 440 | |
| 441 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
| 442 | ctx->Color.LogicOp = opcode; |
| 443 | |
| 444 | if (ctx->Driver.LogicOpcode) |
| 445 | ctx->Driver.LogicOpcode( ctx, opcode ); |
| 446 | } |
| 447 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 448 | #if _HAVE_FULL_GL |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 449 | void GLAPIENTRY |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 450 | _mesa_IndexMask( GLuint mask ) |
| 451 | { |
| 452 | GET_CURRENT_CONTEXT(ctx); |
| 453 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 454 | |
| 455 | if (ctx->Color.IndexMask == mask) |
| 456 | return; |
| 457 | |
| 458 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
| 459 | ctx->Color.IndexMask = mask; |
| 460 | |
| 461 | if (ctx->Driver.IndexMask) |
| 462 | ctx->Driver.IndexMask( ctx, mask ); |
| 463 | } |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 464 | #endif |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 465 | |
| 466 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 467 | /** |
| 468 | * Enable or disable writing of frame buffer color components. |
| 469 | * |
| 470 | * \param red whether to mask writing of the red color component. |
| 471 | * \param green whether to mask writing of the green color component. |
| 472 | * \param blue whether to mask writing of the blue color component. |
| 473 | * \param alpha whether to mask writing of the alpha color component. |
| 474 | * |
| 475 | * \sa glColorMask(). |
| 476 | * |
| 477 | * Sets the appropriate value of gl_colorbuffer_attrib::ColorMask. On a |
| 478 | * change, flushes the vertices and notifies the driver via the |
| 479 | * dd_function_table::ColorMask callback. |
| 480 | */ |
Kendall Bennett | c40d1dd | 2003-10-21 22:22:17 +0000 | [diff] [blame] | 481 | void GLAPIENTRY |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 482 | _mesa_ColorMask( GLboolean red, GLboolean green, |
| 483 | GLboolean blue, GLboolean alpha ) |
| 484 | { |
| 485 | GET_CURRENT_CONTEXT(ctx); |
| 486 | GLubyte tmp[4]; |
Brian Paul | fd5511d | 2009-12-29 16:17:14 -0700 | [diff] [blame] | 487 | GLuint i; |
| 488 | GLboolean flushed; |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 489 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 490 | |
| 491 | if (MESA_VERBOSE & VERBOSE_API) |
Brian Paul | 4753d60 | 2002-06-15 02:38:15 +0000 | [diff] [blame] | 492 | _mesa_debug(ctx, "glColorMask %d %d %d %d\n", red, green, blue, alpha); |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 493 | |
| 494 | /* Shouldn't have any information about channel depth in core mesa |
| 495 | * -- should probably store these as the native booleans: |
| 496 | */ |
| 497 | tmp[RCOMP] = red ? 0xff : 0x0; |
| 498 | tmp[GCOMP] = green ? 0xff : 0x0; |
| 499 | tmp[BCOMP] = blue ? 0xff : 0x0; |
| 500 | tmp[ACOMP] = alpha ? 0xff : 0x0; |
| 501 | |
Brian Paul | fd5511d | 2009-12-29 16:17:14 -0700 | [diff] [blame] | 502 | flushed = GL_FALSE; |
| 503 | for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) { |
| 504 | if (!TEST_EQ_4V(tmp, ctx->Color.ColorMask[i])) { |
| 505 | if (!flushed) { |
| 506 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
| 507 | } |
| 508 | flushed = GL_TRUE; |
| 509 | COPY_4UBV(ctx->Color.ColorMask[i], tmp); |
| 510 | } |
| 511 | } |
Brian Paul | 1b25898 | 2001-06-18 17:26:08 +0000 | [diff] [blame] | 512 | |
| 513 | if (ctx->Driver.ColorMask) |
| 514 | ctx->Driver.ColorMask( ctx, red, green, blue, alpha ); |
| 515 | } |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 516 | |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 517 | |
Brian Paul | fd5511d | 2009-12-29 16:17:14 -0700 | [diff] [blame] | 518 | /** |
| 519 | * For GL_EXT_draw_buffers2 and GL3 |
| 520 | */ |
| 521 | void GLAPIENTRY |
| 522 | _mesa_ColorMaskIndexed( GLuint buf, GLboolean red, GLboolean green, |
| 523 | GLboolean blue, GLboolean alpha ) |
| 524 | { |
| 525 | GLubyte tmp[4]; |
| 526 | GET_CURRENT_CONTEXT(ctx); |
| 527 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 528 | |
| 529 | if (MESA_VERBOSE & VERBOSE_API) |
| 530 | _mesa_debug(ctx, "glColorMaskIndexed %u %d %d %d %d\n", |
| 531 | buf, red, green, blue, alpha); |
| 532 | |
| 533 | if (buf >= ctx->Const.MaxDrawBuffers) { |
| 534 | _mesa_error(ctx, GL_INVALID_VALUE, "glColorMaskIndexed(buf=%u)", buf); |
| 535 | return; |
| 536 | } |
| 537 | |
| 538 | /* Shouldn't have any information about channel depth in core mesa |
| 539 | * -- should probably store these as the native booleans: |
| 540 | */ |
| 541 | tmp[RCOMP] = red ? 0xff : 0x0; |
| 542 | tmp[GCOMP] = green ? 0xff : 0x0; |
| 543 | tmp[BCOMP] = blue ? 0xff : 0x0; |
| 544 | tmp[ACOMP] = alpha ? 0xff : 0x0; |
| 545 | |
| 546 | if (TEST_EQ_4V(tmp, ctx->Color.ColorMask[buf])) |
| 547 | return; |
| 548 | |
| 549 | FLUSH_VERTICES(ctx, _NEW_COLOR); |
| 550 | COPY_4UBV(ctx->Color.ColorMask[buf], tmp); |
| 551 | |
| 552 | if (ctx->Driver.ColorMaskIndexed) |
| 553 | ctx->Driver.ColorMaskIndexed(ctx, buf, red, green, blue, alpha); |
| 554 | } |
| 555 | |
| 556 | |
Brian Paul | 0b26e82 | 2006-10-22 17:18:50 +0000 | [diff] [blame] | 557 | extern void GLAPIENTRY |
| 558 | _mesa_ClampColorARB(GLenum target, GLenum clamp) |
| 559 | { |
| 560 | GET_CURRENT_CONTEXT(ctx); |
| 561 | |
| 562 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
| 563 | |
| 564 | if (clamp != GL_TRUE && clamp != GL_FALSE && clamp != GL_FIXED_ONLY_ARB) { |
| 565 | _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(clamp)"); |
| 566 | return; |
| 567 | } |
| 568 | |
| 569 | switch (target) { |
| 570 | case GL_CLAMP_VERTEX_COLOR_ARB: |
| 571 | ctx->Light.ClampVertexColor = clamp; |
| 572 | break; |
| 573 | case GL_CLAMP_FRAGMENT_COLOR_ARB: |
| 574 | ctx->Color.ClampFragmentColor = clamp; |
| 575 | break; |
| 576 | case GL_CLAMP_READ_COLOR_ARB: |
| 577 | ctx->Color.ClampReadColor = clamp; |
| 578 | break; |
| 579 | default: |
| 580 | _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(target)"); |
| 581 | return; |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 588 | /**********************************************************************/ |
| 589 | /** \name Initialization */ |
| 590 | /*@{*/ |
| 591 | |
| 592 | /** |
Brian Paul | 894844a | 2004-03-21 17:05:03 +0000 | [diff] [blame] | 593 | * Initialization of the context's Color attribute group. |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 594 | * |
| 595 | * \param ctx GL context. |
| 596 | * |
| 597 | * Initializes the related fields in the context color attribute group, |
| 598 | * __GLcontextRec::Color. |
| 599 | */ |
| 600 | void _mesa_init_color( GLcontext * ctx ) |
| 601 | { |
| 602 | /* Color buffer group */ |
Brian Paul | a760ccf | 2004-12-03 15:24:34 +0000 | [diff] [blame] | 603 | ctx->Color.IndexMask = ~0u; |
Brian Paul | fd5511d | 2009-12-29 16:17:14 -0700 | [diff] [blame] | 604 | memset(ctx->Color.ColorMask, 0xff, sizeof(ctx->Color.ColorMask)); |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 605 | ctx->Color.ClearIndex = 0; |
| 606 | ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 ); |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 607 | ctx->Color.AlphaEnabled = GL_FALSE; |
| 608 | ctx->Color.AlphaFunc = GL_ALWAYS; |
| 609 | ctx->Color.AlphaRef = 0; |
Brian Paul | 3728673 | 2009-12-29 15:04:03 -0700 | [diff] [blame] | 610 | ctx->Color.BlendEnabled = 0x0; |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 611 | ctx->Color.BlendSrcRGB = GL_ONE; |
| 612 | ctx->Color.BlendDstRGB = GL_ZERO; |
| 613 | ctx->Color.BlendSrcA = GL_ONE; |
| 614 | ctx->Color.BlendDstA = GL_ZERO; |
Ian Romanick | c93105e | 2004-01-27 18:52:40 +0000 | [diff] [blame] | 615 | ctx->Color.BlendEquationRGB = GL_FUNC_ADD; |
| 616 | ctx->Color.BlendEquationA = GL_FUNC_ADD; |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 617 | ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 ); |
| 618 | ctx->Color.IndexLogicOpEnabled = GL_FALSE; |
| 619 | ctx->Color.ColorLogicOpEnabled = GL_FALSE; |
Brian Paul | 57857ca | 2003-11-12 15:27:52 +0000 | [diff] [blame] | 620 | ctx->Color._LogicOpEnabled = GL_FALSE; |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 621 | ctx->Color.LogicOp = GL_COPY; |
| 622 | ctx->Color.DitherFlag = GL_TRUE; |
| 623 | |
| 624 | if (ctx->Visual.doubleBufferMode) { |
Brian Paul | 53f82c5 | 2004-10-02 16:39:09 +0000 | [diff] [blame] | 625 | ctx->Color.DrawBuffer[0] = GL_BACK; |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 626 | } |
| 627 | else { |
Brian Paul | 53f82c5 | 2004-10-02 16:39:09 +0000 | [diff] [blame] | 628 | ctx->Color.DrawBuffer[0] = GL_FRONT; |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 629 | } |
Brian Paul | ba3da61 | 2005-11-12 18:44:29 +0000 | [diff] [blame] | 630 | |
| 631 | ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB; |
| 632 | ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB; |
Keith Whitwell | 6dc8557 | 2003-07-17 13:43:59 +0000 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /*@}*/ |