include surface.offset in address calculations
[mesa.git] / src / mesa / pipe / softpipe / sp_state_derived.c
index 26083c29628e58df8b240428ddb9b71a98e6b9c2..e1faaed93ce759cef26962eb03b54b3b1a32d42a 100644 (file)
@@ -163,6 +163,41 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe )
 }
 
 
+/**
+ * Recompute cliprect from scissor bounds, scissor enable and surface size.
+ */
+static void
+compute_cliprect(struct softpipe_context *sp)
+{
+   GLint surfWidth, surfHeight;
+
+   if (sp->framebuffer.num_cbufs > 0) {
+      surfWidth = sp->framebuffer.cbufs[0]->width;
+      surfHeight = sp->framebuffer.cbufs[0]->height;
+   }
+   else {
+      /* no surface? */
+      surfWidth = sp->scissor.maxx;
+      surfHeight = sp->scissor.maxy;
+   }
+
+   if (sp->setup.scissor) {
+      /* clip to scissor rect */
+      sp->cliprect.minx = MAX2(sp->scissor.minx, 0);
+      sp->cliprect.miny = MAX2(sp->scissor.miny, 0);
+      sp->cliprect.maxx = MIN2(sp->scissor.maxx, surfWidth);
+      sp->cliprect.maxy = MIN2(sp->scissor.maxy, surfHeight);
+   }
+   else {
+      /* clip to surface bounds */
+      sp->cliprect.minx = 0;
+      sp->cliprect.miny = 0;
+      sp->cliprect.maxx = surfWidth;
+      sp->cliprect.maxy = surfHeight;
+   }
+}
+
+
 /* Hopefully this will remain quite simple, otherwise need to pull in
  * something like the state tracker mechanism.
  */
@@ -171,6 +206,11 @@ void softpipe_update_derived( struct softpipe_context *softpipe )
    if (softpipe->dirty & (SP_NEW_SETUP | SP_NEW_FS))
       calculate_vertex_layout( softpipe );
 
+   if (softpipe->dirty & (SP_NEW_SCISSOR |
+                          SP_NEW_STENCIL |
+                          SP_NEW_FRAMEBUFFER))
+      compute_cliprect(softpipe);
+
    if (softpipe->dirty & (SP_NEW_BLEND |
                           SP_NEW_DEPTH_TEST |
                           SP_NEW_ALPHA_TEST |