source: trunk/src/opengl/mesa/scissor.c

Last change on this file was 3598, checked in by jeroen, 25 years ago

* empty log message *

File size: 3.5 KB
Line 
1/* $Id: scissor.c,v 1.3 2000-05-23 20:40:53 jeroen Exp $ */
2
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.3
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#include "glheader.h"
36#include "types.h"
37#include "context.h"
38#include "macros.h"
39#include "scissor.h"
40#endif
41
42
43void
44_mesa_Scissor( GLint x, GLint y, GLsizei width, GLsizei height )
45{
46 GET_CURRENT_CONTEXT(ctx);
47 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glScissor");
48
49 if (width < 0 || height < 0) {
50 gl_error( ctx, GL_INVALID_VALUE, "glScissor" );
51 return;
52 }
53
54 if (MESA_VERBOSE & VERBOSE_API)
55 fprintf(stderr, "glScissor %d %d %d %d\n", x, y, width, height);
56
57 if (x != ctx->Scissor.X ||
58 y != ctx->Scissor.Y ||
59 width != ctx->Scissor.Width ||
60 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 */
79GLint 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->DrawBuffer->Ymin
84 || y > ctx->DrawBuffer->Ymax
85 || x > ctx->DrawBuffer->Xmax
86 || x + (GLint) n - 1 < ctx->DrawBuffer->Xmin) {
87 return 0;
88 }
89 else {
90 const GLint xMin = ctx->DrawBuffer->Xmin;
91 const GLint xMax = ctx->DrawBuffer->Xmax;
92 GLint i;
93 for (i = 0; x + i < xMin; i++) {
94 mask[i] = 0;
95 }
96 for (i = (GLint) n - 1; x + i > xMax; i--) {
97 mask[i] = 0;
98 }
99
100 return 1;
101 }
102}
103
104
105
106
107/*
108 * Apply the scissor test to an array of pixels.
109 */
110GLuint gl_scissor_pixels( GLcontext *ctx,
111 GLuint n, const GLint x[], const GLint y[],
112 GLubyte mask[] )
113{
114 const GLint xmin = ctx->DrawBuffer->Xmin;
115 const GLint xmax = ctx->DrawBuffer->Xmax;
116 const GLint ymin = ctx->DrawBuffer->Ymin;
117 const GLint ymax = ctx->DrawBuffer->Ymax;
118 GLuint i;
119
120 for (i=0;i<n;i++) {
121 mask[i] &= (x[i]>=xmin) & (x[i]<=xmax) & (y[i]>=ymin) & (y[i]<=ymax);
122 }
123
124 return 1;
125}
126
Note: See TracBrowser for help on using the repository browser.