Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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.  */
  43. static void
  44. update_scissor( struct st_context *st )
  45. {
  46.    struct pipe_scissor_state scissor;
  47.    const struct gl_framebuffer *fb = st->ctx->DrawBuffer;
  48.    GLint miny, maxy;
  49.  
  50.    scissor.minx = 0;
  51.    scissor.miny = 0;
  52.    scissor.maxx = fb->Width;
  53.    scissor.maxy = fb->Height;
  54.  
  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);
  59.  
  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;
  64.  
  65.       if (xmax < (GLint) scissor.maxx)
  66.          scissor.maxx = xmax;
  67.       if (ymax < (GLint) scissor.maxy)
  68.          scissor.maxy = ymax;
  69.  
  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;
  73.    }
  74.  
  75.    /* Now invert Y if needed.
  76.     * Gallium drivers use the convention Y=0=top for surfaces.
  77.     */
  78.    if (st_fb_orientation(fb) == Y_0_TOP) {
  79.       miny = fb->Height - scissor.maxy;
  80.       maxy = fb->Height - scissor.miny;
  81.       scissor.miny = miny;
  82.       scissor.maxy = maxy;
  83.    }
  84.  
  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 */
  89.    }
  90. }
  91.  
  92.  
  93. const struct st_tracked_state st_update_scissor = {
  94.    "st_update_scissor",                                 /* name */
  95.    {                                                    /* dirty */
  96.       (_NEW_SCISSOR | _NEW_BUFFERS),                    /* mesa */
  97.       0,                                                /* st */
  98.    },
  99.    update_scissor                                       /* update */
  100. };
  101.