Cell: compute bounding box in cell_vbuf_draw()
authorBrian <brian.paul@tungstengraphics.com>
Fri, 11 Jan 2008 04:50:55 +0000 (21:50 -0700)
committerBrian <brian.paul@tungstengraphics.com>
Fri, 11 Jan 2008 04:50:55 +0000 (21:50 -0700)
src/mesa/pipe/cell/ppu/cell_vbuf.c

index 059a098..62d453c 100644 (file)
@@ -95,8 +95,24 @@ cell_vbuf_draw(struct vbuf_render *vbr,
 {
    struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr);
    struct cell_context *cell = cvbr->cell;
+   float xmin, ymin, xmax, ymax;
    uint i;
 
+   /* compute x/y bounding box */
+   xmin = ymin = 1e50;
+   xmax = ymax = -1e50;
+   for (i = 0; i < nr_vertices; i++) {
+      const float *v = (float *) ((ubyte *) vertices + i * vertex_size);
+      if (v[0] < xmin)
+         xmin = v[0];
+      if (v[0] > xmax)
+         xmax = v[0];
+      if (v[1] < ymin)
+         ymin = v[1];
+      if (v[1] > ymax)
+         ymax = v[1];
+   }
+
    /*printf("cell_vbuf_draw nr_indices = %u\n", nr_indices);*/
 
    if (prim != PIPE_PRIM_TRIANGLES)
@@ -110,17 +126,10 @@ cell_vbuf_draw(struct vbuf_render *vbr,
       render->vertex_data = vertices;
       render->index_data = indices;
       render->num_indexes = nr_indices;
-#if 0
-      render->xmin = cell->prim_buffer.xmin;
-      render->ymin = cell->prim_buffer.ymin;
-      render->xmax = cell->prim_buffer.xmax;
-      render->ymax = cell->prim_buffer.ymax;
-#else
-      render->xmin = -100;
-      render->ymin = -100;
-      render->xmax =  100;
-      render->ymax =  100;
-#endif
+      render->xmin = xmin;
+      render->ymin = ymin;
+      render->xmax = xmax;
+      render->ymax = ymax;
 
       ASSERT_ALIGN16(render->vertex_data);
       ASSERT_ALIGN16(render->index_data);