1/************************************************************************** 2 * 3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 4 * All Rights Reserved. 5 * 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: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 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. 25 * 26 **************************************************************************/ 27 28 /* 29 * Authors: 30 * Keith Whitwell <keith@tungstengraphics.com> 31 */ 32 33 34#include "main/macros.h" 35#include "st_context.h" 36#include "pipe/p_context.h" 37#include "st_atom.h" 38 39 40/** 41 * Scissor depends on the scissor box, and the framebuffer dimensions. 42 */ 43static void 44update_scissor( struct st_context *st ) 45{ 46 struct pipe_scissor_state scissor; 47 const struct gl_context *ctx = st->ctx; 48 const struct gl_framebuffer *fb = ctx->DrawBuffer; 49 GLint miny, maxy; 50 51 scissor.minx = 0; 52 scissor.miny = 0; 53 scissor.maxx = fb->Width; 54 scissor.maxy = fb->Height; 55 56 if (ctx->Scissor.Enabled) { 57 /* need to be careful here with xmax or ymax < 0 */ 58 GLint xmax = MAX2(0, ctx->Scissor.X + ctx->Scissor.Width); 59 GLint ymax = MAX2(0, ctx->Scissor.Y + ctx->Scissor.Height); 60 61 if (ctx->Scissor.X > (GLint)scissor.minx) 62 scissor.minx = ctx->Scissor.X; 63 if (ctx->Scissor.Y > (GLint)scissor.miny) 64 scissor.miny = ctx->Scissor.Y; 65 66 if (xmax < (GLint) scissor.maxx) 67 scissor.maxx = xmax; 68 if (ymax < (GLint) scissor.maxy) 69 scissor.maxy = ymax; 70 71 /* check for null space */ 72 if (scissor.minx >= scissor.maxx || scissor.miny >= scissor.maxy) 73 scissor.minx = scissor.miny = scissor.maxx = scissor.maxy = 0; 74 } 75 76 /* Now invert Y if needed. 77 * Gallium drivers use the convention Y=0=top for surfaces. 78 */ 79 if (st_fb_orientation(fb) == Y_0_TOP) { 80 miny = fb->Height - scissor.maxy; 81 maxy = fb->Height - scissor.miny; 82 scissor.miny = miny; 83 scissor.maxy = maxy; 84 } 85 86 if (memcmp(&scissor, &st->state.scissor, sizeof(scissor)) != 0) { 87 /* state has changed */ 88 st->state.scissor = scissor; /* struct copy */ 89 st->pipe->set_scissor_state(st->pipe, &scissor); /* activate */ 90 } 91} 92 93 94const struct st_tracked_state st_update_scissor = { 95 "st_update_scissor", /* name */ 96 { /* dirty */ 97 (_NEW_SCISSOR | _NEW_BUFFERS), /* mesa */ 98 0, /* st */ 99 }, 100 update_scissor /* update */ 101}; 102