home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / mesa-1.2.8 / src / masking.c < prev    next >
C/C++ Source or Header  |  1996-05-27  |  4KB  |  165 lines

  1. /* $Id: masking.c,v 1.3 1996/02/19 21:50:00 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  7.  *
  8.  * This library is free software; you can redistribute it and/or
  9.  * modify it under the terms of the GNU Library General Public
  10.  * License as published by the Free Software Foundation; either
  11.  * version 2 of the License, or (at your option) any later version.
  12.  *
  13.  * This library is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16.  * Library General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU Library General Public
  19.  * License along with this library; if not, write to the Free
  20.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23.  
  24. /*
  25. $Log: masking.c,v $
  26.  * Revision 1.3  1996/02/19  21:50:00  brianp
  27.  * added support for software alpha buffering
  28.  *
  29.  * Revision 1.2  1995/10/30  15:33:24  brianp
  30.  * added mask argument to gl_mask_[color|index]_pixels functions
  31.  *
  32.  * Revision 1.1  1995/10/13  22:40:00  brianp
  33.  * Initial revision
  34.  *
  35.  */
  36.  
  37.  
  38. /*
  39.  * Implement the effect of glColorMask and glIndexMask in software.
  40.  */
  41.  
  42.  
  43.  
  44. #include <string.h>
  45. #include "alphabuf.h"
  46. #include "dd.h"
  47. #include "context.h"
  48. #include "macros.h"
  49. #include "masking.h"
  50. #include "pb.h"
  51.  
  52.  
  53.  
  54.  
  55. /*
  56.  * Implement glColorMask for a span of RGBA pixels.
  57.  */
  58. void gl_mask_color_span( GLuint n, GLint x, GLint y,
  59.                          GLubyte red[], GLubyte green[],
  60.                          GLubyte blue[], GLubyte alpha[] )
  61. {
  62.    GLubyte r[MAX_WIDTH], g[MAX_WIDTH], b[MAX_WIDTH], a[MAX_WIDTH];
  63.  
  64.    (*DD.read_color_span)( n, x, y, r, g, b, a );
  65.    if (CC.RasterMask & ALPHABUF_BIT) {
  66.       gl_read_alpha_span( n, x, y, a );
  67.    }
  68.  
  69.    if ((CC.Color.ColorMask & 8) == 0) {
  70.       /* replace source reds with frame buffer reds */
  71.       MEMCPY( red, r, n );
  72.    }
  73.    if ((CC.Color.ColorMask & 4) == 0) {
  74.       /* replace source greens with frame buffer greens */
  75.       MEMCPY( green, g, n );
  76.    }
  77.    if ((CC.Color.ColorMask & 2) == 0) {
  78.       /* replace source blues with frame buffer blues */
  79.       MEMCPY( blue, b, n );
  80.    }
  81.    if ((CC.Color.ColorMask & 1) == 0) {
  82.       /* replace source alphas with frame buffer alphas */
  83.       MEMCPY( alpha, a, n );
  84.    }
  85. }
  86.  
  87.  
  88.  
  89. /*
  90.  * Implement glColorMask for an array of RGBA pixels.
  91.  */
  92. void gl_mask_color_pixels( GLuint n, const GLint x[], const GLint y[],
  93.                            GLubyte red[], GLubyte green[],
  94.                            GLubyte blue[], GLubyte alpha[],
  95.                            const GLubyte mask[] )
  96. {
  97.    GLubyte r[PB_SIZE], g[PB_SIZE], b[PB_SIZE], a[PB_SIZE];
  98.  
  99.    (*DD.read_color_pixels)( n, x, y, r, g, b, a, mask );
  100.    if (CC.RasterMask & ALPHABUF_BIT) {
  101.       gl_read_alpha_pixels( n, x, y, a, mask );
  102.    }
  103.  
  104.    if ((CC.Color.ColorMask & 8) == 0) {
  105.       /* replace source reds with frame buffer reds */
  106.       MEMCPY( red, r, n );
  107.    }
  108.    if ((CC.Color.ColorMask & 4) == 0) {
  109.       /* replace source greens with frame buffer greens */
  110.       MEMCPY( green, g, n );
  111.    }
  112.    if ((CC.Color.ColorMask & 2) == 0) {
  113.       /* replace source blues with frame buffer blues */
  114.       MEMCPY( blue, b, n );
  115.    }
  116.    if ((CC.Color.ColorMask & 1) == 0) {
  117.       /* replace source alphas with frame buffer alphas */
  118.       MEMCPY( alpha, a, n );
  119.    }
  120. }
  121.  
  122.  
  123.  
  124. /*
  125.  * Implement glIndexMask for a span of CI pixels.
  126.  */
  127. void gl_mask_index_span( GLuint n, GLint x, GLint y, GLuint index[] )
  128. {
  129.    GLuint i;
  130.    GLuint fbindexes[MAX_WIDTH];
  131.    GLuint msrc, mdest;
  132.  
  133.    (*DD.read_index_span)( n, x, y, fbindexes );
  134.  
  135.    msrc = CC.Color.IndexMask;
  136.    mdest = ~msrc;
  137.  
  138.    for (i=0;i<n;i++) {
  139.       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
  140.    }
  141. }
  142.  
  143.  
  144.  
  145. /*
  146.  * Implement glIndexMask for an array of CI pixels.
  147.  */
  148. void gl_mask_index_pixels( GLuint n, const GLint x[], const GLint y[],
  149.                            GLuint index[], const GLubyte mask[] )
  150. {
  151.    GLuint i;
  152.    GLuint fbindexes[MAX_WIDTH];
  153.    GLuint msrc, mdest;
  154.  
  155.    (*DD.read_index_pixels)( n, x, y, fbindexes, mask );
  156.  
  157.    msrc = CC.Color.IndexMask;
  158.    mdest = ~msrc;
  159.  
  160.    for (i=0;i<n;i++) {
  161.       index[i] = (index[i] & msrc) | (fbindexes[i] & mdest);
  162.    }
  163. }
  164.  
  165.