summaryrefslogtreecommitdiffstats
path: root/src/mesa/swrast/s_masking.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/swrast/s_masking.c')
-rw-r--r--src/mesa/swrast/s_masking.c102
1 files changed, 95 insertions, 7 deletions
diff --git a/src/mesa/swrast/s_masking.c b/src/mesa/swrast/s_masking.c
index b4433b2bc74..968a2b914a9 100644
--- a/src/mesa/swrast/s_masking.c
+++ b/src/mesa/swrast/s_masking.c
@@ -1,10 +1,10 @@
-/* $Id: s_masking.c,v 1.5 2001/03/19 02:25:36 keithw Exp $ */
+/* $Id: s_masking.c,v 1.6 2002/02/02 17:24:11 brianp Exp $ */
/*
* Mesa 3-D graphics library
- * Version: 3.5
+ * Version: 4.1
*
- * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -41,12 +41,65 @@
#include "s_span.h"
+
+void
+_mesa_mask_rgba_span( GLcontext *ctx, const struct sw_span *span,
+ GLchan rgba[][4] )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ GLchan dest[MAX_WIDTH][4];
+#if CHAN_BITS == 8
+ GLuint srcMask = *((GLuint*)ctx->Color.ColorMask);
+ GLuint dstMask = ~srcMask;
+ GLuint *rgba32 = (GLuint *) rgba;
+ GLuint *dest32 = (GLuint *) dest;
+#else
+ const GLboolean rMask = ctx->Color.ColorMask[RCOMP];
+ const GLboolean gMask = ctx->Color.ColorMask[GCOMP];
+ const GLboolean bMask = ctx->Color.ColorMask[BCOMP];
+ const GLboolean aMask = ctx->Color.ColorMask[ACOMP];
+#endif
+ const GLuint n = span->end;
+ GLuint i;
+
+ ASSERT(n < MAX_WIDTH);
+ ASSERT(span->arrayMask & SPAN_RGBA);
+
+ if (span->arrayMask & SPAN_XY) {
+ (*swrast->Driver.ReadRGBAPixels)(ctx, n, span->xArray, span->yArray,
+ dest, span->mask);
+ if (SWRAST_CONTEXT(ctx)->_RasterMask & ALPHABUF_BIT) {
+ _mesa_read_alpha_pixels(ctx, n, span->xArray, span->yArray,
+ dest, span->mask );
+ }
+ }
+ else {
+ _mesa_read_rgba_span(ctx, ctx->DrawBuffer, n, span->x, span->y, dest);
+ }
+
+#if CHAN_BITS == 8
+ for (i = 0; i < n; i++) {
+ rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
+ }
+#else
+ for (i = 0; i < n; i++) {
+ if (!rMask) rgba[i][RCOMP] = dest[i][RCOMP];
+ if (!gMask) rgba[i][GCOMP] = dest[i][GCOMP];
+ if (!bMask) rgba[i][BCOMP] = dest[i][BCOMP];
+ if (!aMask) rgba[i][ACOMP] = dest[i][ACOMP];
+ }
+#endif
+}
+
+
+
+
/*
* Apply glColorMask to a span of RGBA pixels.
*/
void
-_mesa_mask_rgba_span( GLcontext *ctx,
- GLuint n, GLint x, GLint y, GLchan rgba[][4] )
+_mesa_mask_rgba_array( GLcontext *ctx,
+ GLuint n, GLint x, GLint y, GLchan rgba[][4] )
{
GLchan dest[MAX_WIDTH][4];
GLuint i;
@@ -135,12 +188,46 @@ _mesa_mask_rgba_pixels( GLcontext *ctx,
+void
+_mesa_mask_index_span( GLcontext *ctx, const struct sw_span *span,
+ GLuint index[] )
+{
+ SWcontext *swrast = SWRAST_CONTEXT(ctx);
+ const GLuint msrc = ctx->Color.IndexMask;
+ const GLuint mdest = ~msrc;
+ GLuint fbindexes[MAX_WIDTH];
+ GLuint i;
+
+ ASSERT(span->arrayMask & SPAN_INDEX);
+ ASSERT(span->end < MAX_WIDTH);
+
+ if (span->arrayMask & SPAN_XY) {
+
+ (*swrast->Driver.ReadCI32Pixels)(ctx, span->end, span->xArray,
+ span->yArray, fbindexes, span->mask);
+
+ for (i = 0; i < span->end; i++) {
+ index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
+ }
+ }
+ else {
+ _mesa_read_index_span(ctx, ctx->DrawBuffer, span->end, span->x, span->y,
+ fbindexes );
+
+ for (i = 0; i < span->end; i++) {
+ index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
+ }
+ }
+}
+
+
+
/*
* Apply glIndexMask to a span of CI pixels.
*/
void
-_mesa_mask_index_span( GLcontext *ctx,
- GLuint n, GLint x, GLint y, GLuint index[] )
+_mesa_mask_index_array( GLcontext *ctx,
+ GLuint n, GLint x, GLint y, GLuint index[] )
{
GLuint i;
GLuint fbindexes[MAX_WIDTH];
@@ -180,3 +267,4 @@ _mesa_mask_index_pixels( GLcontext *ctx,
index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
}
}
+