1 /**************************************************************************
3 * Copyright 2007 VMware, Inc.
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 VMWARE 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 <keithw@vmware.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
[PIPE_MAX_VIEWPORTS
];
47 const struct gl_context
*ctx
= st
->ctx
;
48 const struct gl_framebuffer
*fb
= ctx
->DrawBuffer
;
52 for (i
= 0 ; i
< ctx
->Const
.MaxViewports
; i
++) {
55 scissor
[i
].maxx
= fb
->Width
;
56 scissor
[i
].maxy
= fb
->Height
;
58 if (ctx
->Scissor
.EnableFlags
& (1 << i
)) {
59 /* need to be careful here with xmax or ymax < 0 */
60 GLint xmax
= MAX2(0, ctx
->Scissor
.ScissorArray
[i
].X
+ ctx
->Scissor
.ScissorArray
[i
].Width
);
61 GLint ymax
= MAX2(0, ctx
->Scissor
.ScissorArray
[i
].Y
+ ctx
->Scissor
.ScissorArray
[i
].Height
);
63 if (ctx
->Scissor
.ScissorArray
[i
].X
> (GLint
)scissor
[i
].minx
)
64 scissor
[i
].minx
= ctx
->Scissor
.ScissorArray
[i
].X
;
65 if (ctx
->Scissor
.ScissorArray
[i
].Y
> (GLint
)scissor
[i
].miny
)
66 scissor
[i
].miny
= ctx
->Scissor
.ScissorArray
[i
].Y
;
68 if (xmax
< (GLint
) scissor
[i
].maxx
)
69 scissor
[i
].maxx
= xmax
;
70 if (ymax
< (GLint
) scissor
[i
].maxy
)
71 scissor
[i
].maxy
= ymax
;
73 /* check for null space */
74 if (scissor
[i
].minx
>= scissor
[i
].maxx
|| scissor
[i
].miny
>= scissor
[i
].maxy
)
75 scissor
[i
].minx
= scissor
[i
].miny
= scissor
[i
].maxx
= scissor
[i
].maxy
= 0;
78 /* Now invert Y if needed.
79 * Gallium drivers use the convention Y=0=top for surfaces.
81 if (st_fb_orientation(fb
) == Y_0_TOP
) {
82 miny
= fb
->Height
- scissor
[i
].maxy
;
83 maxy
= fb
->Height
- scissor
[i
].miny
;
84 scissor
[i
].miny
= miny
;
85 scissor
[i
].maxy
= maxy
;
88 if (memcmp(&scissor
[i
], &st
->state
.scissor
[i
], sizeof(scissor
[0])) != 0) {
89 /* state has changed */
90 st
->state
.scissor
[i
] = scissor
[i
]; /* struct copy */
95 st
->pipe
->set_scissor_states(st
->pipe
, 0, ctx
->Const
.MaxViewports
, scissor
); /* activate */
99 const struct st_tracked_state st_update_scissor
= {
100 "st_update_scissor", /* name */
102 (_NEW_SCISSOR
| _NEW_BUFFERS
), /* mesa */
105 update_scissor
/* update */