4 bits per draw buffer, 8 draw buffers in total --> 32 bits.
This is easier to work with.
Reviewed-by: Eric Anholt <eric@anholt.net>
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);
_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 */
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));
}
}
}
_mesa_DrawBuffers(i, enums);
}
-/**
- * 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
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) {
}
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++;
}
GLboolean DitherFlag;
/** MESA_META_COLOR_MASK */
- GLubyte ColorMask[MAX_DRAW_BUFFERS][4];
+ GLbitfield ColorMask;
/** MESA_META_DEPTH_TEST */
struct gl_depthbuffer_attrib Depth;
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;
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;
}
}
/* 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);
}
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;
}
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;
}
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,
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;
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
(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;
}
}
/* _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;
}
}
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);
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;
}
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;
}
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(
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;
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. */
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
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);
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))
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 );
{
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;
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
/* 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)
_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];
}
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));
}
}
{
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 );
_mesa_ColorMaski(GLuint buf, GLboolean red, GLboolean green,
GLboolean blue, GLboolean alpha)
{
- GLubyte tmp[4];
GET_CURRENT_CONTEXT(ctx);
if (MESA_VERBOSE & VERBOSE_API)
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);
}
/* 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;
_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
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;
}
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:
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:
(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
*/
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 */
#include "cso_cache/cso_context.h"
#include "framebuffer.h"
+#include "main/blend.h"
#include "main/macros.h"
/**
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;
}
/**
/* 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;
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)
}
-/**
- * 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.
*/
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;
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);
}
}
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;
}
}
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;
}
* 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;
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;
}
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;
_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;
/* 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;
}
_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);
}
!_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;
}