summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/accum.c16
-rw-r--r--src/mesa/main/attrib.c16
-rw-r--r--src/mesa/main/blend.c53
-rw-r--r--src/mesa/main/blend.h10
-rw-r--r--src/mesa/main/clear.c2
-rw-r--r--src/mesa/main/get.c16
-rw-r--r--src/mesa/main/mtypes.h8
7 files changed, 62 insertions, 59 deletions
diff --git a/src/mesa/main/accum.c b/src/mesa/main/accum.c
index 2b15b6ee0d3..5fbee8fbdbd 100644
--- a/src/mesa/main/accum.c
+++ b/src/mesa/main/accum.c
@@ -298,10 +298,10 @@ accum_return(struct gl_context *ctx, GLfloat value,
/* Loop over destination buffers */
for (buffer = 0; buffer < fb->_NumColorDrawBuffers; buffer++) {
struct gl_renderbuffer *colorRb = fb->_ColorDrawBuffers[buffer];
- const GLboolean masking = (!ctx->Color.ColorMask[buffer][RCOMP] ||
- !ctx->Color.ColorMask[buffer][GCOMP] ||
- !ctx->Color.ColorMask[buffer][BCOMP] ||
- !ctx->Color.ColorMask[buffer][ACOMP]);
+ const GLboolean masking = (!GET_COLORMASK_BIT(ctx->Color.ColorMask, buffer, 0) ||
+ !GET_COLORMASK_BIT(ctx->Color.ColorMask, buffer, 1) ||
+ !GET_COLORMASK_BIT(ctx->Color.ColorMask, buffer, 2) ||
+ !GET_COLORMASK_BIT(ctx->Color.ColorMask, buffer, 3));
GLbitfield mappingFlags = GL_MAP_WRITE_BIT;
if (masking)
@@ -340,19 +340,19 @@ accum_return(struct gl_context *ctx, GLfloat value,
_mesa_unpack_rgba_row(colorRb->Format, width, colorMap, dest);
/* use the dest colors where mask[channel] = 0 */
- if (ctx->Color.ColorMask[buffer][RCOMP] == 0) {
+ if (!GET_COLORMASK_BIT(ctx->Color.ColorMask, buffer, 0)) {
for (i = 0; i < width; i++)
rgba[i][RCOMP] = dest[i][RCOMP];
}
- if (ctx->Color.ColorMask[buffer][GCOMP] == 0) {
+ if (!GET_COLORMASK_BIT(ctx->Color.ColorMask, buffer, 1)) {
for (i = 0; i < width; i++)
rgba[i][GCOMP] = dest[i][GCOMP];
}
- if (ctx->Color.ColorMask[buffer][BCOMP] == 0) {
+ if (!GET_COLORMASK_BIT(ctx->Color.ColorMask, buffer, 2)) {
for (i = 0; i < width; i++)
rgba[i][BCOMP] = dest[i][BCOMP];
}
- if (ctx->Color.ColorMask[buffer][ACOMP] == 0) {
+ if (!GET_COLORMASK_BIT(ctx->Color.ColorMask, buffer, 3)) {
for (i = 0; i < width; i++)
rgba[i][ACOMP] = dest[i][ACOMP];
}
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 0b4b63f712f..a9e4a11d7d7 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -967,19 +967,19 @@ _mesa_PopAttrib(void)
color->ClearColor.f[3]);
_mesa_IndexMask(color->IndexMask);
if (!ctx->Extensions.EXT_draw_buffers2) {
- _mesa_ColorMask((GLboolean) (color->ColorMask[0][0] != 0),
- (GLboolean) (color->ColorMask[0][1] != 0),
- (GLboolean) (color->ColorMask[0][2] != 0),
- (GLboolean) (color->ColorMask[0][3] != 0));
+ _mesa_ColorMask(GET_COLORMASK_BIT(color->ColorMask, 0, 0),
+ GET_COLORMASK_BIT(color->ColorMask, 0, 1),
+ GET_COLORMASK_BIT(color->ColorMask, 0, 2),
+ GET_COLORMASK_BIT(color->ColorMask, 0, 3));
}
else {
GLuint i;
for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
_mesa_ColorMaski(i,
- (GLboolean) (color->ColorMask[i][0] != 0),
- (GLboolean) (color->ColorMask[i][1] != 0),
- (GLboolean) (color->ColorMask[i][2] != 0),
- (GLboolean) (color->ColorMask[i][3] != 0));
+ GET_COLORMASK_BIT(color->ColorMask, i, 0),
+ GET_COLORMASK_BIT(color->ColorMask, i, 1),
+ GET_COLORMASK_BIT(color->ColorMask, i, 2),
+ GET_COLORMASK_BIT(color->ColorMask, i, 3));
}
}
{
diff --git a/src/mesa/main/blend.c b/src/mesa/main/blend.c
index ec8e27e1d4d..34e8d11569d 100644
--- a/src/mesa/main/blend.c
+++ b/src/mesa/main/blend.c
@@ -974,33 +974,23 @@ _mesa_ColorMask( GLboolean red, GLboolean green,
GLboolean blue, GLboolean alpha )
{
GET_CURRENT_CONTEXT(ctx);
- GLubyte tmp[4];
- GLuint i;
- GLboolean flushed;
if (MESA_VERBOSE & VERBOSE_API)
_mesa_debug(ctx, "glColorMask(%d, %d, %d, %d)\n",
red, green, blue, alpha);
- /* 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;
-
- 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, ctx->DriverFlags.NewColorMask ? 0 : _NEW_COLOR);
- ctx->NewDriverState |= ctx->DriverFlags.NewColorMask;
- }
- flushed = GL_TRUE;
- COPY_4UBV(ctx->Color.ColorMask[i], tmp);
- }
- }
+ GLbitfield mask = (!!red) |
+ ((!!green) << 1) |
+ ((!!blue) << 2) |
+ ((!!alpha) << 3);
+ mask = _mesa_replicate_colormask(mask, ctx->Const.MaxDrawBuffers);
+
+ if (ctx->Color.ColorMask == mask)
+ return;
+
+ FLUSH_VERTICES(ctx, ctx->DriverFlags.NewColorMask ? 0 : _NEW_COLOR);
+ ctx->NewDriverState |= ctx->DriverFlags.NewColorMask;
+ ctx->Color.ColorMask = mask;
if (ctx->Driver.ColorMask)
ctx->Driver.ColorMask( ctx, red, green, blue, alpha );
@@ -1014,7 +1004,6 @@ void GLAPIENTRY
_mesa_ColorMaski(GLuint buf, GLboolean red, GLboolean green,
GLboolean blue, GLboolean alpha)
{
- GLubyte tmp[4];
GET_CURRENT_CONTEXT(ctx);
if (MESA_VERBOSE & VERBOSE_API)
@@ -1026,20 +1015,18 @@ _mesa_ColorMaski(GLuint buf, GLboolean red, GLboolean green,
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;
+ GLbitfield mask = (!!red) |
+ ((!!green) << 1) |
+ ((!!blue) << 2) |
+ ((!!alpha) << 3);
- if (TEST_EQ_4V(tmp, ctx->Color.ColorMask[buf]))
+ if (GET_COLORMASK(ctx->Color.ColorMask, buf) == mask)
return;
FLUSH_VERTICES(ctx, ctx->DriverFlags.NewColorMask ? 0 : _NEW_COLOR);
ctx->NewDriverState |= ctx->DriverFlags.NewColorMask;
- COPY_4UBV(ctx->Color.ColorMask[buf], tmp);
+ ctx->Color.ColorMask &= ~(0xf << (4 * buf));
+ ctx->Color.ColorMask |= mask << (4 * buf);
}
@@ -1190,7 +1177,7 @@ void _mesa_init_color( struct gl_context * ctx )
/* Color buffer group */
ctx->Color.IndexMask = ~0u;
- memset(ctx->Color.ColorMask, 0xff, sizeof(ctx->Color.ColorMask));
+ ctx->Color.ColorMask = 0xffffffff;
ctx->Color.ClearIndex = 0;
ASSIGN_4V( ctx->Color.ClearColor.f, 0, 0, 0, 0 );
ctx->Color.AlphaEnabled = GL_FALSE;
diff --git a/src/mesa/main/blend.h b/src/mesa/main/blend.h
index c95bc578961..6e56f2fd1ea 100644
--- a/src/mesa/main/blend.h
+++ b/src/mesa/main/blend.h
@@ -198,4 +198,14 @@ _mesa_flush_vertices_for_blend_adv(struct gl_context *ctx,
_mesa_flush_vertices_for_blend_state(ctx);
}
+static inline GLbitfield
+_mesa_replicate_colormask(GLbitfield mask0, unsigned num_buffers)
+{
+ GLbitfield mask = mask0;
+
+ for (unsigned i = 1; i < num_buffers; i++)
+ mask |= mask0 << (i * 4);
+ return mask;
+}
+
#endif
diff --git a/src/mesa/main/clear.c b/src/mesa/main/clear.c
index be604426a0a..6beff9ed842 100644
--- a/src/mesa/main/clear.c
+++ b/src/mesa/main/clear.c
@@ -118,7 +118,7 @@ color_buffer_writes_enabled(const struct gl_context *ctx, unsigned idx)
if (rb) {
for (c = 0; c < 4; c++) {
- if (ctx->Color.ColorMask[idx][c] &&
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, idx, c) &&
_mesa_format_has_color_component(rb->Format, c)) {
return true;
}
diff --git a/src/mesa/main/get.c b/src/mesa/main/get.c
index cf9a2f66d2f..516e8d174ce 100644
--- a/src/mesa/main/get.c
+++ b/src/mesa/main/get.c
@@ -677,10 +677,10 @@ find_custom_value(struct gl_context *ctx, const struct value_desc *d, union valu
break;
case GL_COLOR_WRITEMASK:
- v->value_int_4[0] = ctx->Color.ColorMask[0][RCOMP] ? 1 : 0;
- v->value_int_4[1] = ctx->Color.ColorMask[0][GCOMP] ? 1 : 0;
- v->value_int_4[2] = ctx->Color.ColorMask[0][BCOMP] ? 1 : 0;
- v->value_int_4[3] = ctx->Color.ColorMask[0][ACOMP] ? 1 : 0;
+ v->value_int_4[0] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0);
+ v->value_int_4[1] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1);
+ v->value_int_4[2] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2);
+ v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3);
break;
case GL_EDGE_FLAG:
@@ -2262,10 +2262,10 @@ find_value_indexed(const char *func, GLenum pname, GLuint index, union value *v)
goto invalid_value;
if (!ctx->Extensions.EXT_draw_buffers2)
goto invalid_enum;
- v->value_int_4[0] = ctx->Color.ColorMask[index][RCOMP] ? 1 : 0;
- v->value_int_4[1] = ctx->Color.ColorMask[index][GCOMP] ? 1 : 0;
- v->value_int_4[2] = ctx->Color.ColorMask[index][BCOMP] ? 1 : 0;
- v->value_int_4[3] = ctx->Color.ColorMask[index][ACOMP] ? 1 : 0;
+ v->value_int_4[0] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 0);
+ v->value_int_4[1] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 1);
+ v->value_int_4[2] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 2);
+ v->value_int_4[3] = GET_COLORMASK_BIT(ctx->Color.ColorMask, index, 3);
return TYPE_INT_4;
case GL_SCISSOR_BOX:
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index b00f059e39a..3a67d43420f 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -81,6 +81,10 @@ typedef GLuint64 GLbitfield64;
(BITFIELD64_MASK((b) + (count)) & ~BITFIELD64_MASK(b))
+#define GET_COLORMASK_BIT(mask, buf, chan) (((mask) >> (4 * (buf) + (chan))) & 0x1)
+#define GET_COLORMASK(mask, buf) (((mask) >> (4 * (buf))) & 0xf)
+
+
/**
* \name Some forward type declarations
*/
@@ -459,7 +463,9 @@ struct gl_colorbuffer_attrib
GLuint ClearIndex; /**< Index for glClear */
union gl_color_union ClearColor; /**< Color for glClear, unclamped */
GLuint IndexMask; /**< Color index write mask */
- GLubyte ColorMask[MAX_DRAW_BUFFERS][4]; /**< Each flag is 0xff or 0x0 */
+
+ /** 4 colormask bits per draw buffer, max 8 draw buffers. 4*8 = 32 bits */
+ GLbitfield ColorMask;
GLenum16 DrawBuffer[MAX_DRAW_BUFFERS]; /**< Which buffer to draw into */