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

  1. /* alpha.c */
  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.  * Alpha test
  26.  */
  27.  
  28.  
  29. /*
  30. $Id: alpha.c,v 1.7 1995/07/20 15:34:37 brianp Exp $
  31.  
  32. $Log: alpha.c,v $
  33.  * Revision 1.7  1995/07/20  15:34:37  brianp
  34.  * added type casts to stop warnings with Sun's cc
  35.  *
  36.  * Revision 1.6  1995/06/12  15:35:14  brianp
  37.  * changed color arrays to GLubyte
  38.  *
  39.  * Revision 1.5  1995/05/22  21:02:41  brianp
  40.  * Release 1.2
  41.  *
  42.  * Revision 1.4  1995/05/12  19:22:23  brianp
  43.  * added #include "macros.h"
  44.  *
  45.  * Revision 1.3  1995/05/12  19:20:19  brianp
  46.  * replaced CC.Mode!=0 with INSIDE_BEGIN_END
  47.  *
  48.  * Revision 1.2  1995/03/04  19:29:44  brianp
  49.  * 1.1 beta revision
  50.  *
  51.  * Revision 1.1  1995/02/24  14:15:10  brianp
  52.  * Initial revision
  53.  *
  54.  */
  55.  
  56.  
  57. #include "context.h"
  58. #include "list.h"
  59. #include "macros.h"
  60.  
  61.  
  62. void glAlphaFunc( GLenum func, GLclampf ref )
  63. {
  64.    if (CC.CompileFlag) {
  65.       gl_save_alphafunc( func, ref );
  66.    }
  67.    if (CC.ExecuteFlag) {
  68.       if (INSIDE_BEGIN_END) {
  69.      gl_error( GL_INVALID_OPERATION, "glAlphaFunc" );
  70.      return;
  71.       }
  72.       switch (func) {
  73.      case GL_NEVER:
  74.      case GL_LESS:
  75.      case GL_EQUAL:
  76.      case GL_LEQUAL:
  77.      case GL_GREATER:
  78.      case GL_NOTEQUAL:
  79.      case GL_GEQUAL:
  80.      case GL_ALWAYS:
  81.         CC.Color.AlphaFunc = func;
  82.         CC.Color.AlphaRef = CLAMP( ref, 0.0F, 1.0F );
  83.         CC.Color.AlphaRefInt = (GLint) (CC.Color.AlphaRef * CC.AlphaScale);
  84.         break;
  85.      default:
  86.         gl_error( GL_INVALID_ENUM, "glAlphaFunc" );
  87.         break;
  88.       }
  89.    }
  90. }
  91.  
  92.  
  93.  
  94.  
  95. /*
  96.  * Apply the alpha test to a span of pixels.
  97.  * In/Out:  mask - current pixel mask.  Pixels which fail the alpha test
  98.  *                 will set the corresponding mask flag to 0.
  99.  * Return:  0 = all pixels in the span failed the alpha test.
  100.  *          1 = one or more pixels passed the alpha test.
  101.  */
  102. GLint gl_alpha_test( GLuint n, const GLubyte alpha[], GLubyte mask[] )
  103. {
  104.    GLuint i;
  105.  
  106.    /* switch cases ordered from most frequent to less frequent */
  107.    switch (CC.Color.AlphaFunc) {
  108.       case GL_LESS:
  109.          for (i=0;i<n;i++) {
  110.         if ((GLint) alpha[i] >= CC.Color.AlphaRefInt) {
  111.            mask[i] = 0;
  112.         }
  113.      }
  114.      return 1;
  115.       case GL_LEQUAL:
  116.          for (i=0;i<n;i++) {
  117.         if ((GLint) alpha[i] > CC.Color.AlphaRefInt) {
  118.            mask[i] = 0;
  119.         }
  120.      }
  121.      return 1;
  122.       case GL_GEQUAL:
  123.          for (i=0;i<n;i++) {
  124.         if ((GLint) alpha[i] < CC.Color.AlphaRefInt) {
  125.            mask[i] = 0;
  126.         }
  127.      }
  128.      return 1;
  129.       case GL_GREATER:
  130.          for (i=0;i<n;i++) {
  131.         if ((GLint) alpha[i] <= CC.Color.AlphaRefInt) {
  132.            mask[i] = 0;
  133.         }
  134.      }
  135.      return 1;
  136.       case GL_NOTEQUAL:
  137.          for (i=0;i<n;i++) {
  138.         if ((GLint) alpha[i] == CC.Color.AlphaRefInt) {
  139.            mask[i] = 0;
  140.         }
  141.      }
  142.      return 1;
  143.       case GL_EQUAL:
  144.          for (i=0;i<n;i++) {
  145.         if ((GLint) alpha[i] != CC.Color.AlphaRefInt) {
  146.            mask[i] = 0;
  147.         }
  148.      }
  149.      return 1;
  150.       case GL_ALWAYS:
  151.      /* do nothing */
  152.      return 1;
  153.       case GL_NEVER:
  154.      for (i=0;i<n;i++) {
  155.         mask[i] = 0;
  156.      }
  157.      return 0;
  158.       default:
  159.      gl_error( GL_INVALID_ENUM, "Internal error in gl_alpha_test" );
  160.      break;
  161.    }
  162.    return 1;
  163. }
  164.