| 1 |
/* $Id: scissor.c,v 1.2 2000/10/27 15:21:40 mholst Exp $ */ |
| 2 |
|
| 3 |
/* |
| 4 |
* Mesa 3-D graphics library |
| 5 |
* Version: 2.0 |
| 6 |
* Copyright (C) 1995-1996 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 |
#include "context.h" |
| 24 |
#include "macros.h" |
| 25 |
#include "dlist.h" |
| 26 |
#include "scissor.h" |
| 27 |
#include "types.h" |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
void gl_Scissor( GLcontext *ctx, |
| 32 |
GLint x, GLint y, GLsizei width, GLsizei height ) |
| 33 |
{ |
| 34 |
if (width<0 || height<0) { |
| 35 |
gl_error( ctx, GL_INVALID_VALUE, "glScissor" ); |
| 36 |
return; |
| 37 |
} |
| 38 |
if (INSIDE_BEGIN_END(ctx)) { |
| 39 |
gl_error( ctx, GL_INVALID_OPERATION, "glBegin" ); |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
ctx->Scissor.X = x; |
| 44 |
ctx->Scissor.Y = y; |
| 45 |
ctx->Scissor.Width = width; |
| 46 |
ctx->Scissor.Height = height; |
| 47 |
|
| 48 |
ctx->NewState |= NEW_ALL; /* TODO: this is overkill */ |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
/* |
| 54 |
* Apply the scissor test to a span of pixels. |
| 55 |
* Return: 0 = all pixels in the span are outside the scissor box. |
| 56 |
* 1 = one or more pixels passed the scissor test. |
| 57 |
*/ |
| 58 |
GLint gl_scissor_span( GLcontext *ctx, |
| 59 |
GLuint n, GLint x, GLint y, GLubyte mask[] ) |
| 60 |
{ |
| 61 |
/* first check if whole span is outside the scissor box */ |
| 62 |
if (y<ctx->Buffer->Ymin || y>ctx->Buffer->Ymax |
| 63 |
|| x>ctx->Buffer->Xmax || x+(GLint)n-1<ctx->Buffer->Xmin) { |
| 64 |
return 0; |
| 65 |
} |
| 66 |
else { |
| 67 |
GLuint i; |
| 68 |
/* TODO: this could be better: */ |
| 69 |
for (i=0;i<n;i++,x++) { |
| 70 |
if (x<ctx->Buffer->Xmin || x>ctx->Buffer->Xmax) |
| 71 |
mask[i] = 0; |
| 72 |
} |
| 73 |
return 1; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
/* |
| 81 |
* Apply the scissor test to an array of pixels. |
| 82 |
*/ |
| 83 |
GLuint gl_scissor_pixels( GLcontext *ctx, |
| 84 |
GLuint n, const GLint x[], const GLint y[], |
| 85 |
GLubyte mask[] ) |
| 86 |
{ |
| 87 |
GLint xmin = ctx->Buffer->Xmin; |
| 88 |
GLint xmax = ctx->Buffer->Xmax; |
| 89 |
GLint ymin = ctx->Buffer->Ymin; |
| 90 |
GLint ymax = ctx->Buffer->Ymax; |
| 91 |
GLuint i; |
| 92 |
|
| 93 |
for (i=0;i<n;i++) { |
| 94 |
mask[i] &= (x[i]>=xmin) & (x[i]<=xmax) & (y[i]>=ymin) & (y[i]<=ymax); |
| 95 |
} |
| 96 |
|
| 97 |
return 1; |
| 98 |
} |
| 99 |
|