summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2018-01-31 03:03:25 +0100
committerMarek Olšák <[email protected]>2018-02-04 01:50:10 +0100
commitaf3685d14936844f79e6f372b4b258e29375f21b (patch)
tree84c3ab4b661bceaf4364be3e7c9501cb6b50537e
parent83e60ce927142752c57163fcb8b30eca2370d014 (diff)
mesa: change ctx->Color.ColorMask into a 32-bit bitmask
4 bits per draw buffer, 8 draw buffers in total --> 32 bits. This is easier to work with. Reviewed-by: Eric Anholt <[email protected]>
-rw-r--r--src/mesa/drivers/common/driverfuncs.c8
-rw-r--r--src/mesa/drivers/common/meta.c41
-rw-r--r--src/mesa/drivers/common/meta.h2
-rw-r--r--src/mesa/drivers/dri/i915/intel_clear.c5
-rw-r--r--src/mesa/drivers/dri/i915/intel_pixel.c5
-rw-r--r--src/mesa/drivers/dri/i915/intel_pixel_copy.c5
-rw-r--r--src/mesa/drivers/dri/i965/brw_blorp.c9
-rw-r--r--src/mesa/drivers/dri/i965/brw_wm_surface_state.c8
-rw-r--r--src/mesa/drivers/dri/i965/genX_state_upload.c13
-rw-r--r--src/mesa/drivers/dri/i965/intel_pixel.c5
-rw-r--r--src/mesa/drivers/dri/i965/intel_pixel_copy.c5
-rw-r--r--src/mesa/drivers/dri/nouveau/nouveau_driver.c8
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_context.c5
-rw-r--r--src/mesa/drivers/dri/nouveau/nv04_state_raster.c8
-rw-r--r--src/mesa/drivers/dri/nouveau/nv10_state_raster.c8
-rw-r--r--src/mesa/drivers/dri/nouveau/nv20_context.c8
-rw-r--r--src/mesa/drivers/dri/r200/r200_state.c8
-rw-r--r--src/mesa/drivers/dri/radeon/radeon_state.c8
-rw-r--r--src/mesa/drivers/x11/xm_dd.c4
-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
-rw-r--r--src/mesa/state_tracker/st_atom_blend.c27
-rw-r--r--src/mesa/state_tracker/st_cb_clear.c39
-rw-r--r--src/mesa/swrast/s_clear.c8
-rw-r--r--src/mesa/swrast/s_context.c10
-rw-r--r--src/mesa/swrast/s_masking.c24
-rw-r--r--src/mesa/swrast/s_span.c6
-rw-r--r--src/mesa/swrast/s_triangle.c8
33 files changed, 174 insertions, 232 deletions
diff --git a/src/mesa/drivers/common/driverfuncs.c b/src/mesa/drivers/common/driverfuncs.c
index 99c1520d2ad..8f2e3e075c8 100644
--- a/src/mesa/drivers/common/driverfuncs.c
+++ b/src/mesa/drivers/common/driverfuncs.c
@@ -232,10 +232,10 @@ _mesa_init_driver_state(struct gl_context *ctx)
ctx->Color.Blend[0].DstA);
ctx->Driver.ColorMask(ctx,
- ctx->Color.ColorMask[0][RCOMP],
- ctx->Color.ColorMask[0][GCOMP],
- ctx->Color.ColorMask[0][BCOMP],
- ctx->Color.ColorMask[0][ACOMP]);
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3));
ctx->Driver.CullFace(ctx, ctx->Polygon.CullFaceMode);
ctx->Driver.DepthFunc(ctx, ctx->Depth.Func);
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index a48f7000269..a7dd139500f 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -515,10 +515,8 @@ _mesa_meta_begin(struct gl_context *ctx, GLbitfield state)
_mesa_set_enable(ctx, GL_DITHER, GL_TRUE);
}
- if (state & MESA_META_COLOR_MASK) {
- memcpy(save->ColorMask, ctx->Color.ColorMask,
- sizeof(ctx->Color.ColorMask));
- }
+ if (state & MESA_META_COLOR_MASK)
+ save->ColorMask = ctx->Color.ColorMask;
if (state & MESA_META_DEPTH_TEST) {
save->Depth = ctx->Depth; /* struct copy */
@@ -880,17 +878,20 @@ _mesa_meta_end(struct gl_context *ctx)
if (state & MESA_META_COLOR_MASK) {
GLuint i;
for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- if (!TEST_EQ_4V(ctx->Color.ColorMask[i], save->ColorMask[i])) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, i) !=
+ GET_COLORMASK(save->ColorMask, i)) {
if (i == 0) {
- _mesa_ColorMask(save->ColorMask[i][0], save->ColorMask[i][1],
- save->ColorMask[i][2], save->ColorMask[i][3]);
+ _mesa_ColorMask(GET_COLORMASK_BIT(save->ColorMask, i, 0),
+ GET_COLORMASK_BIT(save->ColorMask, i, 1),
+ GET_COLORMASK_BIT(save->ColorMask, i, 2),
+ GET_COLORMASK_BIT(save->ColorMask, i, 3));
}
else {
_mesa_ColorMaski(i,
- save->ColorMask[i][0],
- save->ColorMask[i][1],
- save->ColorMask[i][2],
- save->ColorMask[i][3]);
+ GET_COLORMASK_BIT(save->ColorMask, i, 0),
+ GET_COLORMASK_BIT(save->ColorMask, i, 1),
+ GET_COLORMASK_BIT(save->ColorMask, i, 2),
+ GET_COLORMASK_BIT(save->ColorMask, i, 3));
}
}
}
@@ -1631,18 +1632,6 @@ _mesa_meta_drawbuffers_from_bitfield(GLbitfield bits)
}
/**
- * Return if all of the color channels are masked.
- */
-static inline GLboolean
-is_color_disabled(struct gl_context *ctx, int i)
-{
- return !ctx->Color.ColorMask[i][0] &&
- !ctx->Color.ColorMask[i][1] &&
- !ctx->Color.ColorMask[i][2] &&
- !ctx->Color.ColorMask[i][3];
-}
-
-/**
* Given a bitfield of BUFFER_BIT_x draw buffers, call glDrawBuffers to
* set GL to only draw to those buffers. Also, update color masks to
* reflect the new draw buffer ordering.
@@ -1666,7 +1655,8 @@ _mesa_meta_drawbuffers_and_colormask(struct gl_context *ctx, GLbitfield mask)
gl_buffer_index b = ctx->DrawBuffer->_ColorDrawBufferIndexes[i];
int colormask_idx = ctx->Extensions.EXT_draw_buffers2 ? i : 0;
- if (b < 0 || !(mask & (1 << b)) || is_color_disabled(ctx, colormask_idx))
+ if (b < 0 || !(mask & (1 << b)) ||
+ GET_COLORMASK(ctx->Color.ColorMask, colormask_idx) == 0)
continue;
switch (b) {
@@ -1689,7 +1679,8 @@ _mesa_meta_drawbuffers_and_colormask(struct gl_context *ctx, GLbitfield mask)
}
for (int k = 0; k < 4; k++)
- colormask[num_bufs][k] = ctx->Color.ColorMask[colormask_idx][k];
+ colormask[num_bufs][k] = GET_COLORMASK_BIT(ctx->Color.ColorMask,
+ colormask_idx, k);
num_bufs++;
}
diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index 3d9c2917d2d..1c35ea3e0bf 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -90,7 +90,7 @@ struct save_state
GLboolean DitherFlag;
/** MESA_META_COLOR_MASK */
- GLubyte ColorMask[MAX_DRAW_BUFFERS][4];
+ GLbitfield ColorMask;
/** MESA_META_DEPTH_TEST */
struct gl_depthbuffer_attrib Depth;
diff --git a/src/mesa/drivers/dri/i915/intel_clear.c b/src/mesa/drivers/dri/i915/intel_clear.c
index f8df2e08d37..c9722cbe405 100644
--- a/src/mesa/drivers/dri/i915/intel_clear.c
+++ b/src/mesa/drivers/dri/i915/intel_clear.c
@@ -81,7 +81,6 @@ static void
intelClear(struct gl_context *ctx, GLbitfield mask)
{
struct intel_context *intel = intel_context(ctx);
- GLuint colorMask;
GLbitfield tri_mask = 0;
GLbitfield blit_mask = 0;
GLbitfield swrast_mask = 0;
@@ -89,8 +88,6 @@ intelClear(struct gl_context *ctx, GLbitfield mask)
struct intel_renderbuffer *irb;
int i;
- memcpy(&colorMask, &ctx->Color.ColorMask[0], sizeof(colorMask));
-
if (mask & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_FRONT_RIGHT)) {
intel->front_buffer_dirty = true;
}
@@ -115,7 +112,7 @@ intelClear(struct gl_context *ctx, GLbitfield mask)
}
/* HW color buffers (front, back, aux, generic FBO, etc) */
- if (colorMask == ~0) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, 0) == 0xf) {
/* clear all R,G,B,A */
blit_mask |= (mask & BUFFER_BITS_COLOR);
}
diff --git a/src/mesa/drivers/dri/i915/intel_pixel.c b/src/mesa/drivers/dri/i915/intel_pixel.c
index 084b5636b48..eaca8e30978 100644
--- a/src/mesa/drivers/dri/i915/intel_pixel.c
+++ b/src/mesa/drivers/dri/i915/intel_pixel.c
@@ -83,10 +83,7 @@ intel_check_blit_fragment_ops(struct gl_context * ctx, bool src_alpha_is_one)
return false;
}
- if (!(ctx->Color.ColorMask[0][0] &&
- ctx->Color.ColorMask[0][1] &&
- ctx->Color.ColorMask[0][2] &&
- ctx->Color.ColorMask[0][3])) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, 0) != 0xf) {
DBG("fallback due to color masking\n");
return false;
}
diff --git a/src/mesa/drivers/dri/i915/intel_pixel_copy.c b/src/mesa/drivers/dri/i915/intel_pixel_copy.c
index 0dea8f9c796..1b1993ea728 100644
--- a/src/mesa/drivers/dri/i915/intel_pixel_copy.c
+++ b/src/mesa/drivers/dri/i915/intel_pixel_copy.c
@@ -130,10 +130,7 @@ do_blit_copypixels(struct gl_context * ctx,
return false;
}
- if (!ctx->Color.ColorMask[0][0] ||
- !ctx->Color.ColorMask[0][1] ||
- !ctx->Color.ColorMask[0][2] ||
- !ctx->Color.ColorMask[0][3]) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, 0) != 0xf) {
perf_debug("glCopyPixels(): Unsupported color mask state\n");
return false;
}
diff --git a/src/mesa/drivers/dri/i965/brw_blorp.c b/src/mesa/drivers/dri/i965/brw_blorp.c
index 82d9de1ead5..30120df9a50 100644
--- a/src/mesa/drivers/dri/i965/brw_blorp.c
+++ b/src/mesa/drivers/dri/i965/brw_blorp.c
@@ -1117,7 +1117,7 @@ err:
static bool
set_write_disables(const struct intel_renderbuffer *irb,
- const GLubyte *color_mask, bool *color_write_disable)
+ const unsigned color_mask, bool *color_write_disable)
{
/* Format information in the renderbuffer represents the requirements
* given by the client. There are cases where the backing miptree uses,
@@ -1131,8 +1131,8 @@ set_write_disables(const struct intel_renderbuffer *irb,
assert(components > 0);
for (int i = 0; i < components; i++) {
- color_write_disable[i] = !color_mask[i];
- disables = disables || !color_mask[i];
+ color_write_disable[i] = !(color_mask & (1 << i));
+ disables = disables || color_write_disable[i];
}
return disables;
@@ -1169,7 +1169,8 @@ do_single_blorp_clear(struct brw_context *brw, struct gl_framebuffer *fb,
bool can_fast_clear = !partial_clear;
bool color_write_disable[4] = { false, false, false, false };
- if (set_write_disables(irb, ctx->Color.ColorMask[buf], color_write_disable))
+ if (set_write_disables(irb, GET_COLORMASK(ctx->Color.ColorMask, buf),
+ color_write_disable))
can_fast_clear = false;
/* We store clear colors as floats or uints as needed. If there are
diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
index 611e85024d8..92ac1e45a3a 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
@@ -919,18 +919,18 @@ gen4_update_renderbuffer_surface(struct brw_context *brw,
(ctx->Color.BlendEnabled & (1 << unit)))
surf[0] |= BRW_SURFACE_BLEND_ENABLED;
- if (!ctx->Color.ColorMask[unit][0])
+ if (!GET_COLORMASK_BIT(ctx->Color.ColorMask, unit, 0))
surf[0] |= 1 << BRW_SURFACE_WRITEDISABLE_R_SHIFT;
- if (!ctx->Color.ColorMask[unit][1])
+ if (!GET_COLORMASK_BIT(ctx->Color.ColorMask, unit, 1))
surf[0] |= 1 << BRW_SURFACE_WRITEDISABLE_G_SHIFT;
- if (!ctx->Color.ColorMask[unit][2])
+ if (!GET_COLORMASK_BIT(ctx->Color.ColorMask, unit, 2))
surf[0] |= 1 << BRW_SURFACE_WRITEDISABLE_B_SHIFT;
/* As mentioned above, disable writes to the alpha component when the
* renderbuffer is XRGB.
*/
if (ctx->DrawBuffer->Visual.alphaBits == 0 ||
- !ctx->Color.ColorMask[unit][3]) {
+ !GET_COLORMASK_BIT(ctx->Color.ColorMask, unit, 3)) {
surf[0] |= 1 << BRW_SURFACE_WRITEDISABLE_A_SHIFT;
}
}
diff --git a/src/mesa/drivers/dri/i965/genX_state_upload.c b/src/mesa/drivers/dri/i965/genX_state_upload.c
index 45636fe69df..e607852c7ac 100644
--- a/src/mesa/drivers/dri/i965/genX_state_upload.c
+++ b/src/mesa/drivers/dri/i965/genX_state_upload.c
@@ -1751,10 +1751,7 @@ brw_color_buffer_write_enabled(struct brw_context *brw)
/* _NEW_COLOR */
if (rb && (outputs_written & BITFIELD64_BIT(FRAG_RESULT_COLOR) ||
outputs_written & BITFIELD64_BIT(FRAG_RESULT_DATA0 + i)) &&
- (ctx->Color.ColorMask[i][0] ||
- ctx->Color.ColorMask[i][1] ||
- ctx->Color.ColorMask[i][2] ||
- ctx->Color.ColorMask[i][3])) {
+ GET_COLORMASK(ctx->Color.ColorMask, i)) {
return true;
}
}
@@ -2993,10 +2990,10 @@ genX(upload_blend_state)(struct brw_context *brw)
entry.PostBlendColorClampEnable = true;
entry.ColorClampRange = COLORCLAMP_RTFORMAT;
- entry.WriteDisableRed = !ctx->Color.ColorMask[i][0];
- entry.WriteDisableGreen = !ctx->Color.ColorMask[i][1];
- entry.WriteDisableBlue = !ctx->Color.ColorMask[i][2];
- entry.WriteDisableAlpha = !ctx->Color.ColorMask[i][3];
+ entry.WriteDisableRed = !GET_COLORMASK_BIT(ctx->Color.ColorMask, i, 0);
+ entry.WriteDisableGreen = !GET_COLORMASK_BIT(ctx->Color.ColorMask, i, 1);
+ entry.WriteDisableBlue = !GET_COLORMASK_BIT(ctx->Color.ColorMask, i, 2);
+ entry.WriteDisableAlpha = !GET_COLORMASK_BIT(ctx->Color.ColorMask, i, 3);
#if GEN_GEN >= 8
GENX(BLEND_STATE_ENTRY_pack)(NULL, &blend_map[1 + i * 2], &entry);
diff --git a/src/mesa/drivers/dri/i965/intel_pixel.c b/src/mesa/drivers/dri/i965/intel_pixel.c
index c69c3cc7dce..0cbb572838c 100644
--- a/src/mesa/drivers/dri/i965/intel_pixel.c
+++ b/src/mesa/drivers/dri/i965/intel_pixel.c
@@ -80,10 +80,7 @@ intel_check_blit_fragment_ops(struct gl_context * ctx, bool src_alpha_is_one)
return false;
}
- if (!(ctx->Color.ColorMask[0][0] &&
- ctx->Color.ColorMask[0][1] &&
- ctx->Color.ColorMask[0][2] &&
- ctx->Color.ColorMask[0][3])) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, 0) != 0xf) {
DBG("fallback due to color masking\n");
return false;
}
diff --git a/src/mesa/drivers/dri/i965/intel_pixel_copy.c b/src/mesa/drivers/dri/i965/intel_pixel_copy.c
index a23c5b18ac6..8029ffbeddc 100644
--- a/src/mesa/drivers/dri/i965/intel_pixel_copy.c
+++ b/src/mesa/drivers/dri/i965/intel_pixel_copy.c
@@ -134,10 +134,7 @@ do_blit_copypixels(struct gl_context * ctx,
return false;
}
- if (!ctx->Color.ColorMask[0][0] ||
- !ctx->Color.ColorMask[0][1] ||
- !ctx->Color.ColorMask[0][2] ||
- !ctx->Color.ColorMask[0][3]) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, 0) != 0xf) {
perf_debug("glCopyPixels(): Unsupported color mask state\n");
return false;
}
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_driver.c b/src/mesa/drivers/dri/nouveau/nouveau_driver.c
index 998e751fc3c..1698df6ab19 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_driver.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_driver.c
@@ -132,7 +132,13 @@ nouveau_clear(struct gl_context *ctx, GLbitfield buffers)
else
value = pack_rgba_clamp_f(s->format, color);
- mask = pack_rgba_i(s->format, ctx->Color.ColorMask[0]);
+ const uint8_t colormask[4] = {
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3) ? 0xff : 0,
+ };
+ mask = pack_rgba_i(s->format, colormask);
if (mask)
context_drv(ctx)->surface_fill(
diff --git a/src/mesa/drivers/dri/nouveau/nv04_context.c b/src/mesa/drivers/dri/nouveau/nv04_context.c
index 3cc219beab4..4dbb950e9ab 100644
--- a/src/mesa/drivers/dri/nouveau/nv04_context.c
+++ b/src/mesa/drivers/dri/nouveau/nv04_context.c
@@ -57,10 +57,7 @@ nv04_context_engine(struct gl_context *ctx)
texunit_needs_combiners(&ctx->Texture.Unit[0])) ||
ctx->Texture.Unit[1]._Current ||
ctx->Stencil.Enabled ||
- !(ctx->Color.ColorMask[0][RCOMP] &&
- ctx->Color.ColorMask[0][GCOMP] &&
- ctx->Color.ColorMask[0][BCOMP] &&
- ctx->Color.ColorMask[0][ACOMP]))
+ GET_COLORMASK(ctx->Color.ColorMask, 0) != 0xf)
fahrenheit = hw->eng3dm;
else
fahrenheit = hw->eng3d;
diff --git a/src/mesa/drivers/dri/nouveau/nv04_state_raster.c b/src/mesa/drivers/dri/nouveau/nv04_state_raster.c
index 69664fb40ad..a2b0ab921de 100644
--- a/src/mesa/drivers/dri/nouveau/nv04_state_raster.c
+++ b/src/mesa/drivers/dri/nouveau/nv04_state_raster.c
@@ -162,13 +162,13 @@ nv04_emit_control(struct gl_context *ctx, int emit)
FLOAT_TO_UBYTE(ctx->Color.AlphaRef);
/* Color mask. */
- if (ctx->Color.ColorMask[0][RCOMP])
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0))
nv04->ctrl[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_RED_WRITE;
- if (ctx->Color.ColorMask[0][GCOMP])
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1))
nv04->ctrl[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_GREEN_WRITE;
- if (ctx->Color.ColorMask[0][BCOMP])
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2))
nv04->ctrl[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_BLUE_WRITE;
- if (ctx->Color.ColorMask[0][ACOMP])
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3))
nv04->ctrl[0] |= NV04_MULTITEX_TRIANGLE_CONTROL0_ALPHA_WRITE;
/* Stencil test. */
diff --git a/src/mesa/drivers/dri/nouveau/nv10_state_raster.c b/src/mesa/drivers/dri/nouveau/nv10_state_raster.c
index 047f539dbc5..3f4ff73cef5 100644
--- a/src/mesa/drivers/dri/nouveau/nv10_state_raster.c
+++ b/src/mesa/drivers/dri/nouveau/nv10_state_raster.c
@@ -87,10 +87,10 @@ nv10_emit_color_mask(struct gl_context *ctx, int emit)
struct nouveau_pushbuf *push = context_push(ctx);
BEGIN_NV04(push, NV10_3D(COLOR_MASK), 1);
- PUSH_DATA (push, ((ctx->Color.ColorMask[0][3] ? 1 << 24 : 0) |
- (ctx->Color.ColorMask[0][0] ? 1 << 16 : 0) |
- (ctx->Color.ColorMask[0][1] ? 1 << 8 : 0) |
- (ctx->Color.ColorMask[0][2] ? 1 << 0 : 0)));
+ PUSH_DATA (push, ((GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3) ? 1 << 24 : 0) |
+ (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0) ? 1 << 16 : 0) |
+ (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1) ? 1 << 8 : 0) |
+ (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2) ? 1 << 0 : 0)));
}
void
diff --git a/src/mesa/drivers/dri/nouveau/nv20_context.c b/src/mesa/drivers/dri/nouveau/nv20_context.c
index 0ab2db0b086..887aa5f483f 100644
--- a/src/mesa/drivers/dri/nouveau/nv20_context.c
+++ b/src/mesa/drivers/dri/nouveau/nv20_context.c
@@ -55,13 +55,13 @@ nv20_clear(struct gl_context *ctx, GLbitfield buffers)
struct nouveau_surface *s = &to_nouveau_renderbuffer(
fb->_ColorDrawBuffers[0])->surface;
- if (ctx->Color.ColorMask[0][RCOMP])
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0))
clear |= NV20_3D_CLEAR_BUFFERS_COLOR_R;
- if (ctx->Color.ColorMask[0][GCOMP])
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1))
clear |= NV20_3D_CLEAR_BUFFERS_COLOR_G;
- if (ctx->Color.ColorMask[0][BCOMP])
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2))
clear |= NV20_3D_CLEAR_BUFFERS_COLOR_B;
- if (ctx->Color.ColorMask[0][ACOMP])
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3))
clear |= NV20_3D_CLEAR_BUFFERS_COLOR_A;
BEGIN_NV04(push, NV20_3D(CLEAR_VALUE), 1);
diff --git a/src/mesa/drivers/dri/r200/r200_state.c b/src/mesa/drivers/dri/r200/r200_state.c
index 62a089ea750..33b696347a3 100644
--- a/src/mesa/drivers/dri/r200/r200_state.c
+++ b/src/mesa/drivers/dri/r200/r200_state.c
@@ -688,10 +688,10 @@ static void r200ColorMask( struct gl_context *ctx,
if (!rrb)
return;
mask = radeonPackColor( rrb->cpp,
- ctx->Color.ColorMask[0][RCOMP],
- ctx->Color.ColorMask[0][GCOMP],
- ctx->Color.ColorMask[0][BCOMP],
- ctx->Color.ColorMask[0][ACOMP] );
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3) );
if (!(r && g && b && a))
diff --git a/src/mesa/drivers/dri/radeon/radeon_state.c b/src/mesa/drivers/dri/radeon/radeon_state.c
index a5c7be32230..e413df3542e 100644
--- a/src/mesa/drivers/dri/radeon/radeon_state.c
+++ b/src/mesa/drivers/dri/radeon/radeon_state.c
@@ -504,10 +504,10 @@ static void radeonColorMask( struct gl_context *ctx,
return;
mask = radeonPackColor( rrb->cpp,
- ctx->Color.ColorMask[0][RCOMP],
- ctx->Color.ColorMask[0][GCOMP],
- ctx->Color.ColorMask[0][BCOMP],
- ctx->Color.ColorMask[0][ACOMP] );
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2),
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3) );
if ( rmesa->hw.msk.cmd[MSK_RB3D_PLANEMASK] != mask ) {
RADEON_STATECHANGE( rmesa, msk );
diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c
index 3e61342512d..3c576c7cd8b 100644
--- a/src/mesa/drivers/x11/xm_dd.c
+++ b/src/mesa/drivers/x11/xm_dd.c
@@ -245,7 +245,6 @@ clear_buffers(struct gl_context *ctx, GLbitfield buffers)
{
if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) {
/* this is a window system framebuffer */
- const GLuint *colorMask = (GLuint *) &ctx->Color.ColorMask[0];
const XMesaContext xmesa = XMESA_CONTEXT(ctx);
XMesaBuffer b = XMESA_BUFFER(ctx->DrawBuffer);
const GLint x = ctx->DrawBuffer->_Xmin;
@@ -264,7 +263,8 @@ clear_buffers(struct gl_context *ctx, GLbitfield buffers)
XMesaSetForeground(xmesa->display, b->cleargc, xmesa->clearpixel);
/* we can't handle color or index masking */
- if (*colorMask == 0xffffffff && ctx->Color.IndexMask == 0xffffffff) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, 0) == 0xf &&
+ ctx->Color.IndexMask == 0xffffffff) {
if (buffers & BUFFER_BIT_FRONT_LEFT) {
/* clear front color buffer */
struct gl_renderbuffer *frontRb
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 */
diff --git a/src/mesa/state_tracker/st_atom_blend.c b/src/mesa/state_tracker/st_atom_blend.c
index 8bc5a5fd12c..f7327d6838c 100644
--- a/src/mesa/state_tracker/st_atom_blend.c
+++ b/src/mesa/state_tracker/st_atom_blend.c
@@ -40,6 +40,7 @@
#include "cso_cache/cso_context.h"
#include "framebuffer.h"
+#include "main/blend.h"
#include "main/macros.h"
/**
@@ -113,14 +114,11 @@ translate_blend(GLenum blend)
static GLboolean
colormask_per_rt(const struct gl_context *ctx)
{
- /* a bit suboptimal have to compare lots of values */
- unsigned i;
- for (i = 1; i < ctx->Const.MaxDrawBuffers; i++) {
- if (memcmp(ctx->Color.ColorMask[0], ctx->Color.ColorMask[i], 4)) {
- return GL_TRUE;
- }
- }
- return GL_FALSE;
+ GLbitfield repl_mask0 =
+ _mesa_replicate_colormask(GET_COLORMASK(ctx->Color.ColorMask, 0),
+ ctx->Const.MaxDrawBuffers);
+
+ return ctx->Color.ColorMask != repl_mask0;
}
/**
@@ -206,17 +204,8 @@ st_update_blend( struct st_context *st )
/* no blending / logicop */
}
- /* Colormask - maybe reverse these bits? */
- for (i = 0; i < num_state; i++) {
- if (ctx->Color.ColorMask[i][0])
- blend->rt[i].colormask |= PIPE_MASK_R;
- if (ctx->Color.ColorMask[i][1])
- blend->rt[i].colormask |= PIPE_MASK_G;
- if (ctx->Color.ColorMask[i][2])
- blend->rt[i].colormask |= PIPE_MASK_B;
- if (ctx->Color.ColorMask[i][3])
- blend->rt[i].colormask |= PIPE_MASK_A;
- }
+ for (i = 0; i < num_state; i++)
+ blend->rt[i].colormask = GET_COLORMASK(ctx->Color.ColorMask, i);
blend->dither = ctx->Color.DitherFlag;
diff --git a/src/mesa/state_tracker/st_cb_clear.c b/src/mesa/state_tracker/st_cb_clear.c
index f50f8442d55..68677182abf 100644
--- a/src/mesa/state_tracker/st_cb_clear.c
+++ b/src/mesa/state_tracker/st_cb_clear.c
@@ -226,14 +226,7 @@ clear_with_quad(struct gl_context *ctx, unsigned clear_buffers)
if (!(clear_buffers & (PIPE_CLEAR_COLOR0 << i)))
continue;
- if (ctx->Color.ColorMask[i][0])
- blend.rt[i].colormask |= PIPE_MASK_R;
- if (ctx->Color.ColorMask[i][1])
- blend.rt[i].colormask |= PIPE_MASK_G;
- if (ctx->Color.ColorMask[i][2])
- blend.rt[i].colormask |= PIPE_MASK_B;
- if (ctx->Color.ColorMask[i][3])
- blend.rt[i].colormask |= PIPE_MASK_A;
+ blend.rt[i].colormask = GET_COLORMASK(ctx->Color.ColorMask, i);
}
if (ctx->Color.DitherFlag)
@@ -338,32 +331,6 @@ is_window_rectangle_enabled(struct gl_context *ctx)
/**
- * Return if all of the color channels are masked.
- */
-static inline GLboolean
-is_color_disabled(struct gl_context *ctx, int i)
-{
- return !ctx->Color.ColorMask[i][0] &&
- !ctx->Color.ColorMask[i][1] &&
- !ctx->Color.ColorMask[i][2] &&
- !ctx->Color.ColorMask[i][3];
-}
-
-
-/**
- * Return if any of the color channels are masked.
- */
-static inline GLboolean
-is_color_masked(struct gl_context *ctx, int i)
-{
- return !ctx->Color.ColorMask[i][0] ||
- !ctx->Color.ColorMask[i][1] ||
- !ctx->Color.ColorMask[i][2] ||
- !ctx->Color.ColorMask[i][3];
-}
-
-
-/**
* Return if all of the stencil bits are masked.
*/
static inline GLboolean
@@ -423,12 +390,12 @@ st_Clear(struct gl_context *ctx, GLbitfield mask)
if (!strb || !strb->surface)
continue;
- if (is_color_disabled(ctx, colormask_index))
+ if (!GET_COLORMASK(ctx->Color.ColorMask, colormask_index))
continue;
if (is_scissor_enabled(ctx, rb) ||
is_window_rectangle_enabled(ctx) ||
- is_color_masked(ctx, colormask_index))
+ GET_COLORMASK(ctx->Color.ColorMask, colormask_index) != 0xf)
quad_buffers |= PIPE_CLEAR_COLOR0 << i;
else
clear_buffers |= PIPE_CLEAR_COLOR0 << i;
diff --git a/src/mesa/swrast/s_clear.c b/src/mesa/swrast/s_clear.c
index c26b4be0d9e..ddafb67c98f 100644
--- a/src/mesa/swrast/s_clear.c
+++ b/src/mesa/swrast/s_clear.c
@@ -187,7 +187,13 @@ clear_color_buffers(struct gl_context *ctx)
if (rb == NULL)
continue;
- clear_rgba_buffer(ctx, rb, ctx->Color.ColorMask[buf]);
+ const GLubyte colormask[4] = {
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 0) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 1) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 2) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 3) ? 0xff : 0,
+ };
+ clear_rgba_buffer(ctx, rb, colormask);
}
}
diff --git a/src/mesa/swrast/s_context.c b/src/mesa/swrast/s_context.c
index 9f3d21f91d1..f7f08b19dd9 100644
--- a/src/mesa/swrast/s_context.c
+++ b/src/mesa/swrast/s_context.c
@@ -65,10 +65,7 @@ _swrast_update_rasterflags( struct gl_context *ctx )
if (ctx->Scissor.EnableFlags) rasterMask |= CLIP_BIT;
if (_mesa_stencil_is_enabled(ctx)) rasterMask |= STENCIL_BIT;
for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- if (!ctx->Color.ColorMask[i][0] ||
- !ctx->Color.ColorMask[i][1] ||
- !ctx->Color.ColorMask[i][2] ||
- !ctx->Color.ColorMask[i][3]) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, i) != 0xf) {
rasterMask |= MASKING_BIT;
break;
}
@@ -96,10 +93,7 @@ _swrast_update_rasterflags( struct gl_context *ctx )
}
for (i = 0; i < ctx->Const.MaxDrawBuffers; i++) {
- if (ctx->Color.ColorMask[i][0] +
- ctx->Color.ColorMask[i][1] +
- ctx->Color.ColorMask[i][2] +
- ctx->Color.ColorMask[i][3] == 0) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, i) == 0) {
rasterMask |= MULTI_DRAW_BIT; /* all RGBA channels disabled */
break;
}
diff --git a/src/mesa/swrast/s_masking.c b/src/mesa/swrast/s_masking.c
index c10bf1ac251..8941375a999 100644
--- a/src/mesa/swrast/s_masking.c
+++ b/src/mesa/swrast/s_masking.c
@@ -56,8 +56,14 @@ _swrast_mask_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
* Note that we're not using span->array->mask[] here. We could...
*/
if (span->array->ChanType == GL_UNSIGNED_BYTE) {
+ const GLubyte colormask[4] = {
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 0) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 1) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 2) ? 0xff : 0,
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 3) ? 0xff : 0,
+ };
GLuint srcMask;
- memcpy(&srcMask, ctx->Color.ColorMask[buf], sizeof(srcMask));
+ memcpy(&srcMask, colormask, sizeof(srcMask));
const GLuint dstMask = ~srcMask;
const GLuint *dst = (const GLuint *) rbPixels;
GLuint *src = (GLuint *) span->array->rgba8;
@@ -69,10 +75,10 @@ _swrast_mask_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
else if (span->array->ChanType == GL_UNSIGNED_SHORT) {
/* 2-byte components */
/* XXX try to use 64-bit arithmetic someday */
- const GLushort rMask = ctx->Color.ColorMask[buf][RCOMP] ? 0xffff : 0x0;
- const GLushort gMask = ctx->Color.ColorMask[buf][GCOMP] ? 0xffff : 0x0;
- const GLushort bMask = ctx->Color.ColorMask[buf][BCOMP] ? 0xffff : 0x0;
- const GLushort aMask = ctx->Color.ColorMask[buf][ACOMP] ? 0xffff : 0x0;
+ const GLushort rMask = GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 0) ? 0xffff : 0x0;
+ const GLushort gMask = GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 1) ? 0xffff : 0x0;
+ const GLushort bMask = GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 2) ? 0xffff : 0x0;
+ const GLushort aMask = GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 3) ? 0xffff : 0x0;
const GLushort (*dst)[4] = (const GLushort (*)[4]) rbPixels;
GLushort (*src)[4] = span->array->rgba16;
GLuint i;
@@ -85,10 +91,10 @@ _swrast_mask_rgba_span(struct gl_context *ctx, struct gl_renderbuffer *rb,
}
else {
/* 4-byte components */
- const GLuint rMask = ctx->Color.ColorMask[buf][RCOMP] ? ~0x0 : 0x0;
- const GLuint gMask = ctx->Color.ColorMask[buf][GCOMP] ? ~0x0 : 0x0;
- const GLuint bMask = ctx->Color.ColorMask[buf][BCOMP] ? ~0x0 : 0x0;
- const GLuint aMask = ctx->Color.ColorMask[buf][ACOMP] ? ~0x0 : 0x0;
+ const GLuint rMask = GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 0) ? ~0x0 : 0x0;
+ const GLuint gMask = GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 1) ? ~0x0 : 0x0;
+ const GLuint bMask = GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 2) ? ~0x0 : 0x0;
+ const GLuint aMask = GET_COLORMASK_BIT(ctx->Color.ColorMask, buf, 3) ? ~0x0 : 0x0;
const GLuint (*dst)[4] = (const GLuint (*)[4]) rbPixels;
GLuint (*src)[4] = (GLuint (*)[4]) span->array->attribs[VARYING_SLOT_COL0];
GLuint i;
diff --git a/src/mesa/swrast/s_span.c b/src/mesa/swrast/s_span.c
index 47a73e99f3d..9bc1f227fe1 100644
--- a/src/mesa/swrast/s_span.c
+++ b/src/mesa/swrast/s_span.c
@@ -1133,7 +1133,6 @@ void
_swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
{
const SWcontext *swrast = SWRAST_CONTEXT(ctx);
- const GLuint *colorMask = (GLuint *) ctx->Color.ColorMask;
const GLbitfield origInterpMask = span->interpMask;
const GLbitfield origArrayMask = span->arrayMask;
const GLbitfield64 origArrayAttribs = span->arrayAttribs;
@@ -1251,7 +1250,8 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
/* We had to wait until now to check for glColorMask(0,0,0,0) because of
* the occlusion test.
*/
- if (fb->_NumColorDrawBuffers == 1 && colorMask[0] == 0x0) {
+ if (fb->_NumColorDrawBuffers == 1 &&
+ !GET_COLORMASK(ctx->Color.ColorMask, 0)) {
/* no colors to write */
goto end;
}
@@ -1368,7 +1368,7 @@ _swrast_write_rgba_span( struct gl_context *ctx, SWspan *span)
_swrast_blend_span(ctx, rb, span);
}
- if (colorMask[buf] != 0xffffffff) {
+ if (GET_COLORMASK(ctx->Color.ColorMask, buf) != 0xf) {
_swrast_mask_rgba_span(ctx, rb, span, buf);
}
diff --git a/src/mesa/swrast/s_triangle.c b/src/mesa/swrast/s_triangle.c
index a4113e5582b..c84cfec93d3 100644
--- a/src/mesa/swrast/s_triangle.c
+++ b/src/mesa/swrast/s_triangle.c
@@ -1027,10 +1027,10 @@ _swrast_choose_triangle( struct gl_context *ctx )
!_mesa_stencil_is_enabled(ctx) &&
depthRb &&
depthRb->Format == MESA_FORMAT_Z_UNORM16) {
- if (ctx->Color.ColorMask[0][0] == 0 &&
- ctx->Color.ColorMask[0][1] == 0 &&
- ctx->Color.ColorMask[0][2] == 0 &&
- ctx->Color.ColorMask[0][3] == 0) {
+ if (GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 0) == 0 &&
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 1) == 0 &&
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 2) == 0 &&
+ GET_COLORMASK_BIT(ctx->Color.ColorMask, 0, 3) == 0) {
USE(occlusion_zless_16_triangle);
return;
}