xref: /aosp_15_r20/external/mesa3d/src/mesa/main/scissor.c (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1*61046927SAndroid Build Coastguard Worker /*
2*61046927SAndroid Build Coastguard Worker  * Mesa 3-D graphics library
3*61046927SAndroid Build Coastguard Worker  *
4*61046927SAndroid Build Coastguard Worker  * Copyright (C) 1999-2007  Brian Paul   All Rights Reserved.
5*61046927SAndroid Build Coastguard Worker  *
6*61046927SAndroid Build Coastguard Worker  * Permission is hereby granted, free of charge, to any person obtaining a
7*61046927SAndroid Build Coastguard Worker  * copy of this software and associated documentation files (the "Software"),
8*61046927SAndroid Build Coastguard Worker  * to deal in the Software without restriction, including without limitation
9*61046927SAndroid Build Coastguard Worker  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10*61046927SAndroid Build Coastguard Worker  * and/or sell copies of the Software, and to permit persons to whom the
11*61046927SAndroid Build Coastguard Worker  * Software is furnished to do so, subject to the following conditions:
12*61046927SAndroid Build Coastguard Worker  *
13*61046927SAndroid Build Coastguard Worker  * The above copyright notice and this permission notice shall be included
14*61046927SAndroid Build Coastguard Worker  * in all copies or substantial portions of the Software.
15*61046927SAndroid Build Coastguard Worker  *
16*61046927SAndroid Build Coastguard Worker  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17*61046927SAndroid Build Coastguard Worker  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18*61046927SAndroid Build Coastguard Worker  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19*61046927SAndroid Build Coastguard Worker  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20*61046927SAndroid Build Coastguard Worker  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21*61046927SAndroid Build Coastguard Worker  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22*61046927SAndroid Build Coastguard Worker  * OTHER DEALINGS IN THE SOFTWARE.
23*61046927SAndroid Build Coastguard Worker  */
24*61046927SAndroid Build Coastguard Worker 
25*61046927SAndroid Build Coastguard Worker 
26*61046927SAndroid Build Coastguard Worker #include "util/glheader.h"
27*61046927SAndroid Build Coastguard Worker #include "main/context.h"
28*61046927SAndroid Build Coastguard Worker #include "main/enums.h"
29*61046927SAndroid Build Coastguard Worker #include "main/mtypes.h"
30*61046927SAndroid Build Coastguard Worker #include "main/scissor.h"
31*61046927SAndroid Build Coastguard Worker #include "api_exec_decl.h"
32*61046927SAndroid Build Coastguard Worker 
33*61046927SAndroid Build Coastguard Worker #include "state_tracker/st_cb_bitmap.h"
34*61046927SAndroid Build Coastguard Worker #include "state_tracker/st_context.h"
35*61046927SAndroid Build Coastguard Worker 
36*61046927SAndroid Build Coastguard Worker /**
37*61046927SAndroid Build Coastguard Worker  * Set scissor rectangle data directly in ScissorArray
38*61046927SAndroid Build Coastguard Worker  *
39*61046927SAndroid Build Coastguard Worker  * This is an internal function that performs no error checking on the
40*61046927SAndroid Build Coastguard Worker  * supplied data.  It also does \b not call \c dd_function_table::Scissor.
41*61046927SAndroid Build Coastguard Worker  *
42*61046927SAndroid Build Coastguard Worker  * \sa _mesa_set_scissor
43*61046927SAndroid Build Coastguard Worker  */
44*61046927SAndroid Build Coastguard Worker static void
set_scissor_no_notify(struct gl_context * ctx,unsigned idx,GLint x,GLint y,GLsizei width,GLsizei height)45*61046927SAndroid Build Coastguard Worker set_scissor_no_notify(struct gl_context *ctx, unsigned idx,
46*61046927SAndroid Build Coastguard Worker                       GLint x, GLint y, GLsizei width, GLsizei height)
47*61046927SAndroid Build Coastguard Worker {
48*61046927SAndroid Build Coastguard Worker    if (x == ctx->Scissor.ScissorArray[idx].X &&
49*61046927SAndroid Build Coastguard Worker        y == ctx->Scissor.ScissorArray[idx].Y &&
50*61046927SAndroid Build Coastguard Worker        width == ctx->Scissor.ScissorArray[idx].Width &&
51*61046927SAndroid Build Coastguard Worker        height == ctx->Scissor.ScissorArray[idx].Height)
52*61046927SAndroid Build Coastguard Worker       return;
53*61046927SAndroid Build Coastguard Worker 
54*61046927SAndroid Build Coastguard Worker    FLUSH_VERTICES(ctx, 0, GL_SCISSOR_BIT);
55*61046927SAndroid Build Coastguard Worker    ctx->NewDriverState |= ST_NEW_SCISSOR;
56*61046927SAndroid Build Coastguard Worker 
57*61046927SAndroid Build Coastguard Worker    ctx->Scissor.ScissorArray[idx].X = x;
58*61046927SAndroid Build Coastguard Worker    ctx->Scissor.ScissorArray[idx].Y = y;
59*61046927SAndroid Build Coastguard Worker    ctx->Scissor.ScissorArray[idx].Width = width;
60*61046927SAndroid Build Coastguard Worker    ctx->Scissor.ScissorArray[idx].Height = height;
61*61046927SAndroid Build Coastguard Worker }
62*61046927SAndroid Build Coastguard Worker 
63*61046927SAndroid Build Coastguard Worker static void
scissor(struct gl_context * ctx,GLint x,GLint y,GLsizei width,GLsizei height)64*61046927SAndroid Build Coastguard Worker scissor(struct gl_context *ctx, GLint x, GLint y, GLsizei width, GLsizei height)
65*61046927SAndroid Build Coastguard Worker {
66*61046927SAndroid Build Coastguard Worker    unsigned i;
67*61046927SAndroid Build Coastguard Worker 
68*61046927SAndroid Build Coastguard Worker    /* The GL_ARB_viewport_array spec says:
69*61046927SAndroid Build Coastguard Worker     *
70*61046927SAndroid Build Coastguard Worker     *     "Scissor sets the scissor rectangle for all viewports to the same
71*61046927SAndroid Build Coastguard Worker     *     values and is equivalent (assuming no errors are generated) to:
72*61046927SAndroid Build Coastguard Worker     *
73*61046927SAndroid Build Coastguard Worker     *     for (uint i = 0; i < MAX_VIEWPORTS; i++) {
74*61046927SAndroid Build Coastguard Worker     *         ScissorIndexed(i, left, bottom, width, height);
75*61046927SAndroid Build Coastguard Worker     *     }"
76*61046927SAndroid Build Coastguard Worker     *
77*61046927SAndroid Build Coastguard Worker     * Set the scissor rectangle for all of the viewports supported by the
78*61046927SAndroid Build Coastguard Worker     * implementation, but only signal the driver once at the end.
79*61046927SAndroid Build Coastguard Worker     */
80*61046927SAndroid Build Coastguard Worker    for (i = 0; i < ctx->Const.MaxViewports; i++)
81*61046927SAndroid Build Coastguard Worker       set_scissor_no_notify(ctx, i, x, y, width, height);
82*61046927SAndroid Build Coastguard Worker }
83*61046927SAndroid Build Coastguard Worker 
84*61046927SAndroid Build Coastguard Worker /**
85*61046927SAndroid Build Coastguard Worker  * Called via glScissor
86*61046927SAndroid Build Coastguard Worker  */
87*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_Scissor_no_error(GLint x,GLint y,GLsizei width,GLsizei height)88*61046927SAndroid Build Coastguard Worker _mesa_Scissor_no_error(GLint x, GLint y, GLsizei width, GLsizei height)
89*61046927SAndroid Build Coastguard Worker {
90*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
91*61046927SAndroid Build Coastguard Worker    scissor(ctx, x, y, width, height);
92*61046927SAndroid Build Coastguard Worker }
93*61046927SAndroid Build Coastguard Worker 
94*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_Scissor(GLint x,GLint y,GLsizei width,GLsizei height)95*61046927SAndroid Build Coastguard Worker _mesa_Scissor(GLint x, GLint y, GLsizei width, GLsizei height)
96*61046927SAndroid Build Coastguard Worker {
97*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
98*61046927SAndroid Build Coastguard Worker 
99*61046927SAndroid Build Coastguard Worker    if (MESA_VERBOSE & VERBOSE_API)
100*61046927SAndroid Build Coastguard Worker       _mesa_debug(ctx, "glScissor %d %d %d %d\n", x, y, width, height);
101*61046927SAndroid Build Coastguard Worker 
102*61046927SAndroid Build Coastguard Worker    if (width < 0 || height < 0) {
103*61046927SAndroid Build Coastguard Worker       _mesa_error( ctx, GL_INVALID_VALUE, "glScissor" );
104*61046927SAndroid Build Coastguard Worker       return;
105*61046927SAndroid Build Coastguard Worker    }
106*61046927SAndroid Build Coastguard Worker 
107*61046927SAndroid Build Coastguard Worker    scissor(ctx, x, y, width, height);
108*61046927SAndroid Build Coastguard Worker }
109*61046927SAndroid Build Coastguard Worker 
110*61046927SAndroid Build Coastguard Worker 
111*61046927SAndroid Build Coastguard Worker /**
112*61046927SAndroid Build Coastguard Worker  * Define the scissor box.
113*61046927SAndroid Build Coastguard Worker  *
114*61046927SAndroid Build Coastguard Worker  * \param x, y coordinates of the scissor box lower-left corner.
115*61046927SAndroid Build Coastguard Worker  * \param width width of the scissor box.
116*61046927SAndroid Build Coastguard Worker  * \param height height of the scissor box.
117*61046927SAndroid Build Coastguard Worker  *
118*61046927SAndroid Build Coastguard Worker  * \sa glScissor().
119*61046927SAndroid Build Coastguard Worker  *
120*61046927SAndroid Build Coastguard Worker  * Verifies the parameters and updates __struct gl_contextRec::Scissor. On a
121*61046927SAndroid Build Coastguard Worker  * change flushes the vertices and notifies the driver via
122*61046927SAndroid Build Coastguard Worker  * the dd_function_table::Scissor callback.
123*61046927SAndroid Build Coastguard Worker  */
124*61046927SAndroid Build Coastguard Worker void
_mesa_set_scissor(struct gl_context * ctx,unsigned idx,GLint x,GLint y,GLsizei width,GLsizei height)125*61046927SAndroid Build Coastguard Worker _mesa_set_scissor(struct gl_context *ctx, unsigned idx,
126*61046927SAndroid Build Coastguard Worker                   GLint x, GLint y, GLsizei width, GLsizei height)
127*61046927SAndroid Build Coastguard Worker {
128*61046927SAndroid Build Coastguard Worker    set_scissor_no_notify(ctx, idx, x, y, width, height);
129*61046927SAndroid Build Coastguard Worker }
130*61046927SAndroid Build Coastguard Worker 
131*61046927SAndroid Build Coastguard Worker static void
scissor_array(struct gl_context * ctx,GLuint first,GLsizei count,struct gl_scissor_rect * rect)132*61046927SAndroid Build Coastguard Worker scissor_array(struct gl_context *ctx, GLuint first, GLsizei count,
133*61046927SAndroid Build Coastguard Worker               struct gl_scissor_rect *rect)
134*61046927SAndroid Build Coastguard Worker {
135*61046927SAndroid Build Coastguard Worker    for (GLsizei i = 0; i < count; i++) {
136*61046927SAndroid Build Coastguard Worker       set_scissor_no_notify(ctx, i + first, rect[i].X, rect[i].Y,
137*61046927SAndroid Build Coastguard Worker                             rect[i].Width, rect[i].Height);
138*61046927SAndroid Build Coastguard Worker    }
139*61046927SAndroid Build Coastguard Worker }
140*61046927SAndroid Build Coastguard Worker 
141*61046927SAndroid Build Coastguard Worker /**
142*61046927SAndroid Build Coastguard Worker  * Define count scissor boxes starting at index.
143*61046927SAndroid Build Coastguard Worker  *
144*61046927SAndroid Build Coastguard Worker  * \param index  index of first scissor records to set
145*61046927SAndroid Build Coastguard Worker  * \param count  number of scissor records to set
146*61046927SAndroid Build Coastguard Worker  * \param x, y   pointer to array of struct gl_scissor_rects
147*61046927SAndroid Build Coastguard Worker  *
148*61046927SAndroid Build Coastguard Worker  * \sa glScissorArrayv().
149*61046927SAndroid Build Coastguard Worker  *
150*61046927SAndroid Build Coastguard Worker  * Verifies the parameters and call set_scissor_no_notify to do the work.
151*61046927SAndroid Build Coastguard Worker  */
152*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ScissorArrayv_no_error(GLuint first,GLsizei count,const GLint * v)153*61046927SAndroid Build Coastguard Worker _mesa_ScissorArrayv_no_error(GLuint first, GLsizei count, const GLint *v)
154*61046927SAndroid Build Coastguard Worker {
155*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
156*61046927SAndroid Build Coastguard Worker 
157*61046927SAndroid Build Coastguard Worker    struct gl_scissor_rect *p = (struct gl_scissor_rect *)v;
158*61046927SAndroid Build Coastguard Worker    scissor_array(ctx, first, count, p);
159*61046927SAndroid Build Coastguard Worker }
160*61046927SAndroid Build Coastguard Worker 
161*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ScissorArrayv(GLuint first,GLsizei count,const GLint * v)162*61046927SAndroid Build Coastguard Worker _mesa_ScissorArrayv(GLuint first, GLsizei count, const GLint *v)
163*61046927SAndroid Build Coastguard Worker {
164*61046927SAndroid Build Coastguard Worker    int i;
165*61046927SAndroid Build Coastguard Worker    struct gl_scissor_rect *p = (struct gl_scissor_rect *) v;
166*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
167*61046927SAndroid Build Coastguard Worker 
168*61046927SAndroid Build Coastguard Worker    if ((first + count) > ctx->Const.MaxViewports) {
169*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE,
170*61046927SAndroid Build Coastguard Worker                   "glScissorArrayv: first (%d) + count (%d) >= MaxViewports (%d)",
171*61046927SAndroid Build Coastguard Worker                   first, count, ctx->Const.MaxViewports);
172*61046927SAndroid Build Coastguard Worker       return;
173*61046927SAndroid Build Coastguard Worker    }
174*61046927SAndroid Build Coastguard Worker 
175*61046927SAndroid Build Coastguard Worker    /* Verify width & height */
176*61046927SAndroid Build Coastguard Worker    for (i = 0; i < count; i++) {
177*61046927SAndroid Build Coastguard Worker       if (p[i].Width < 0 || p[i].Height < 0) {
178*61046927SAndroid Build Coastguard Worker          _mesa_error(ctx, GL_INVALID_VALUE,
179*61046927SAndroid Build Coastguard Worker                      "glScissorArrayv: index (%d) width or height < 0 (%d, %d)",
180*61046927SAndroid Build Coastguard Worker                      i, p[i].Width, p[i].Height);
181*61046927SAndroid Build Coastguard Worker          return;
182*61046927SAndroid Build Coastguard Worker       }
183*61046927SAndroid Build Coastguard Worker    }
184*61046927SAndroid Build Coastguard Worker 
185*61046927SAndroid Build Coastguard Worker    scissor_array(ctx, first, count, p);
186*61046927SAndroid Build Coastguard Worker }
187*61046927SAndroid Build Coastguard Worker 
188*61046927SAndroid Build Coastguard Worker /**
189*61046927SAndroid Build Coastguard Worker  * Define the scissor box.
190*61046927SAndroid Build Coastguard Worker  *
191*61046927SAndroid Build Coastguard Worker  * \param index  index of scissor records to set
192*61046927SAndroid Build Coastguard Worker  * \param x, y   coordinates of the scissor box lower-left corner.
193*61046927SAndroid Build Coastguard Worker  * \param width  width of the scissor box.
194*61046927SAndroid Build Coastguard Worker  * \param height height of the scissor box.
195*61046927SAndroid Build Coastguard Worker  *
196*61046927SAndroid Build Coastguard Worker  * Verifies the parameters call set_scissor_no_notify to do the work.
197*61046927SAndroid Build Coastguard Worker  */
198*61046927SAndroid Build Coastguard Worker static void
scissor_indexed_err(struct gl_context * ctx,GLuint index,GLint left,GLint bottom,GLsizei width,GLsizei height,const char * function)199*61046927SAndroid Build Coastguard Worker scissor_indexed_err(struct gl_context *ctx, GLuint index, GLint left,
200*61046927SAndroid Build Coastguard Worker                     GLint bottom, GLsizei width, GLsizei height,
201*61046927SAndroid Build Coastguard Worker                     const char *function)
202*61046927SAndroid Build Coastguard Worker {
203*61046927SAndroid Build Coastguard Worker    if (MESA_VERBOSE & VERBOSE_API)
204*61046927SAndroid Build Coastguard Worker       _mesa_debug(ctx, "%s(%d, %d, %d, %d, %d)\n",
205*61046927SAndroid Build Coastguard Worker                   function, index, left, bottom, width, height);
206*61046927SAndroid Build Coastguard Worker 
207*61046927SAndroid Build Coastguard Worker    if (index >= ctx->Const.MaxViewports) {
208*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE,
209*61046927SAndroid Build Coastguard Worker                   "%s: index (%d) >= MaxViewports (%d)",
210*61046927SAndroid Build Coastguard Worker                   function, index, ctx->Const.MaxViewports);
211*61046927SAndroid Build Coastguard Worker       return;
212*61046927SAndroid Build Coastguard Worker    }
213*61046927SAndroid Build Coastguard Worker 
214*61046927SAndroid Build Coastguard Worker    if (width < 0 || height < 0) {
215*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE,
216*61046927SAndroid Build Coastguard Worker                   "%s: index (%d) width or height < 0 (%d, %d)",
217*61046927SAndroid Build Coastguard Worker                   function, index, width, height);
218*61046927SAndroid Build Coastguard Worker       return;
219*61046927SAndroid Build Coastguard Worker    }
220*61046927SAndroid Build Coastguard Worker 
221*61046927SAndroid Build Coastguard Worker    _mesa_set_scissor(ctx, index, left, bottom, width, height);
222*61046927SAndroid Build Coastguard Worker }
223*61046927SAndroid Build Coastguard Worker 
224*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ScissorIndexed_no_error(GLuint index,GLint left,GLint bottom,GLsizei width,GLsizei height)225*61046927SAndroid Build Coastguard Worker _mesa_ScissorIndexed_no_error(GLuint index, GLint left, GLint bottom,
226*61046927SAndroid Build Coastguard Worker                               GLsizei width, GLsizei height)
227*61046927SAndroid Build Coastguard Worker {
228*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
229*61046927SAndroid Build Coastguard Worker    _mesa_set_scissor(ctx, index, left, bottom, width, height);
230*61046927SAndroid Build Coastguard Worker }
231*61046927SAndroid Build Coastguard Worker 
232*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ScissorIndexed(GLuint index,GLint left,GLint bottom,GLsizei width,GLsizei height)233*61046927SAndroid Build Coastguard Worker _mesa_ScissorIndexed(GLuint index, GLint left, GLint bottom,
234*61046927SAndroid Build Coastguard Worker                      GLsizei width, GLsizei height)
235*61046927SAndroid Build Coastguard Worker {
236*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
237*61046927SAndroid Build Coastguard Worker    scissor_indexed_err(ctx, index, left, bottom, width, height,
238*61046927SAndroid Build Coastguard Worker                        "glScissorIndexed");
239*61046927SAndroid Build Coastguard Worker }
240*61046927SAndroid Build Coastguard Worker 
241*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ScissorIndexedv_no_error(GLuint index,const GLint * v)242*61046927SAndroid Build Coastguard Worker _mesa_ScissorIndexedv_no_error(GLuint index, const GLint *v)
243*61046927SAndroid Build Coastguard Worker {
244*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
245*61046927SAndroid Build Coastguard Worker    _mesa_set_scissor(ctx, index, v[0], v[1], v[2], v[3]);
246*61046927SAndroid Build Coastguard Worker }
247*61046927SAndroid Build Coastguard Worker 
248*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_ScissorIndexedv(GLuint index,const GLint * v)249*61046927SAndroid Build Coastguard Worker _mesa_ScissorIndexedv(GLuint index, const GLint *v)
250*61046927SAndroid Build Coastguard Worker {
251*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
252*61046927SAndroid Build Coastguard Worker    scissor_indexed_err(ctx, index, v[0], v[1], v[2], v[3],
253*61046927SAndroid Build Coastguard Worker                        "glScissorIndexedv");
254*61046927SAndroid Build Coastguard Worker }
255*61046927SAndroid Build Coastguard Worker 
256*61046927SAndroid Build Coastguard Worker void GLAPIENTRY
_mesa_WindowRectanglesEXT(GLenum mode,GLsizei count,const GLint * box)257*61046927SAndroid Build Coastguard Worker _mesa_WindowRectanglesEXT(GLenum mode, GLsizei count, const GLint *box)
258*61046927SAndroid Build Coastguard Worker {
259*61046927SAndroid Build Coastguard Worker    int i;
260*61046927SAndroid Build Coastguard Worker    struct gl_scissor_rect newval[MAX_WINDOW_RECTANGLES];
261*61046927SAndroid Build Coastguard Worker    GET_CURRENT_CONTEXT(ctx);
262*61046927SAndroid Build Coastguard Worker 
263*61046927SAndroid Build Coastguard Worker    if (MESA_VERBOSE & VERBOSE_API)
264*61046927SAndroid Build Coastguard Worker       _mesa_debug(ctx, "glWindowRectanglesEXT(%s, %d, %p)\n",
265*61046927SAndroid Build Coastguard Worker                   _mesa_enum_to_string(mode), count, box);
266*61046927SAndroid Build Coastguard Worker 
267*61046927SAndroid Build Coastguard Worker    if (mode != GL_INCLUSIVE_EXT && mode != GL_EXCLUSIVE_EXT) {
268*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_ENUM,
269*61046927SAndroid Build Coastguard Worker                   "glWindowRectanglesEXT(invalid mode 0x%x)", mode);
270*61046927SAndroid Build Coastguard Worker       return;
271*61046927SAndroid Build Coastguard Worker    }
272*61046927SAndroid Build Coastguard Worker 
273*61046927SAndroid Build Coastguard Worker    if (count < 0) {
274*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE, "glWindowRectanglesEXT(count < 0)");
275*61046927SAndroid Build Coastguard Worker       return;
276*61046927SAndroid Build Coastguard Worker    }
277*61046927SAndroid Build Coastguard Worker 
278*61046927SAndroid Build Coastguard Worker    if (count > ctx->Const.MaxWindowRectangles) {
279*61046927SAndroid Build Coastguard Worker       _mesa_error(ctx, GL_INVALID_VALUE,
280*61046927SAndroid Build Coastguard Worker                   "glWindowRectanglesEXT(count >= MaxWindowRectangles (%d)",
281*61046927SAndroid Build Coastguard Worker                   ctx->Const.MaxWindowRectangles);
282*61046927SAndroid Build Coastguard Worker       return;
283*61046927SAndroid Build Coastguard Worker    }
284*61046927SAndroid Build Coastguard Worker 
285*61046927SAndroid Build Coastguard Worker    for (i = 0; i < count; i++) {
286*61046927SAndroid Build Coastguard Worker       if (box[2] < 0 || box[3] < 0) {
287*61046927SAndroid Build Coastguard Worker          _mesa_error(ctx, GL_INVALID_VALUE,
288*61046927SAndroid Build Coastguard Worker                      "glWindowRectanglesEXT(box %d: w < 0 || h < 0)", i);
289*61046927SAndroid Build Coastguard Worker          return;
290*61046927SAndroid Build Coastguard Worker       }
291*61046927SAndroid Build Coastguard Worker       newval[i].X = box[0];
292*61046927SAndroid Build Coastguard Worker       newval[i].Y = box[1];
293*61046927SAndroid Build Coastguard Worker       newval[i].Width = box[2];
294*61046927SAndroid Build Coastguard Worker       newval[i].Height = box[3];
295*61046927SAndroid Build Coastguard Worker       box += 4;
296*61046927SAndroid Build Coastguard Worker    }
297*61046927SAndroid Build Coastguard Worker 
298*61046927SAndroid Build Coastguard Worker    st_flush_bitmap_cache(st_context(ctx));
299*61046927SAndroid Build Coastguard Worker 
300*61046927SAndroid Build Coastguard Worker    FLUSH_VERTICES(ctx, 0, GL_SCISSOR_BIT);
301*61046927SAndroid Build Coastguard Worker    ctx->NewDriverState |= ST_NEW_WINDOW_RECTANGLES;
302*61046927SAndroid Build Coastguard Worker 
303*61046927SAndroid Build Coastguard Worker    memcpy(ctx->Scissor.WindowRects, newval,
304*61046927SAndroid Build Coastguard Worker           sizeof(struct gl_scissor_rect) * count);
305*61046927SAndroid Build Coastguard Worker    ctx->Scissor.NumWindowRects = count;
306*61046927SAndroid Build Coastguard Worker    ctx->Scissor.WindowRectMode = mode;
307*61046927SAndroid Build Coastguard Worker }
308*61046927SAndroid Build Coastguard Worker 
309*61046927SAndroid Build Coastguard Worker 
310*61046927SAndroid Build Coastguard Worker /**
311*61046927SAndroid Build Coastguard Worker  * Initialize the context's scissor state.
312*61046927SAndroid Build Coastguard Worker  * \param ctx  the GL context.
313*61046927SAndroid Build Coastguard Worker  */
314*61046927SAndroid Build Coastguard Worker void
_mesa_init_scissor(struct gl_context * ctx)315*61046927SAndroid Build Coastguard Worker _mesa_init_scissor(struct gl_context *ctx)
316*61046927SAndroid Build Coastguard Worker {
317*61046927SAndroid Build Coastguard Worker    unsigned i;
318*61046927SAndroid Build Coastguard Worker 
319*61046927SAndroid Build Coastguard Worker    /* Scissor group */
320*61046927SAndroid Build Coastguard Worker    ctx->Scissor.EnableFlags = 0;
321*61046927SAndroid Build Coastguard Worker    ctx->Scissor.WindowRectMode = GL_EXCLUSIVE_EXT;
322*61046927SAndroid Build Coastguard Worker 
323*61046927SAndroid Build Coastguard Worker    /* Note: ctx->Const.MaxViewports may not have been set by the driver yet,
324*61046927SAndroid Build Coastguard Worker     * so just initialize all of them.
325*61046927SAndroid Build Coastguard Worker     */
326*61046927SAndroid Build Coastguard Worker    for (i = 0; i < MAX_VIEWPORTS; i++)
327*61046927SAndroid Build Coastguard Worker       set_scissor_no_notify(ctx, i, 0, 0, 0, 0);
328*61046927SAndroid Build Coastguard Worker }
329