summaryrefslogtreecommitdiff
path: root/src/mesa/main/blend.c
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2009-12-29 16:17:14 -0700
committerBrian Paul <brianp@vmware.com>2009-12-29 16:17:14 -0700
commitfd5511d27fc44096117c47ab503fb5b47f993061 (patch)
treece5b1a3152d1c7ec495403f43e222c421b6e99d0 /src/mesa/main/blend.c
parent126b35bd3acbf486471879531cd2e6f446b14497 (diff)
mesa: implement per-buffer color masking
This is part of the GL_EXT_draw_buffers2 extension and part of GL 3.0. The ctx->Color.ColorMask field is now a 2-D array. Until drivers are modified to support per-buffer color masking, they can just look at the 0th color mask. The new _mesa_ColorMaskIndexed() function will be called by glColorMaskIndexedEXT() or glColorMaski().
Diffstat (limited to 'src/mesa/main/blend.c')
-rw-r--r--src/mesa/main/blend.c59
1 files changed, 51 insertions, 8 deletions
diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index 5a9d94e12d..b8170dd468 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -484,6 +484,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 +499,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);
}
@@ -555,10 +601,7 @@ void _mesa_init_color( GLcontext * 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;