[965] Simplify scissor handling by using DrawBuffer values.
authorEric Anholt <eric@anholt.net>
Mon, 17 Dec 2007 22:51:24 +0000 (14:51 -0800)
committerEric Anholt <eric@anholt.net>
Mon, 17 Dec 2007 23:30:04 +0000 (15:30 -0800)
src/mesa/drivers/dri/i965/brw_sf_state.c
src/mesa/drivers/dri/i965/brw_structs.h

index 8891693e8707cce5d9fa3d9e710c3311855a3380..6c085a1dbf781a344e1b275e9742bb5ba208be97 100644 (file)
@@ -43,62 +43,41 @@ static void upload_sf_vp(struct brw_context *brw)
    struct brw_sf_viewport sfv;
 
    memset(&sfv, 0, sizeof(sfv));
-   
-   if (brw->intel.driDrawable) 
-   {
-      /* _NEW_VIEWPORT, BRW_NEW_METAOPS */
-
-      if (!brw->metaops.active) {
-        const GLfloat *v = ctx->Viewport._WindowMap.m;
-        
-        sfv.viewport.m00 =   v[MAT_SX];
-        sfv.viewport.m11 = - v[MAT_SY];
-        sfv.viewport.m22 =   v[MAT_SZ] * depth_scale;
-        sfv.viewport.m30 =   v[MAT_TX];
-        sfv.viewport.m31 = - v[MAT_TY] + brw->intel.driDrawable->h;
-        sfv.viewport.m32 =   v[MAT_TZ] * depth_scale;
-      }
-      else {
-        sfv.viewport.m00 =   1;
-        sfv.viewport.m11 = - 1;
-        sfv.viewport.m22 =   1;
-        sfv.viewport.m30 =   0;
-        sfv.viewport.m31 =   brw->intel.driDrawable->h;
-        sfv.viewport.m32 =   0;
-      }
-   }
 
-   /* XXX: what state for this? */
-   if (brw->intel.driDrawable)
-   {
-      intelScreenPrivate *screen = brw->intel.intelScreen;
-      /* _NEW_SCISSOR */
-      GLint x = brw->attribs.Scissor->X;
-      GLint y = brw->attribs.Scissor->Y;
-      GLuint w = brw->attribs.Scissor->Width;
-      GLuint h = brw->attribs.Scissor->Height;
-
-      GLint x1 = x;
-      GLint y1 = brw->intel.driDrawable->h - (y + h);
-      GLint x2 = x + w - 1;
-      GLint y2 = y1 + h - 1;
-
-      if (x1 < 0) x1 = 0;
-      if (y1 < 0) y1 = 0;
-      if (x2 < 0) x2 = 0;
-      if (y2 < 0) y2 = 0;
-
-      if (x2 >= screen->width) x2 = screen->width-1;
-      if (y2 >= screen->height) y2 = screen->height-1;
-      if (x1 >= screen->width) x1 = screen->width-1;
-      if (y1 >= screen->height) y1 = screen->height-1;
-      
-      sfv.scissor.xmin = x1;
-      sfv.scissor.xmax = x2;
-      sfv.scissor.ymin = y1;
-      sfv.scissor.ymax = y2;
+   /* _NEW_VIEWPORT, BRW_NEW_METAOPS */
+
+   if (!brw->metaops.active) {
+      const GLfloat *v = ctx->Viewport._WindowMap.m;
+
+      sfv.viewport.m00 =   v[MAT_SX];
+      sfv.viewport.m11 = - v[MAT_SY];
+      sfv.viewport.m22 =   v[MAT_SZ] * depth_scale;
+      sfv.viewport.m30 =   v[MAT_TX];
+      sfv.viewport.m31 = - v[MAT_TY] + ctx->DrawBuffer->Height;
+      sfv.viewport.m32 =   v[MAT_TZ] * depth_scale;
+   } else {
+      sfv.viewport.m00 =   1;
+      sfv.viewport.m11 = - 1;
+      sfv.viewport.m22 =   1;
+      sfv.viewport.m30 =   0;
+      sfv.viewport.m31 =   ctx->DrawBuffer->Height;
+      sfv.viewport.m32 =   0;
    }
 
+   /* _NEW_SCISSOR */
+
+   /* The scissor only needs to handle the intersection of drawable and
+    * scissor rect.  Clipping to the boundaries of static shared buffers
+    * for front/back/depth is covered by looping over cliprects in brw_draw.c.
+    *
+    * Note that the hardware's coordinates are inclusive, while Mesa's min is
+    * inclusive but max is exclusive.
+    */
+   sfv.scissor.xmin = ctx->DrawBuffer->_Xmin;
+   sfv.scissor.xmax = ctx->DrawBuffer->_Xmax - 1;
+   sfv.scissor.ymin = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymax;
+   sfv.scissor.ymax = ctx->DrawBuffer->Height - ctx->DrawBuffer->_Ymin - 1;
+
    dri_bo_unreference(brw->sf.vp_bo);
    brw->sf.vp_bo = brw_cache_data( &brw->cache, BRW_SF_VP, &sfv, NULL, 0 );
 }
index b4500ea8a5fd9cce16c30ea84274a48046b82811..dd11640e6bff897324cfe556aeb706f6eaff1e92 100644 (file)
@@ -924,6 +924,7 @@ struct brw_sf_viewport
       GLfloat m32;  
    } viewport;
 
+   /* scissor coordinates are inclusive */
    struct {
       GLshort xmin;
       GLshort ymin;