mesa: support for GL_ARB_instanced_arrays
[mesa.git] / src / mesa / main / blend.c
index 39cf6153e2850c3b6fc691f984317f26e7ff24af..ec778b7244dd8968f92aaf11248a14502db1a2e1 100644 (file)
@@ -35,7 +35,6 @@
 #include "enums.h"
 #include "macros.h"
 #include "mtypes.h"
-#include "glapi/glapitable.h"
 
 
 /**
@@ -72,7 +71,7 @@ _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+   if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glBlendFuncSeparate %s %s %s %s\n",
                   _mesa_lookup_enum_by_nr(sfactorRGB),
                   _mesa_lookup_enum_by_nr(dfactorRGB),
@@ -208,7 +207,7 @@ _mesa_BlendFuncSeparateEXT( GLenum sfactorRGB, GLenum dfactorRGB,
 #if _HAVE_FULL_GL
 
 static GLboolean
-_mesa_validate_blend_equation( GLcontext *ctx,
+_mesa_validate_blend_equation( struct gl_context *ctx,
                               GLenum mode, GLboolean is_separate )
 {
    switch (mode) {
@@ -216,8 +215,7 @@ _mesa_validate_blend_equation( GLcontext *ctx,
          break;
       case GL_MIN:
       case GL_MAX:
-         if (!ctx->Extensions.EXT_blend_minmax &&
-             !ctx->Extensions.ARB_imaging) {
+         if (!ctx->Extensions.EXT_blend_minmax) {
             return GL_FALSE;
          }
          break;
@@ -230,8 +228,7 @@ _mesa_validate_blend_equation( GLcontext *ctx,
          break;
       case GL_FUNC_SUBTRACT:
       case GL_FUNC_REVERSE_SUBTRACT:
-         if (!ctx->Extensions.EXT_blend_subtract &&
-             !ctx->Extensions.ARB_imaging) {
+         if (!ctx->Extensions.EXT_blend_subtract) {
             return GL_FALSE;
          }
          break;
@@ -250,7 +247,7 @@ _mesa_BlendEquation( GLenum mode )
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+   if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glBlendEquation %s\n",
                   _mesa_lookup_enum_by_nr(mode));
 
@@ -278,7 +275,7 @@ _mesa_BlendEquationSeparateEXT( GLenum modeRGB, GLenum modeA )
    GET_CURRENT_CONTEXT(ctx);
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
-   if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
+   if (MESA_VERBOSE & VERBOSE_API)
       _mesa_debug(ctx, "glBlendEquationSeparateEXT %s %s\n",
                   _mesa_lookup_enum_by_nr(modeRGB),
                   _mesa_lookup_enum_by_nr(modeA));
@@ -457,9 +454,6 @@ _mesa_IndexMask( GLuint mask )
 
    FLUSH_VERTICES(ctx, _NEW_COLOR);
    ctx->Color.IndexMask = mask;
-
-   if (ctx->Driver.IndexMask)
-      ctx->Driver.IndexMask( ctx, mask );
 }
 #endif
 
@@ -484,6 +478,8 @@ _mesa_ColorMask( GLboolean red, GLboolean green,
 {
    GET_CURRENT_CONTEXT(ctx);
    GLubyte tmp[4];
+   GLuint i;
+   GLboolean flushed;
    ASSERT_OUTSIDE_BEGIN_END(ctx);
 
    if (MESA_VERBOSE & VERBOSE_API)
@@ -497,14 +493,58 @@ _mesa_ColorMask( GLboolean red, GLboolean green,
    tmp[BCOMP] = blue   ? 0xff : 0x0;
    tmp[ACOMP] = alpha  ? 0xff : 0x0;
 
-   if (TEST_EQ_4UBV(tmp, ctx->Color.ColorMask))
+   flushed = GL_FALSE;
+   for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
+      if (!TEST_EQ_4V(tmp, ctx->Color.ColorMask[i])) {
+         if (!flushed) {
+            FLUSH_VERTICES(ctx, _NEW_COLOR);
+         }
+         flushed = GL_TRUE;
+         COPY_4UBV(ctx->Color.ColorMask[i], tmp);
+      }
+   }
+
+   if (ctx->Driver.ColorMask)
+      ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
+}
+
+
+/**
+ * For GL_EXT_draw_buffers2 and GL3
+ */
+void GLAPIENTRY
+_mesa_ColorMaskIndexed( GLuint buf, GLboolean red, GLboolean green,
+                        GLboolean blue, GLboolean alpha )
+{
+   GLubyte tmp[4];
+   GET_CURRENT_CONTEXT(ctx);
+   ASSERT_OUTSIDE_BEGIN_END(ctx);
+
+   if (MESA_VERBOSE & VERBOSE_API)
+      _mesa_debug(ctx, "glColorMaskIndexed %u %d %d %d %d\n",
+                  buf, red, green, blue, alpha);
+
+   if (buf >= ctx->Const.MaxDrawBuffers) {
+      _mesa_error(ctx, GL_INVALID_VALUE, "glColorMaskIndexed(buf=%u)", buf);
+      return;
+   }
+
+   /* Shouldn't have any information about channel depth in core mesa
+    * -- should probably store these as the native booleans:
+    */
+   tmp[RCOMP] = red    ? 0xff : 0x0;
+   tmp[GCOMP] = green  ? 0xff : 0x0;
+   tmp[BCOMP] = blue   ? 0xff : 0x0;
+   tmp[ACOMP] = alpha  ? 0xff : 0x0;
+
+   if (TEST_EQ_4V(tmp, ctx->Color.ColorMask[buf]))
       return;
 
    FLUSH_VERTICES(ctx, _NEW_COLOR);
-   COPY_4UBV(ctx->Color.ColorMask, tmp);
+   COPY_4UBV(ctx->Color.ColorMask[buf], tmp);
 
-   if (ctx->Driver.ColorMask)
-      ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
+   if (ctx->Driver.ColorMaskIndexed)
+      ctx->Driver.ColorMaskIndexed(ctx, buf, red, green, blue, alpha);
 }
 
 
@@ -549,22 +589,19 @@ _mesa_ClampColorARB(GLenum target, GLenum clamp)
  * \param ctx GL context.
  *
  * Initializes the related fields in the context color attribute group,
- * __GLcontextRec::Color.
+ * __struct gl_contextRec::Color.
  */
-void _mesa_init_color( GLcontext * ctx )
+void _mesa_init_color( struct gl_context * ctx )
 {
    /* Color buffer group */
    ctx->Color.IndexMask = ~0u;
-   ctx->Color.ColorMask[0] = 0xff;
-   ctx->Color.ColorMask[1] = 0xff;
-   ctx->Color.ColorMask[2] = 0xff;
-   ctx->Color.ColorMask[3] = 0xff;
+   memset(ctx->Color.ColorMask, 0xff, sizeof(ctx->Color.ColorMask));
    ctx->Color.ClearIndex = 0;
    ASSIGN_4V( ctx->Color.ClearColor, 0, 0, 0, 0 );
    ctx->Color.AlphaEnabled = GL_FALSE;
    ctx->Color.AlphaFunc = GL_ALWAYS;
    ctx->Color.AlphaRef = 0;
-   ctx->Color.BlendEnabled = GL_FALSE;
+   ctx->Color.BlendEnabled = 0x0;
    ctx->Color.BlendSrcRGB = GL_ONE;
    ctx->Color.BlendDstRGB = GL_ZERO;
    ctx->Color.BlendSrcA = GL_ONE;