ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

blend.c
Go to the documentation of this file.
00001 
00006 /*
00007  * Mesa 3-D graphics library
00008  * Version:  6.5.1
00009  *
00010  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
00011  *
00012  * Permission is hereby granted, free of charge, to any person obtaining a
00013  * copy of this software and associated documentation files (the "Software"),
00014  * to deal in the Software without restriction, including without limitation
00015  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
00016  * and/or sell copies of the Software, and to permit persons to whom the
00017  * Software is furnished to do so, subject to the following conditions:
00018  *
00019  * The above copyright notice and this permission notice shall be included
00020  * in all copies or substantial portions of the Software.
00021  *
00022  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00023  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00024  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
00025  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00026  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00027  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00028  */
00029 
00030 
00031 
00032 #include "glheader.h"
00033 #include "blend.h"
00034 #include "context.h"
00035 #include "enums.h"
00036 #include "macros.h"
00037 #include "mtypes.h"
00038 #include "glapi/glapitable.h"
00039 
00040 
00049 void GLAPIENTRY
00050 _mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
00051 {
00052    _mesa_BlendFuncSeparateEXT(sfactor, dfactor, sfactor, dfactor);
00053 }
00054 
00055 
00068 void GLAPIENTRY
00069 _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
00070                             GLenum sfactorA, GLenum dfactorA )
00071 {
00072    GET_CURRENT_CONTEXT(ctx);
00073    ASSERT_OUTSIDE_BEGIN_END(ctx);
00074 
00075    if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
00076       _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n",
00077                   _mesa_lookup_enum_by_nr(sfactorRGB),
00078                   _mesa_lookup_enum_by_nr(dfactorRGB),
00079                   _mesa_lookup_enum_by_nr(sfactorA),
00080                   _mesa_lookup_enum_by_nr(dfactorA));
00081 
00082    switch (sfactorRGB) {
00083       case GL_SRC_COLOR:
00084       case GL_ONE_MINUS_SRC_COLOR:
00085          if (!ctx->Extensions.NV_blend_square) {
00086             _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (sfactorRGB)");
00087             return;
00088          }
00089          /* fall-through */
00090       case GL_ZERO:
00091       case GL_ONE:
00092       case GL_DST_COLOR:
00093       case GL_ONE_MINUS_DST_COLOR:
00094       case GL_SRC_ALPHA:
00095       case GL_ONE_MINUS_SRC_ALPHA:
00096       case GL_DST_ALPHA:
00097       case GL_ONE_MINUS_DST_ALPHA:
00098       case GL_SRC_ALPHA_SATURATE:
00099       case GL_CONSTANT_COLOR:
00100       case GL_ONE_MINUS_CONSTANT_COLOR:
00101       case GL_CONSTANT_ALPHA:
00102       case GL_ONE_MINUS_CONSTANT_ALPHA:
00103          break;
00104       default:
00105          _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (sfactorRGB)");
00106          return;
00107    }
00108 
00109    switch (dfactorRGB) {
00110       case GL_DST_COLOR:
00111       case GL_ONE_MINUS_DST_COLOR:
00112          if (!ctx->Extensions.NV_blend_square) {
00113             _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (dfactorRGB)");
00114             return;
00115          }
00116          /* fall-through */
00117       case GL_ZERO:
00118       case GL_ONE:
00119       case GL_SRC_COLOR:
00120       case GL_ONE_MINUS_SRC_COLOR:
00121       case GL_SRC_ALPHA:
00122       case GL_ONE_MINUS_SRC_ALPHA:
00123       case GL_DST_ALPHA:
00124       case GL_ONE_MINUS_DST_ALPHA:
00125       case GL_CONSTANT_COLOR:
00126       case GL_ONE_MINUS_CONSTANT_COLOR:
00127       case GL_CONSTANT_ALPHA:
00128       case GL_ONE_MINUS_CONSTANT_ALPHA:
00129          break;
00130       default:
00131          _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (dfactorRGB)");
00132          return;
00133    }
00134 
00135    switch (sfactorA) {
00136       case GL_SRC_COLOR:
00137       case GL_ONE_MINUS_SRC_COLOR:
00138          if (!ctx->Extensions.NV_blend_square) {
00139             _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (sfactorA)");
00140             return;
00141          }
00142          /* fall-through */
00143       case GL_ZERO:
00144       case GL_ONE:
00145       case GL_DST_COLOR:
00146       case GL_ONE_MINUS_DST_COLOR:
00147       case GL_SRC_ALPHA:
00148       case GL_ONE_MINUS_SRC_ALPHA:
00149       case GL_DST_ALPHA:
00150       case GL_ONE_MINUS_DST_ALPHA:
00151       case GL_SRC_ALPHA_SATURATE:
00152       case GL_CONSTANT_COLOR:
00153       case GL_ONE_MINUS_CONSTANT_COLOR:
00154       case GL_CONSTANT_ALPHA:
00155       case GL_ONE_MINUS_CONSTANT_ALPHA:
00156          break;
00157       default:
00158          _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (sfactorA)");
00159          return;
00160    }
00161 
00162    switch (dfactorA) {
00163       case GL_DST_COLOR:
00164       case GL_ONE_MINUS_DST_COLOR:
00165          if (!ctx->Extensions.NV_blend_square) {
00166             _mesa_error(ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (dfactorA)");
00167             return;
00168          }
00169          /* fall-through */
00170       case GL_ZERO:
00171       case GL_ONE:
00172       case GL_SRC_COLOR:
00173       case GL_ONE_MINUS_SRC_COLOR:
00174       case GL_SRC_ALPHA:
00175       case GL_ONE_MINUS_SRC_ALPHA:
00176       case GL_DST_ALPHA:
00177       case GL_ONE_MINUS_DST_ALPHA:
00178       case GL_CONSTANT_COLOR:
00179       case GL_ONE_MINUS_CONSTANT_COLOR:
00180       case GL_CONSTANT_ALPHA:
00181       case GL_ONE_MINUS_CONSTANT_ALPHA:
00182          break;
00183       default:
00184          _mesa_error( ctx, GL_INVALID_ENUM, "glBlendFunc or glBlendFuncSeparate (dfactorA)" );
00185          return;
00186    }
00187 
00188    if (ctx->Color.BlendSrcRGB == sfactorRGB &&
00189        ctx->Color.BlendDstRGB == dfactorRGB &&
00190        ctx->Color.BlendSrcA == sfactorA &&
00191        ctx->Color.BlendDstA == dfactorA)
00192       return;
00193 
00194    FLUSH_VERTICES(ctx, _NEW_COLOR);
00195 
00196    ctx->Color.BlendSrcRGB = sfactorRGB;
00197    ctx->Color.BlendDstRGB = dfactorRGB;
00198    ctx->Color.BlendSrcA = sfactorA;
00199    ctx->Color.BlendDstA = dfactorA;
00200 
00201    if (ctx->Driver.BlendFuncSeparate) {
00202       (*ctx->Driver.BlendFuncSeparate)( ctx, sfactorRGB, dfactorRGB,
00203                     sfactorA, dfactorA );
00204    }
00205 }
00206 
00207 
00208 #if _HAVE_FULL_GL
00209 
00210 static GLboolean
00211 _mesa_validate_blend_equation( GLcontext *ctx,
00212                    GLenum mode, GLboolean is_separate )
00213 {
00214    switch (mode) {
00215       case GL_FUNC_ADD:
00216          break;
00217       case GL_MIN:
00218       case GL_MAX:
00219          if (!ctx->Extensions.EXT_blend_minmax &&
00220              !ctx->Extensions.ARB_imaging) {
00221             return GL_FALSE;
00222          }
00223          break;
00224       /* glBlendEquationSeparate cannot take GL_LOGIC_OP as a parameter.
00225        */
00226       case GL_LOGIC_OP:
00227          if (!ctx->Extensions.EXT_blend_logic_op || is_separate) {
00228             return GL_FALSE;
00229          }
00230          break;
00231       case GL_FUNC_SUBTRACT:
00232       case GL_FUNC_REVERSE_SUBTRACT:
00233          if (!ctx->Extensions.EXT_blend_subtract &&
00234              !ctx->Extensions.ARB_imaging) {
00235             return GL_FALSE;
00236          }
00237          break;
00238       default:
00239          return GL_FALSE;
00240    }
00241 
00242    return GL_TRUE;
00243 }
00244 
00245 
00246 /* This is really an extension function! */
00247 void GLAPIENTRY
00248 _mesa_BlendEquation( GLenum mode )
00249 {
00250    GET_CURRENT_CONTEXT(ctx);
00251    ASSERT_OUTSIDE_BEGIN_END(ctx);
00252 
00253    if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
00254       _mesa_debug(ctx, "glBlendEquation %s\n",
00255                   _mesa_lookup_enum_by_nr(mode));
00256 
00257    if ( ! _mesa_validate_blend_equation( ctx, mode, GL_FALSE ) ) {
00258       _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquation");
00259       return;
00260    }
00261 
00262    if ( (ctx->Color.BlendEquationRGB == mode) &&
00263     (ctx->Color.BlendEquationA == mode) )
00264       return;
00265 
00266    FLUSH_VERTICES(ctx, _NEW_COLOR);
00267    ctx->Color.BlendEquationRGB = mode;
00268    ctx->Color.BlendEquationA = mode;
00269 
00270    if (ctx->Driver.BlendEquationSeparate)
00271       (*ctx->Driver.BlendEquationSeparate)( ctx, mode, mode );
00272 }
00273 
00274 
00275 void GLAPIENTRY
00276 _mesa_BlendEquationSeparateEXT( GLenum modeRGB, GLenum modeA )
00277 {
00278    GET_CURRENT_CONTEXT(ctx);
00279    ASSERT_OUTSIDE_BEGIN_END(ctx);
00280 
00281    if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
00282       _mesa_debug(ctx, "glBlendEquationSeparateEXT %s %s\n",
00283                   _mesa_lookup_enum_by_nr(modeRGB),
00284                   _mesa_lookup_enum_by_nr(modeA));
00285 
00286    if ( (modeRGB != modeA) && !ctx->Extensions.EXT_blend_equation_separate ) {
00287       _mesa_error(ctx, GL_INVALID_OPERATION,
00288           "glBlendEquationSeparateEXT not supported by driver");
00289       return;
00290    }
00291 
00292    if ( ! _mesa_validate_blend_equation( ctx, modeRGB, GL_TRUE ) ) {
00293       _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeRGB)");
00294       return;
00295    }
00296 
00297    if ( ! _mesa_validate_blend_equation( ctx, modeA, GL_TRUE ) ) {
00298       _mesa_error(ctx, GL_INVALID_ENUM, "glBlendEquationSeparateEXT(modeA)");
00299       return;
00300    }
00301 
00302 
00303    if ( (ctx->Color.BlendEquationRGB == modeRGB) &&
00304     (ctx->Color.BlendEquationA == modeA) )
00305       return;
00306 
00307    FLUSH_VERTICES(ctx, _NEW_COLOR);
00308    ctx->Color.BlendEquationRGB = modeRGB;
00309    ctx->Color.BlendEquationA = modeA;
00310 
00311    if (ctx->Driver.BlendEquationSeparate)
00312       (*ctx->Driver.BlendEquationSeparate)( ctx, modeRGB, modeA );
00313 }
00314 #endif
00315 
00316 
00331 void GLAPIENTRY
00332 _mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
00333 {
00334    GLfloat tmp[4];
00335    GET_CURRENT_CONTEXT(ctx);
00336    ASSERT_OUTSIDE_BEGIN_END(ctx);
00337 
00338    tmp[0] = CLAMP( red,   0.0F, 1.0F );
00339    tmp[1] = CLAMP( green, 0.0F, 1.0F );
00340    tmp[2] = CLAMP( blue,  0.0F, 1.0F );
00341    tmp[3] = CLAMP( alpha, 0.0F, 1.0F );
00342 
00343    if (TEST_EQ_4V(tmp, ctx->Color.BlendColor))
00344       return;
00345 
00346    FLUSH_VERTICES(ctx, _NEW_COLOR);
00347    COPY_4FV( ctx->Color.BlendColor, tmp );
00348 
00349    if (ctx->Driver.BlendColor)
00350       (*ctx->Driver.BlendColor)(ctx, tmp);
00351 }
00352 
00353 
00364 void GLAPIENTRY
00365 _mesa_AlphaFunc( GLenum func, GLclampf ref )
00366 {
00367    GET_CURRENT_CONTEXT(ctx);
00368    ASSERT_OUTSIDE_BEGIN_END(ctx);
00369 
00370    switch (func) {
00371    case GL_NEVER:
00372    case GL_LESS:
00373    case GL_EQUAL:
00374    case GL_LEQUAL:
00375    case GL_GREATER:
00376    case GL_NOTEQUAL:
00377    case GL_GEQUAL:
00378    case GL_ALWAYS:
00379       ref = CLAMP(ref, 0.0F, 1.0F);
00380 
00381       if (ctx->Color.AlphaFunc == func && ctx->Color.AlphaRef == ref)
00382          return; /* no change */
00383 
00384       FLUSH_VERTICES(ctx, _NEW_COLOR);
00385       ctx->Color.AlphaFunc = func;
00386       ctx->Color.AlphaRef = ref;
00387 
00388       if (ctx->Driver.AlphaFunc)
00389          ctx->Driver.AlphaFunc(ctx, func, ref);
00390       return;
00391 
00392    default:
00393       _mesa_error( ctx, GL_INVALID_ENUM, "glAlphaFunc(func)" );
00394       return;
00395    }
00396 }
00397 
00398 
00409 void GLAPIENTRY
00410 _mesa_LogicOp( GLenum opcode )
00411 {
00412    GET_CURRENT_CONTEXT(ctx);
00413    ASSERT_OUTSIDE_BEGIN_END(ctx);
00414 
00415    switch (opcode) {
00416       case GL_CLEAR:
00417       case GL_SET:
00418       case GL_COPY:
00419       case GL_COPY_INVERTED:
00420       case GL_NOOP:
00421       case GL_INVERT:
00422       case GL_AND:
00423       case GL_NAND:
00424       case GL_OR:
00425       case GL_NOR:
00426       case GL_XOR:
00427       case GL_EQUIV:
00428       case GL_AND_REVERSE:
00429       case GL_AND_INVERTED:
00430       case GL_OR_REVERSE:
00431       case GL_OR_INVERTED:
00432      break;
00433       default:
00434          _mesa_error( ctx, GL_INVALID_ENUM, "glLogicOp" );
00435      return;
00436    }
00437 
00438    if (ctx->Color.LogicOp == opcode)
00439       return;
00440 
00441    FLUSH_VERTICES(ctx, _NEW_COLOR);
00442    ctx->Color.LogicOp = opcode;
00443 
00444    if (ctx->Driver.LogicOpcode)
00445       ctx->Driver.LogicOpcode( ctx, opcode );
00446 }
00447 
00448 #if _HAVE_FULL_GL
00449 void GLAPIENTRY
00450 _mesa_IndexMask( GLuint mask )
00451 {
00452    GET_CURRENT_CONTEXT(ctx);
00453    ASSERT_OUTSIDE_BEGIN_END(ctx);
00454 
00455    if (ctx->Color.IndexMask == mask)
00456       return;
00457 
00458    FLUSH_VERTICES(ctx, _NEW_COLOR);
00459    ctx->Color.IndexMask = mask;
00460 
00461    if (ctx->Driver.IndexMask)
00462       ctx->Driver.IndexMask( ctx, mask );
00463 }
00464 #endif
00465 
00466 
00481 void GLAPIENTRY
00482 _mesa_ColorMask( GLboolean red, GLboolean green,
00483                  GLboolean blue, GLboolean alpha )
00484 {
00485    GET_CURRENT_CONTEXT(ctx);
00486    GLubyte tmp[4];
00487    ASSERT_OUTSIDE_BEGIN_END(ctx);
00488 
00489    if (MESA_VERBOSE & VERBOSE_API)
00490       _mesa_debug(ctx, "glColorMask %d %d %d %d\n", red, green, blue, alpha);
00491 
00492    /* Shouldn't have any information about channel depth in core mesa
00493     * -- should probably store these as the native booleans:
00494     */
00495    tmp[RCOMP] = red    ? 0xff : 0x0;
00496    tmp[GCOMP] = green  ? 0xff : 0x0;
00497    tmp[BCOMP] = blue   ? 0xff : 0x0;
00498    tmp[ACOMP] = alpha  ? 0xff : 0x0;
00499 
00500    if (TEST_EQ_4UBV(tmp, ctx->Color.ColorMask))
00501       return;
00502 
00503    FLUSH_VERTICES(ctx, _NEW_COLOR);
00504    COPY_4UBV(ctx->Color.ColorMask, tmp);
00505 
00506    if (ctx->Driver.ColorMask)
00507       ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
00508 }
00509 
00510 
00511 extern void GLAPIENTRY
00512 _mesa_ClampColorARB(GLenum target, GLenum clamp)
00513 {
00514    GET_CURRENT_CONTEXT(ctx);
00515 
00516    ASSERT_OUTSIDE_BEGIN_END(ctx);
00517 
00518    if (clamp != GL_TRUE && clamp != GL_FALSE && clamp != GL_FIXED_ONLY_ARB) {
00519       _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(clamp)");
00520       return;
00521    }
00522 
00523    switch (target) {
00524    case GL_CLAMP_VERTEX_COLOR_ARB:
00525       ctx->Light.ClampVertexColor = clamp;
00526       break;
00527    case GL_CLAMP_FRAGMENT_COLOR_ARB:
00528       ctx->Color.ClampFragmentColor = clamp;
00529       break;
00530    case GL_CLAMP_READ_COLOR_ARB:
00531       ctx->Color.ClampReadColor = clamp;
00532       break;
00533    default:
00534       _mesa_error(ctx, GL_INVALID_ENUM, "glClampColorARB(target)");
00535       return;
00536    }
00537 }
00538 
00539 
00540 
00541 
00542 /**********************************************************************/
00545 
00554 void _mesa_init_color( GLcontext * ctx )
00555 {
00556    /* Color buffer group */
00557    ctx->Color.IndexMask = ~0u;
00558    ctx->Color.ColorMask[0] = 0xff;
00559    ctx->Color.ColorMask[1] = 0xff;
00560    ctx->Color.ColorMask[2] = 0xff;
00561    ctx->Color.ColorMask[3] = 0xff;
00562    ctx->Color.ClearIndex = 0;
00563    ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
00564    ctx->Color.AlphaEnabled = GL_FALSE;
00565    ctx->Color.AlphaFunc = GL_ALWAYS;
00566    ctx->Color.AlphaRef = 0;
00567    ctx->Color.BlendEnabled = GL_FALSE;
00568    ctx->Color.BlendSrcRGB = GL_ONE;
00569    ctx->Color.BlendDstRGB = GL_ZERO;
00570    ctx->Color.BlendSrcA = GL_ONE;
00571    ctx->Color.BlendDstA = GL_ZERO;
00572    ctx->Color.BlendEquationRGB = GL_FUNC_ADD;
00573    ctx->Color.BlendEquationA = GL_FUNC_ADD;
00574    ASSIGN_4V( ctx->Color.BlendColor, 0.0, 0.0, 0.0, 0.0 );
00575    ctx->Color.IndexLogicOpEnabled = GL_FALSE;
00576    ctx->Color.ColorLogicOpEnabled = GL_FALSE;
00577    ctx->Color._LogicOpEnabled = GL_FALSE;
00578    ctx->Color.LogicOp = GL_COPY;
00579    ctx->Color.DitherFlag = GL_TRUE;
00580 
00581    if (ctx->Visual.doubleBufferMode) {
00582       ctx->Color.DrawBuffer[0] = GL_BACK;
00583    }
00584    else {
00585       ctx->Color.DrawBuffer[0] = GL_FRONT;
00586    }
00587 
00588    ctx->Color.ClampFragmentColor = GL_FIXED_ONLY_ARB;
00589    ctx->Color.ClampReadColor = GL_FIXED_ONLY_ARB;
00590 }
00591 

Generated on Sat May 26 2012 04:18:57 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.