1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
30 * Keith Whitwell <keith@tungstengraphics.com>
34 #include "main/macros.h"
35 #include "st_context.h"
36 #include "pipe/p_context.h"
41 * Scissor depends on the scissor box, and the framebuffer dimensions.
44 update_scissor( struct st_context
*st
)
46 struct pipe_scissor_state scissor
;
47 const struct gl_framebuffer
*fb
= st
->ctx
->DrawBuffer
;
52 scissor
.maxx
= fb
->Width
;
53 scissor
.maxy
= fb
->Height
;
55 if (st
->ctx
->Scissor
.Enabled
) {
56 /* need to be careful here with xmax or ymax < 0 */
57 GLint xmax
= MAX2(0, st
->ctx
->Scissor
.X
+ st
->ctx
->Scissor
.Width
);
58 GLint ymax
= MAX2(0, st
->ctx
->Scissor
.Y
+ st
->ctx
->Scissor
.Height
);
60 if (st
->ctx
->Scissor
.X
> (GLint
)scissor
.minx
)
61 scissor
.minx
= st
->ctx
->Scissor
.X
;
62 if (st
->ctx
->Scissor
.Y
> (GLint
)scissor
.miny
)
63 scissor
.miny
= st
->ctx
->Scissor
.Y
;
65 if (xmax
< (GLint
) scissor
.maxx
)
67 if (ymax
< (GLint
) scissor
.maxy
)
70 /* check for null space */
71 if (scissor
.minx
>= scissor
.maxx
|| scissor
.miny
>= scissor
.maxy
)
72 scissor
.minx
= scissor
.miny
= scissor
.maxx
= scissor
.maxy
= 0;
75 /* Now invert Y if needed.
76 * Gallium drivers use the convention Y=0=top for surfaces.
78 if (st_fb_orientation(fb
) == Y_0_TOP
) {
79 miny
= fb
->Height
- scissor
.maxy
;
80 maxy
= fb
->Height
- scissor
.miny
;
85 if (memcmp(&scissor
, &st
->state
.scissor
, sizeof(scissor
)) != 0) {
86 /* state has changed */
87 st
->state
.scissor
= scissor
; /* struct copy */
88 st
->pipe
->set_scissor_state(st
->pipe
, &scissor
); /* activate */
93 const struct st_tracked_state st_update_scissor
= {
94 "st_update_scissor", /* name */
96 (_NEW_SCISSOR
| _NEW_BUFFERS
), /* mesa */
99 update_scissor
/* update */