home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / System / Mesa-3.1 / src / scissor.c < prev    next >
C/C++ Source or Header  |  2000-01-07  |  4KB  |  125 lines

  1. /* $Id: scissor.c,v 1.3 1999/11/08 07:36:44 brianp Exp $ */
  2.  
  3. /*
  4.  * Mesa 3-D graphics library
  5.  * Version:  3.1
  6.  * 
  7.  * Copyright (C) 1999  Brian Paul   All Rights Reserved.
  8.  * 
  9.  * Permission is hereby granted, free of charge, to any person obtaining a
  10.  * copy of this software and associated documentation files (the "Software"),
  11.  * to deal in the Software without restriction, including without limitation
  12.  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  13.  * and/or sell copies of the Software, and to permit persons to whom the
  14.  * Software is furnished to do so, subject to the following conditions:
  15.  * 
  16.  * The above copyright notice and this permission notice shall be included
  17.  * in all copies or substantial portions of the Software.
  18.  * 
  19.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  20.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21.  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
  22.  * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  23.  * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24.  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  */
  26. /* $XFree86: xc/lib/GL/mesa/src/scissor.c,v 1.2 1999/04/04 00:20:31 dawes Exp $ */
  27.  
  28.  
  29.  
  30.  
  31.  
  32. #ifdef PC_HEADER
  33. #include "all.h"
  34. #else
  35. #ifndef XFree86Server
  36. #include <stdio.h>
  37. #else
  38. #include "GL/xf86glx.h"
  39. #endif
  40. #include "context.h"
  41. #include "macros.h"
  42. #include "scissor.h"
  43. #include "types.h"
  44. #endif
  45.  
  46.  
  47. void gl_Scissor( GLcontext *ctx,
  48.                  GLint x, GLint y, GLsizei width, GLsizei height )
  49. {
  50.    if (width<0 || height<0) {
  51.       gl_error( ctx, GL_INVALID_VALUE, "glScissor" );
  52.       return;
  53.    }
  54.    ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBegin");
  55.  
  56.    if (MESA_VERBOSE & VERBOSE_API)
  57.       fprintf(stderr, "glScissor %d %d %d %d\n", x, y, width, height);
  58.  
  59.    if (x!=ctx->Scissor.X || y!=ctx->Scissor.Y || 
  60.        width!=ctx->Scissor.Width || height!=ctx->Scissor.Height) {
  61.       ctx->Scissor.X = x;
  62.       ctx->Scissor.Y = y;
  63.       ctx->Scissor.Width = width;
  64.       ctx->Scissor.Height = height;
  65.       ctx->NewState |= NEW_RASTER_OPS;
  66.    }
  67.  
  68.    if (ctx->Driver.Scissor)
  69.       ctx->Driver.Scissor( ctx, x, y, width, height );
  70. }
  71.  
  72.  
  73.  
  74. /*
  75.  * Apply the scissor test to a span of pixels.
  76.  * Return:  0 = all pixels in the span are outside the scissor box.
  77.  *          1 = one or more pixels passed the scissor test.
  78.  */
  79. GLint gl_scissor_span( GLcontext *ctx,
  80.                        GLuint n, GLint x, GLint y, GLubyte mask[] )
  81. {
  82.    /* first check if whole span is outside the scissor box */
  83.    if (y<ctx->Buffer->Ymin || y>ctx->Buffer->Ymax
  84.        || x>ctx->Buffer->Xmax || x+(GLint)n-1<ctx->Buffer->Xmin) {
  85.       return 0;
  86.    }
  87.    else {
  88.       GLint i;
  89.       GLint xMin = ctx->Buffer->Xmin;
  90.       GLint xMax = ctx->Buffer->Xmax;
  91.       for (i=0; x+i < xMin; i++) {
  92.          mask[i] = 0;
  93.       }
  94.       for (i=(GLint)n-1; x+i > xMax; i--) {
  95.          mask[i] = 0;
  96.       }
  97.  
  98.       return 1;
  99.    }
  100. }
  101.  
  102.  
  103.  
  104.  
  105. /*
  106.  * Apply the scissor test to an array of pixels.
  107.  */
  108. GLuint gl_scissor_pixels( GLcontext *ctx,
  109.                           GLuint n, const GLint x[], const GLint y[],
  110.                           GLubyte mask[] )
  111. {
  112.    GLint xmin = ctx->Buffer->Xmin;
  113.    GLint xmax = ctx->Buffer->Xmax;
  114.    GLint ymin = ctx->Buffer->Ymin;
  115.    GLint ymax = ctx->Buffer->Ymax;
  116.    GLuint i;
  117.  
  118.    for (i=0;i<n;i++) {
  119.       mask[i] &= (x[i]>=xmin) & (x[i]<=xmax) & (y[i]>=ymin) & (y[i]<=ymax);
  120.    }
  121.  
  122.    return 1;
  123. }
  124.  
  125.