Support loop, conditional update fix
[mesa.git] / src / mesa / drivers / dri / i965 / brw_draw_upload.c
index 6968d745c1c9f9e555397299fedcaae51bea690e..6150cac4aa3b4d64e340f87e1627c9250e88798e 100644 (file)
@@ -408,9 +408,11 @@ GLboolean brw_upload_vertices( struct brw_context *brw,
 
    /* First build an array of pointers to ve's in vb.inputs_read
     */
+   if (0)
+      _mesa_printf("%s %d..%d\n", __FUNCTION__, min_index, max_index);
    
    while (tmp) {
-      GLuint i = ffsll(tmp)-1;
+      GLuint i = _mesa_ffsll(tmp)-1;
       struct brw_vertex_element *input = &brw->vb.inputs[i];
 
       tmp &= ~(1<<i);
@@ -418,7 +420,7 @@ GLboolean brw_upload_vertices( struct brw_context *brw,
 
       input->index = i;
       input->element_size = get_size(input->glarray->Type) * input->glarray->Size;
-      input->count = input->glarray->StrideB ? max_index - min_index : 1;
+      input->count = input->glarray->StrideB ? max_index + 1 - min_index : 1;
 
       if (!input->glarray->BufferObj->Name) {
         if (i == 0) {
@@ -437,7 +439,15 @@ GLboolean brw_upload_vertices( struct brw_context *brw,
         }
 
         upload[nr_uploads++] = input;
-        assert(min_index == 0);
+        
+        /* We rebase drawing to start at element zero only when
+         * varyings are not in vbos, which means we can end up
+         * uploading non-varying arrays (stride != 0) when min_index
+         * is zero.  This doesn't matter as the amount to upload is
+         * the same for these arrays whether the draw call is rebased
+         * or not - we just have to upload the one element.
+         */
+        assert(min_index == 0 || input->glarray->StrideB == 0);
       }
    }