struct vbuf_render base;
struct cell_context *cell;
uint prim;
+ uint vertex_size;
+ void *vertex_buffer;
};
cell_vbuf_allocate_vertices(struct vbuf_render *vbr,
ushort vertex_size, ushort nr_vertices)
{
+ struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr);
/*printf("Alloc verts %u * %u\n", vertex_size, nr_vertices);*/
- return align_malloc(vertex_size * nr_vertices, 16);
+ assert(!cvbr->vertex_buffer);
+ cvbr->vertex_buffer = align_malloc(vertex_size * nr_vertices, 16);
+ cvbr->vertex_size = vertex_size;
+ return cvbr->vertex_buffer;
}
static void
cell_vbuf_draw(struct vbuf_render *vbr,
- uint prim,
const ushort *indices,
- uint nr_indices,
- const void *vertices,
- uint nr_vertices,
- uint vertex_size)
+ uint nr_indices)
{
struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr);
struct cell_context *cell = cvbr->cell;
float xmin, ymin, xmax, ymax;
uint i;
+ uint nr_vertices = 0;
+ const void *vertices = cvbr->vertex_buffer;
+ const uint vertex_size = cvbr->vertex_size;
+
+ for (i = 0; i < nr_indices; i++) {
+ if (indices[i] > nr_vertices)
+ nr_vertices = indices[i];
+ }
+ nr_vertices++;
#if 0
printf("cell_vbuf_draw() nr_indices = %u nr_verts = %u\n",
ymax = v[1];
}
- if (prim != PIPE_PRIM_TRIANGLES)
+ if (cvbr->prim != PIPE_PRIM_TRIANGLES)
return; /* only render tris for now */
#if 0
for (i = 0; i < cell->num_spus; i++) {
struct cell_command_render *render = &cell_global.command[i].render;
render->opcode = CELL_CMD_RENDER;
- render->prim_type = prim;
+ render->prim_type = cvbr->prim;
render->num_verts = nr_vertices;
render->num_attribs = CELL_MAX_ATTRIBS; /* XXX fix */
render->vertex_data = vertices;
= (struct cell_command_render *)
cell_batch_alloc(cell, sizeof(*render));
render->opcode = CELL_CMD_RENDER;
- render->prim_type = prim;
+ render->prim_type = cvbr->prim;
render->num_verts = nr_vertices;
render->num_attribs = CELL_MAX_ATTRIBS; /* XXX fix */
render->vertex_data = vertices;
cell_vbuf_release_vertices(struct vbuf_render *vbr, void *vertices,
unsigned vertex_size, unsigned vertices_used)
{
+ struct cell_vbuf_render *cvbr = cell_vbuf_render(vbr);
+
/*printf("Free verts %u * %u\n", vertex_size, vertices_used);*/
align_free(vertices);
+
+ assert(vertices == cvbr->vertex_buffer);
+ cvbr->vertex_buffer = NULL;
}
static void vbuf_flush_indices( struct draw_stage *stage );
-static void vbuf_flush_vertices( struct draw_stage *stage,
+static void vbuf_flush_vertices( struct draw_stage *stage );
+static void vbuf_alloc_vertices( struct draw_stage *stage,
unsigned new_vertex_size );
static INLINE void
check_space( struct vbuf_stage *vbuf, unsigned nr )
{
- if (vbuf->nr_vertices + nr > vbuf->max_vertices )
- vbuf_flush_vertices(&vbuf->stage, vbuf->vertex_size );
+ if (vbuf->nr_vertices + nr > vbuf->max_vertices ) {
+ vbuf_flush_vertices(&vbuf->stage);
+ vbuf_alloc_vertices(&vbuf->stage, vbuf->vertex_size);
+ }
if (vbuf->nr_indices + nr > vbuf->max_indices )
vbuf_flush_indices(&vbuf->stage);
struct vbuf_stage *vbuf = vbuf_stage( stage );
vbuf_flush_indices( stage );
+
stage->tri = vbuf_tri;
- stage->tri( stage, prim );
vbuf->prim = PIPE_PRIM_TRIANGLES;
vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_TRIANGLES);
+
+ stage->tri( stage, prim );
}
vbuf_flush_indices( stage );
stage->line = vbuf_line;
- stage->line( stage, prim );
vbuf->prim = PIPE_PRIM_LINES;
vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_LINES);
+
+ stage->line( stage, prim );
}
struct vbuf_stage *vbuf = vbuf_stage( stage );
vbuf_flush_indices( stage );
+
stage->point = vbuf_point;
- stage->point( stage, prim );
vbuf->prim = PIPE_PRIM_POINTS;
vbuf->render->set_primitive(vbuf->render, PIPE_PRIM_POINTS);
+
+ stage->point( stage, prim );
}
assert(0);
}
- vbuf->render->draw( vbuf->render,
- vbuf->prim,
- vbuf->indices,
- vbuf->nr_indices,
- vbuf->vertices,
- vbuf->nr_vertices,
- vbuf->vertex_size );
-
+ vbuf->render->draw(vbuf->render, vbuf->indices, vbuf->nr_indices);
+
vbuf->nr_indices = 0;
+
+ stage->point = vbuf_first_point;
+ stage->line = vbuf_first_line;
+ stage->tri = vbuf_first_tri;
}
* we flush.
*/
static void
-vbuf_flush_vertices( struct draw_stage *stage,
- unsigned new_vertex_size )
+vbuf_flush_vertices( struct draw_stage *stage )
{
struct vbuf_stage *vbuf = vbuf_stage( stage );
vbuf->vertex_ptr = vbuf->vertices = NULL;
}
+}
+
+static void
+vbuf_alloc_vertices( struct draw_stage *stage,
+ unsigned new_vertex_size )
+{
+ struct vbuf_stage *vbuf = vbuf_stage( stage );
+
assert(!vbuf->nr_indices);
+ assert(!vbuf->vertices);
/* Allocate a new vertex buffer */
vbuf->vertex_size = new_vertex_size;
vbuf->max_vertices = vbuf->render->max_vertex_buffer_bytes / vbuf->vertex_size;
vbuf->vertices = vbuf->render->allocate_vertices(vbuf->render,
- vbuf->vertex_size,
- vbuf->max_vertices) ;
+ (ushort) vbuf->vertex_size,
+ (ushort) vbuf->max_vertices);
vbuf->vertex_ptr = vbuf->vertices;
}
const struct vertex_info *vinfo = vbuf->render->get_vertex_info(vbuf->render);
unsigned vertex_size = vinfo->size * sizeof(float);
- if(vbuf->vertex_size != vertex_size)
- vbuf_flush_vertices(&vbuf->stage, vertex_size);
+ /* XXX: Overkill */
+ vbuf_alloc_vertices(&vbuf->stage, vertex_size);
}
static void
vbuf_end( struct draw_stage *stage )
{
-#if 0
+// vbuf_flush_indices( stage );
/* XXX: Overkill */
- vbuf_flush_indices( stage );
-#else
- /* By flushing vertices we avoid having the vertex buffer grow and grow */
- struct vbuf_stage *vbuf = vbuf_stage(stage);
- vbuf_flush_vertices( stage, vbuf->vertex_size );
-#endif
+ vbuf_flush_vertices( stage );
stage->point = vbuf_first_point;
stage->line = vbuf_first_line;