added GL_X_RENDERABLE to glXChooseFBConfig (bug 4181)
[mesa.git] / src / mesa / swrast / s_masking.c
index 00995cf997af5d940056504cf239a1eb061f6961..391dfde7a190f31eedb9ad0497a77b5842fa2eb7 100644 (file)
@@ -1,10 +1,8 @@
-/* $Id: s_masking.c,v 1.7 2002/02/02 21:40:33 brianp Exp $ */
-
 /*
  * Mesa 3-D graphics library
- * Version:  4.1
+ * Version:  6.3
  *
- * Copyright (C) 1999-2002  Brian Paul   All Rights Reserved.
+ * Copyright (C) 1999-2005  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"),
@@ -34,7 +32,6 @@
 #include "enums.h"
 #include "macros.h"
 
-#include "s_alphabuf.h"
 #include "s_context.h"
 #include "s_masking.h"
 #include "s_span.h"
 
 
 void
-_mesa_mask_rgba_span( GLcontext *ctx, const struct sw_span *span,
-                     GLchan rgba[][4] )
+_swrast_mask_rgba_span(GLcontext *ctx, struct gl_renderbuffer *rb,
+                       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);
@@ -65,15 +61,10 @@ _mesa_mask_rgba_span( GLcontext *ctx, const struct sw_span *span,
    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 );
-      }
+      rb->GetValues(ctx, rb, n, span->array->x, span->array->y, dest);
    }
    else {
-      _mesa_read_rgba_span(ctx, ctx->DrawBuffer, n, span->x, span->y, dest);
+      _swrast_read_rgba_span(ctx, rb, n, span->x, span->y, dest);
    }
 
 #if CHAN_BITS == 8
@@ -91,14 +82,12 @@ _mesa_mask_rgba_span( GLcontext *ctx, const struct sw_span *span,
 }
 
 
-
-
 /*
  * Apply glColorMask to a span of RGBA pixels.
  */
 void
-_mesa_mask_rgba_array( GLcontext *ctx,
-                       GLuint n, GLint x, GLint y, GLchan rgba[][4] )
+_swrast_mask_rgba_array(GLcontext *ctx, struct gl_renderbuffer *rb,
+                        GLuint n, GLint x, GLint y, GLchan rgba[][4])
 {
    GLchan dest[MAX_WIDTH][4];
    GLuint i;
@@ -110,7 +99,7 @@ _mesa_mask_rgba_array( GLcontext *ctx,
    GLuint *rgba32 = (GLuint *) rgba;
    GLuint *dest32 = (GLuint *) dest;
 
-   _mesa_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
+   _swrast_read_rgba_span( ctx, rb, n, x, y, dest );
    for (i = 0; i < n; i++) {
       rgba32[i] = (rgba32[i] & srcMask) | (dest32[i] & dstMask);
    }
@@ -122,7 +111,7 @@ _mesa_mask_rgba_array( GLcontext *ctx,
    const GLint bMask = ctx->Color.ColorMask[BCOMP];
    const GLint aMask = ctx->Color.ColorMask[ACOMP];
 
-   _mesa_read_rgba_span( ctx, ctx->DrawBuffer, n, x, y, dest );
+   _swrast_read_rgba_span( ctx, rb, n, x, y, dest );
    for (i = 0; i < n; i++) {
       if (!rMask)  rgba[i][RCOMP] = dest[i][RCOMP];
       if (!gMask)  rgba[i][GCOMP] = dest[i][GCOMP];
@@ -136,56 +125,46 @@ _mesa_mask_rgba_array( GLcontext *ctx,
 
 
 void
-_mesa_mask_index_span( GLcontext *ctx, const struct sw_span *span,
-                       GLuint index[] )
+_swrast_mask_ci_span(GLcontext *ctx, struct gl_renderbuffer *rb,
+                     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];
+   const GLuint srcMask = ctx->Color.IndexMask;
+   const GLuint dstMask = ~srcMask;
+   GLuint dest[MAX_WIDTH];
    GLuint i;
 
    ASSERT(span->arrayMask & SPAN_INDEX);
    ASSERT(span->end < MAX_WIDTH);
+   ASSERT(rb->DataType == GL_UNSIGNED_INT);
 
    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);
-      }
+      rb->GetValues(ctx, rb, span->end, span->array->x, span->array->y, dest);
    }
    else {
-      _mesa_read_index_span(ctx, ctx->DrawBuffer, span->end, span->x, span->y,
-                            fbindexes );
+      _swrast_read_index_span(ctx, rb, span->end, span->x, span->y, dest);
+   }
 
-      for (i = 0; i < span->end; i++) {
-         index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
-      }
+   for (i = 0; i < span->end; i++) {
+      index[i] = (index[i] & srcMask) | (dest[i] & dstMask);
    }
 }
 
 
-
 /*
- * Apply glIndexMask to a span of CI pixels.
+ * Apply glIndexMask to an array of CI pixels.
  */
 void
-_mesa_mask_index_array( GLcontext *ctx,
-                        GLuint n, GLint x, GLint y, GLuint index[] )
+_swrast_mask_ci_array(GLcontext *ctx, struct gl_renderbuffer *rb,
+                      GLuint n, GLint x, GLint y, GLuint index[])
 {
+   const GLuint srcMask = ctx->Color.IndexMask;
+   const GLuint dstMask = ~srcMask;
+   GLuint dest[MAX_WIDTH];
    GLuint i;
-   GLuint fbindexes[MAX_WIDTH];
-   GLuint msrc, mdest;
-
-   _mesa_read_index_span( ctx, ctx->DrawBuffer, n, x, y, fbindexes );
 
-   msrc = ctx->Color.IndexMask;
-   mdest = ~msrc;
+   _swrast_read_index_span(ctx, rb, n, x, y, dest);
 
    for (i=0;i<n;i++) {
-      index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
+      index[i] = (index[i] & srcMask) | (dest[i] & dstMask);
    }
 }