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