include surface.offset in address calculations
[mesa.git] / src / mesa / pipe / softpipe / sp_state_derived.c
index 84a1ec79f805b835c765ee5ebdc2d5d382ffe145..e1faaed93ce759cef26962eb03b54b3b1a32d42a 100644 (file)
@@ -60,6 +60,14 @@ static const GLuint frag_to_vf[FRAG_ATTRIB_MAX] =
    VF_ATTRIB_TEX5,
    VF_ATTRIB_TEX6,
    VF_ATTRIB_TEX7,
+   VF_ATTRIB_VAR0,
+   VF_ATTRIB_VAR1,
+   VF_ATTRIB_VAR2,
+   VF_ATTRIB_VAR3,
+   VF_ATTRIB_VAR4,
+   VF_ATTRIB_VAR5,
+   VF_ATTRIB_VAR6,
+   VF_ATTRIB_VAR7,
 };
 
 
@@ -109,6 +117,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe )
     */
    for (i = 1; i < FRAG_ATTRIB_TEX0; i++) {
       if (inputsRead & (1 << i)) {
+         assert(i < sizeof(frag_to_vf) / sizeof(frag_to_vf[0]));
          if (softpipe->setup.flatshade
              && (i == FRAG_ATTRIB_COL0 || i == FRAG_ATTRIB_COL1))
             EMIT_ATTR(frag_to_vf[i], i, INTERP_CONSTANT);
@@ -119,6 +128,7 @@ static void calculate_vertex_layout( struct softpipe_context *softpipe )
 
    for (i = FRAG_ATTRIB_TEX0; i < FRAG_ATTRIB_MAX; i++) {
       if (inputsRead & (1 << i)) {
+         assert(i < sizeof(frag_to_vf) / sizeof(frag_to_vf[0]));
          EMIT_ATTR(frag_to_vf[i], i, INTERP_PERSPECTIVE);
          softpipe->need_w = GL_TRUE;
       }
@@ -153,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.
  */
@@ -161,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 |