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

  1. /* $Id: scissor.c,v 1.8 1996/05/08 16:49:37 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  1.2
  6.  * Copyright (C) 1995-1996  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: scissor.c,v $
  26.  * Revision 1.8  1996/05/08  16:49:37  brianp
  27.  * optimized gl_scissor_pixels()
  28.  *
  29.  * Revision 1.7  1995/08/31  21:25:34  brianp
  30.  * added a (GLint) type cast to gl_scissor_span() to fix a bug
  31.  *
  32.  * Revision 1.6  1995/08/31  18:34:16  brianp
  33.  * added display list / glScissor support
  34.  *
  35.  * Revision 1.5  1995/05/22  21:02:41  brianp
  36.  * Release 1.2
  37.  *
  38.  * Revision 1.4  1995/05/12  16:57:22  brianp
  39.  * replaced CC.Mode!=0 with INSIDE_BEGIN_END
  40.  *
  41.  * Revision 1.3  1995/03/04  19:29:44  brianp
  42.  * 1.1 beta revision
  43.  *
  44.  * Revision 1.2  1995/02/27  22:49:05  brianp
  45.  * modified for PB
  46.  *
  47.  * Revision 1.1  1995/02/24  14:27:12  brianp
  48.  * Initial revision
  49.  *
  50.  */
  51.  
  52.  
  53. /*
  54.  * Scissor test.
  55.  */
  56.  
  57.  
  58. #include "context.h"
  59. #include "macros.h"
  60. #include "list.h"
  61.  
  62.  
  63.  
  64.  
  65. void glScissor( GLint x, GLint y, GLsizei width, GLsizei height )
  66. {
  67.    if (CC.CompileFlag) {
  68.       gl_save_scissor( x, y, width, height );
  69.    }
  70.    if (CC.ExecuteFlag) {
  71.       if (width<0 || height<0) {
  72.          gl_error( GL_INVALID_VALUE, "glScissor" );
  73.          return;
  74.       }
  75.       if (INSIDE_BEGIN_END) {
  76.          gl_error( GL_INVALID_OPERATION, "glBegin" );
  77.          return;
  78.       }
  79.  
  80.       CC.Scissor.X = x;
  81.       CC.Scissor.Y = y;
  82.       CC.Scissor.Width = width;
  83.       CC.Scissor.Height = height;
  84.  
  85.       /* in device window coords: */
  86.       CC.Scissor.Xmin = x;
  87.       CC.Scissor.Xmax = x+width-1;
  88.       CC.Scissor.Ymin = y;
  89.       CC.Scissor.Ymax = y+height-1;
  90.    }
  91. }
  92.  
  93.  
  94.  
  95. /*
  96.  * Apply the scissor test to a span of pixels.
  97.  * Return:  0 = all pixels in the span are outside the scissor box.
  98.  *          1 = one or more pixels passed the scissor test.
  99.  */
  100. GLint gl_scissor_span( GLuint n, GLint x, GLint y, GLubyte mask[] )
  101. {
  102.    /* first check if whole span is outside the scissor box */
  103.    if (y<CC.Scissor.Ymin || y>CC.Scissor.Ymax
  104.        || x>CC.Scissor.Xmax || x+(GLint)n-1<CC.Scissor.Xmin) {
  105.       return 0;
  106.    }
  107.    else {
  108.       GLuint i;
  109.       /* TODO: this could be better: */
  110.       for (i=0;i<n;i++,x++) {
  111.      if (x<CC.Scissor.Xmin || x>CC.Scissor.Xmax)
  112.        mask[i] = 0;
  113.       }
  114.       return 1;
  115.    }
  116. }
  117.  
  118.  
  119.  
  120.  
  121. /*
  122.  * Apply the scissor test to an array of pixels.
  123.  */
  124. GLuint gl_scissor_pixels( GLuint n, const GLint x[], const GLint y[],
  125.                           GLubyte mask[] )
  126. {
  127.    GLint xmin = CC.Scissor.Xmin;
  128.    GLint xmax = CC.Scissor.Xmax;
  129.    GLint ymin = CC.Scissor.Ymin;
  130.    GLint ymax = CC.Scissor.Ymax;
  131.    GLuint i;
  132.  
  133.    for (i=0;i<n;i++) {
  134.       mask[i] &= (x[i]>=xmin) & (x[i]<=xmax) & (y[i]>=ymin) & (y[i]<=ymax);
  135.    }
  136.  
  137.    return 1;
  138. }
  139.  
  140.