home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Amiga 5 / MA_Cover_5.iso / ppc / mesa / src / scissor.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-01-31  |  3.1 KB  |  128 lines

  1. /* $Id: scissor.c,v 1.5 1997/07/24 01:21:56 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  2.4
  6.  * Copyright (C) 1995-1997  Brian Paul
  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.5  1997/07/24 01:21:56  brianp
  27.  * changed precompiled header symbol from PCH to PC_HEADER
  28.  *
  29.  * Revision 1.4  1997/05/28 03:26:29  brianp
  30.  * added precompiled header (PCH) support
  31.  *
  32.  * Revision 1.3  1997/05/17 03:17:50  brianp
  33.  * faster gl_scissor_span() from Mats Lofkvist
  34.  *
  35.  * Revision 1.2  1996/09/15 14:18:37  brianp
  36.  * now use GLframebuffer and GLvisual
  37.  *
  38.  * Revision 1.1  1996/09/13 01:38:16  brianp
  39.  * Initial revision
  40.  *
  41.  */
  42.  
  43.  
  44. #ifdef PC_HEADER
  45. #include "all.h"
  46. #else
  47. #include "context.h"
  48. #include "macros.h"
  49. #include "dlist.h"
  50. #include "scissor.h"
  51. #include "types.h"
  52. #endif
  53.  
  54.  
  55. void gl_Scissor( GLcontext *ctx,
  56.          GLint x, GLint y, GLsizei width, GLsizei height )
  57. {
  58.    if (width<0 || height<0) {
  59.       gl_error( ctx, GL_INVALID_VALUE, "glScissor" );
  60.       return;
  61.    }
  62.    if (INSIDE_BEGIN_END(ctx)) {
  63.       gl_error( ctx, GL_INVALID_OPERATION, "glBegin" );
  64.       return;
  65.    }
  66.  
  67.    ctx->NewState |= NEW_ALL;  /* TODO: this is overkill */
  68.    ctx->Scissor.X = x;
  69.    ctx->Scissor.Y = y;
  70.    ctx->Scissor.Width = width;
  71.    ctx->Scissor.Height = height;
  72.  
  73. }
  74.  
  75.  
  76.  
  77. /*
  78.  * Apply the scissor test to a span of pixels.
  79.  * Return:  0 = all pixels in the span are outside the scissor box.
  80.  *          1 = one or more pixels passed the scissor test.
  81.  */
  82. GLint gl_scissor_span( GLcontext *ctx,
  83.                GLuint n, GLint x, GLint y, GLubyte mask[] )
  84. {
  85.    /* first check if whole span is outside the scissor box */
  86.    if (y<ctx->Buffer->Ymin || y>ctx->Buffer->Ymax
  87.        || x>ctx->Buffer->Xmax || x+(GLint)n-1<ctx->Buffer->Xmin) {
  88.       return 0;
  89.    }
  90.    else {
  91.       GLint i;
  92.       GLint xMin = ctx->Buffer->Xmin;
  93.       GLint xMax = ctx->Buffer->Xmax;
  94.       for (i=0; x+i < xMin; i++) {
  95.      mask[i] = 0;
  96.       }
  97.       for (i=(GLint)n-1; x+i > xMax; i--) {
  98.      mask[i] = 0;
  99.       }
  100.  
  101.       return 1;
  102.    }
  103. }
  104.  
  105.  
  106.  
  107.  
  108. /*
  109.  * Apply the scissor test to an array of pixels.
  110.  */
  111. GLuint gl_scissor_pixels( GLcontext *ctx,
  112.               GLuint n, const GLint x[], const GLint y[],
  113.               GLubyte mask[] )
  114. {
  115.    GLint xmin = ctx->Buffer->Xmin;
  116.    GLint xmax = ctx->Buffer->Xmax;
  117.    GLint ymin = ctx->Buffer->Ymin;
  118.    GLint ymax = ctx->Buffer->Ymax;
  119.    GLuint i;
  120.  
  121.    for (i=0;i<n;i++) {
  122.       mask[i] &= (x[i]>=xmin) & (x[i]<=xmax) & (y[i]>=ymin) & (y[i]<=ymax);
  123.    }
  124.  
  125.    return 1;
  126. }
  127.  
  128.