fix GL_BACK color material bug
[mesa.git] / src / mesa / main / blend.c
index 0bcefd097488e49861d92da3637480b7e3d9424d..ddfe6447dee06292614f9e8758fd981365611af6 100644 (file)
@@ -1,4 +1,4 @@
-/* $Id: blend.c,v 1.12 2000/02/21 14:50:31 brianp Exp $ */
+/* $Id: blend.c,v 1.15 2000/05/30 02:28:03 brianp Exp $ */
 
 /*
  * Mesa 3-D graphics library
@@ -53,6 +53,13 @@ _mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
              gl_lookup_enum_by_nr(dfactor));
 
    switch (sfactor) {
+      case GL_SRC_COLOR:
+      case GL_ONE_MINUS_SRC_COLOR:
+         if (!ctx->Extensions.HaveBlendSquare) {
+            gl_error( ctx, GL_INVALID_ENUM, "glBlendFunc(sfactor)" );
+            return;
+         }
+         /* fall-through */
       case GL_ZERO:
       case GL_ONE:
       case GL_DST_COLOR:
@@ -74,6 +81,13 @@ _mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
    }
 
    switch (dfactor) {
+      case GL_DST_COLOR:
+      case GL_ONE_MINUS_DST_COLOR:
+         if (!ctx->Extensions.HaveBlendSquare) {
+            gl_error( ctx, GL_INVALID_ENUM, "glBlendFunc(dfactor)" );
+            return;
+         }
+         /* fall-through */
       case GL_ZERO:
       case GL_ONE:
       case GL_SRC_COLOR:
@@ -102,10 +116,10 @@ _mesa_BlendFunc( GLenum sfactor, GLenum dfactor )
 }
 
 
-/* GL_INGR_blend_func_separate */
+/* GL_EXT_blend_func_separate */
 void
-_mesa_BlendFuncSeparateINGR( GLenum sfactorRGB, GLenum dfactorRGB,
-                             GLenum sfactorA, GLenum dfactorA )
+_mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
+                            GLenum sfactorA, GLenum dfactorA )
 {
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBlendFuncSeparate");
@@ -118,6 +132,13 @@ _mesa_BlendFuncSeparateINGR( GLenum sfactorRGB, GLenum dfactorRGB,
              gl_lookup_enum_by_nr(dfactorA));
 
    switch (sfactorRGB) {
+      case GL_SRC_COLOR:
+      case GL_ONE_MINUS_SRC_COLOR:
+         if (!ctx->Extensions.HaveBlendSquare) {
+            gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorRGB)");
+            return;
+         }
+         /* fall-through */
       case GL_ZERO:
       case GL_ONE:
       case GL_DST_COLOR:
@@ -134,11 +155,18 @@ _mesa_BlendFuncSeparateINGR( GLenum sfactorRGB, GLenum dfactorRGB,
          ctx->Color.BlendSrcRGB = sfactorRGB;
          break;
       default:
-         gl_error( ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorRGB)" );
+         gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorRGB)");
          return;
    }
 
    switch (dfactorRGB) {
+      case GL_DST_COLOR:
+      case GL_ONE_MINUS_DST_COLOR:
+         if (!ctx->Extensions.HaveBlendSquare) {
+            gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(dfactorRGB)");
+            return;
+         }
+         /* fall-through */
       case GL_ZERO:
       case GL_ONE:
       case GL_SRC_COLOR:
@@ -154,11 +182,18 @@ _mesa_BlendFuncSeparateINGR( GLenum sfactorRGB, GLenum dfactorRGB,
          ctx->Color.BlendDstRGB = dfactorRGB;
          break;
       default:
-         gl_error( ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(dfactorRGB)" );
+         gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(dfactorRGB)");
          return;
    }
 
    switch (sfactorA) {
+      case GL_SRC_COLOR:
+      case GL_ONE_MINUS_SRC_COLOR:
+         if (!ctx->Extensions.HaveBlendSquare) {
+            gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorA)");
+            return;
+         }
+         /* fall-through */
       case GL_ZERO:
       case GL_ONE:
       case GL_DST_COLOR:
@@ -175,11 +210,18 @@ _mesa_BlendFuncSeparateINGR( GLenum sfactorRGB, GLenum dfactorRGB,
          ctx->Color.BlendSrcA = sfactorA;
          break;
       default:
-         gl_error( ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorA)" );
+         gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(sfactorA)");
          return;
    }
 
    switch (dfactorA) {
+      case GL_DST_COLOR:
+      case GL_ONE_MINUS_DST_COLOR:
+         if (!ctx->Extensions.HaveBlendSquare) {
+            gl_error(ctx, GL_INVALID_ENUM, "glBlendFuncSeparate(dfactorA)");
+            return;
+         }
+         /* fall-through */
       case GL_ZERO:
       case GL_ONE:
       case GL_SRC_COLOR:
@@ -212,7 +254,7 @@ _mesa_BlendFuncSeparateINGR( GLenum sfactorRGB, GLenum dfactorRGB,
 
 /* This is really an extension function! */
 void
-_mesa_BlendEquationEXT( GLenum mode )
+_mesa_BlendEquation( GLenum mode )
 {
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBlendEquation");
@@ -221,7 +263,6 @@ _mesa_BlendEquationEXT( GLenum mode )
       fprintf(stderr, "glBlendEquation %s\n",
              gl_lookup_enum_by_nr(mode));
 
-
    switch (mode) {
       case GL_MIN_EXT:
       case GL_MAX_EXT:
@@ -256,7 +297,7 @@ _mesa_BlendEquationEXT( GLenum mode )
 
 
 void
-_mesa_BlendColorEXT( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
+_mesa_BlendColor( GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha )
 {
    GET_CURRENT_CONTEXT(ctx);
    ctx->Color.BlendColor[0] = CLAMP( red,   0.0F, 1.0F );
@@ -510,6 +551,16 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
             case GL_ONE_MINUS_CONSTANT_ALPHA:
                sR = sG = sB = 1.0F - ctx->Color.BlendColor[3];
                break;
+            case GL_SRC_COLOR: /* GL_NV_blend_square */
+               sR = (GLfloat) Rs * rscale;
+               sG = (GLfloat) Gs * gscale;
+               sB = (GLfloat) Bs * bscale;
+               break;
+            case GL_ONE_MINUS_SRC_COLOR: /* GL_NV_blend_square */
+               sR = 1.0F - (GLfloat) Rs * rscale;
+               sG = 1.0F - (GLfloat) Gs * gscale;
+               sB = 1.0F - (GLfloat) Bs * bscale;
+               break;
             default:
                /* this should never happen */
                gl_problem(ctx, "Bad blend source RGB factor in do_blend");
@@ -557,6 +608,12 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
             case GL_ONE_MINUS_CONSTANT_ALPHA:
                sA = 1.0F - ctx->Color.BlendColor[3];
                break;
+            case GL_SRC_COLOR: /* GL_NV_blend_square */
+               sA = (GLfloat) As * ascale;
+               break;
+            case GL_ONE_MINUS_SRC_COLOR: /* GL_NV_blend_square */
+               sA = 1.0F - (GLfloat) As * ascale;
+               break;
             default:
                /* this should never happen */
                sA = 0.0F;
@@ -609,6 +666,16 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
             case GL_ONE_MINUS_CONSTANT_ALPHA:
                dR = dG = dB = 1.0F - ctx->Color.BlendColor[3] * ascale;
                break;
+            case GL_DST_COLOR: /* GL_NV_blend_square */
+               dR = (GLfloat) Rd * rscale;
+               dG = (GLfloat) Gd * gscale;
+               dB = (GLfloat) Bd * bscale;
+               break;
+            case GL_ONE_MINUS_DST_COLOR: /* GL_NV_blend_square */
+               dR = 1.0F - (GLfloat) Rd * rscale;
+               dG = 1.0F - (GLfloat) Gd * gscale;
+               dB = 1.0F - (GLfloat) Bd * bscale;
+               break;
             default:
                /* this should never happen */
                dR = dG = dB = 0.0F;
@@ -653,6 +720,12 @@ blend_general( GLcontext *ctx, GLuint n, const GLubyte mask[],
             case GL_ONE_MINUS_CONSTANT_ALPHA:
                dA = 1.0F - ctx->Color.BlendColor[3] * ascale;
                break;
+            case GL_DST_COLOR: /* GL_NV_blend_square */
+               dA = (GLfloat) Ad * ascale;
+               break;
+            case GL_ONE_MINUS_DST_COLOR: /* GL_NV_blend_square */
+               dA = 1.0F - (GLfloat) Ad * ascale;
+               break;
             default:
                /* this should never happen */
                dA = 0.0F;
@@ -826,7 +899,7 @@ _mesa_blend_pixels( GLcontext *ctx,
    /* Read pixels from current color buffer */
    (*ctx->Driver.ReadRGBAPixels)( ctx, n, x, y, dest, mask );
    if (ctx->RasterMask & ALPHABUF_BIT) {
-      gl_read_alpha_pixels( ctx, n, x, y, dest, mask );
+      _mesa_read_alpha_pixels( ctx, n, x, y, dest, mask );
    }
 
    if (!ctx->Color.BlendFunc)