summaryrefslogtreecommitdiff
path: root/src/mesa/pipe/draw/draw_vbuf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/pipe/draw/draw_vbuf.c')
-rw-r--r--src/mesa/pipe/draw/draw_vbuf.c74
1 files changed, 41 insertions, 33 deletions
diff --git a/src/mesa/pipe/draw/draw_vbuf.c b/src/mesa/pipe/draw/draw_vbuf.c
index cd0b4fbbb9..1e260c6156 100644
--- a/src/mesa/pipe/draw/draw_vbuf.c
+++ b/src/mesa/pipe/draw/draw_vbuf.c
@@ -50,6 +50,8 @@ struct vbuf_stage {
struct vbuf_render *render;
+ const struct vertex_info *vinfo;
+
/** Vertex size in bytes */
unsigned vertex_size;
@@ -82,10 +84,9 @@ vbuf_stage( struct draw_stage *stage )
}
-static void vbuf_flush_indices( 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 void vbuf_flush_indices( struct vbuf_stage *vbuf );
+static void vbuf_flush_vertices( struct vbuf_stage *vbuf );
+static void vbuf_alloc_vertices( struct vbuf_stage *vbuf );
static INLINE boolean
@@ -100,12 +101,12 @@ 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_alloc_vertices(&vbuf->stage, vbuf->vertex_size);
+ vbuf_flush_vertices(vbuf);
+ vbuf_alloc_vertices(vbuf);
}
if (vbuf->nr_indices + nr > vbuf->max_indices )
- vbuf_flush_indices(&vbuf->stage);
+ vbuf_flush_indices(vbuf);
}
@@ -120,10 +121,12 @@ static INLINE void
emit_vertex( struct vbuf_stage *vbuf,
struct vertex_header *vertex )
{
- const struct vertex_info *vinfo = vbuf->render->get_vertex_info(vbuf->render);
+ const struct vertex_info *vinfo = vbuf->vinfo;
uint i;
uint count = 0; /* for debug/sanity */
+
+ assert(vinfo == vbuf->render->get_vertex_info(vbuf->render));
// fprintf(stderr, "emit vertex %d to %p\n",
// vbuf->nr_vertices, vbuf->vertex_ptr);
@@ -246,9 +249,8 @@ vbuf_point( struct draw_stage *stage,
* will be flushed if needed and a new one allocated.
*/
static void
-vbuf_set_prim( struct draw_stage *stage, uint newprim )
+vbuf_set_prim( struct vbuf_stage *vbuf, uint newprim )
{
- struct vbuf_stage *vbuf = vbuf_stage(stage);
const struct vertex_info *vinfo;
unsigned vertex_size;
@@ -263,10 +265,13 @@ vbuf_set_prim( struct draw_stage *stage, uint newprim )
vertex_size = vinfo->size * sizeof(float);
if (vertex_size != vbuf->vertex_size)
- vbuf_flush_vertices(stage);
+ vbuf_flush_vertices(vbuf);
+ vbuf->vinfo = vinfo;
+ vbuf->vertex_size = vertex_size;
+
if (!vbuf->vertices)
- vbuf_alloc_vertices(stage, vertex_size);
+ vbuf_alloc_vertices(vbuf);
}
@@ -274,9 +279,11 @@ static void
vbuf_first_tri( struct draw_stage *stage,
struct prim_header *prim )
{
- vbuf_flush_indices( stage );
+ struct vbuf_stage *vbuf = vbuf_stage( stage );
+
+ vbuf_flush_indices( vbuf );
stage->tri = vbuf_tri;
- vbuf_set_prim(stage, PIPE_PRIM_TRIANGLES);
+ vbuf_set_prim(vbuf, PIPE_PRIM_TRIANGLES);
stage->tri( stage, prim );
}
@@ -285,9 +292,11 @@ static void
vbuf_first_line( struct draw_stage *stage,
struct prim_header *prim )
{
- vbuf_flush_indices( stage );
+ struct vbuf_stage *vbuf = vbuf_stage( stage );
+
+ vbuf_flush_indices( vbuf );
stage->line = vbuf_line;
- vbuf_set_prim(stage, PIPE_PRIM_LINES);
+ vbuf_set_prim(vbuf, PIPE_PRIM_LINES);
stage->line( stage, prim );
}
@@ -296,18 +305,18 @@ static void
vbuf_first_point( struct draw_stage *stage,
struct prim_header *prim )
{
- vbuf_flush_indices( stage );
+ struct vbuf_stage *vbuf = vbuf_stage( stage );
+
+ vbuf_flush_indices( vbuf );
stage->point = vbuf_point;
- vbuf_set_prim(stage, PIPE_PRIM_POINTS);
+ vbuf_set_prim(vbuf, PIPE_PRIM_POINTS);
stage->point( stage, prim );
}
static void
-vbuf_flush_indices( struct draw_stage *stage )
+vbuf_flush_indices( struct vbuf_stage *vbuf )
{
- struct vbuf_stage *vbuf = vbuf_stage( stage );
-
if(!vbuf->nr_indices)
return;
@@ -331,9 +340,12 @@ vbuf_flush_indices( struct draw_stage *stage )
vbuf->nr_indices = 0;
+ /* don't need to reset point/line/tri functions */
+#if 0
stage->point = vbuf_first_point;
stage->line = vbuf_first_line;
stage->tri = vbuf_first_tri;
+#endif
}
@@ -345,12 +357,10 @@ vbuf_flush_indices( struct draw_stage *stage )
* we flush.
*/
static void
-vbuf_flush_vertices( struct draw_stage *stage )
+vbuf_flush_vertices( struct vbuf_stage *vbuf )
{
- struct vbuf_stage *vbuf = vbuf_stage( stage );
-
if(vbuf->vertices) {
- vbuf_flush_indices(stage);
+ vbuf_flush_indices(vbuf);
/* Reset temporary vertices ids */
if(vbuf->nr_vertices)
@@ -361,7 +371,7 @@ vbuf_flush_vertices( struct draw_stage *stage )
vbuf->vertices,
vbuf->vertex_size,
vbuf->nr_vertices);
- vbuf->nr_vertices = 0;
+ vbuf->max_vertices = vbuf->nr_vertices = 0;
vbuf->vertex_ptr = vbuf->vertices = NULL;
}
@@ -369,16 +379,12 @@ vbuf_flush_vertices( struct draw_stage *stage )
static void
-vbuf_alloc_vertices( struct draw_stage *stage,
- unsigned new_vertex_size )
+vbuf_alloc_vertices( struct vbuf_stage *vbuf )
{
- 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 = (uint *) vbuf->render->allocate_vertices(vbuf->render,
(ushort) vbuf->vertex_size,
@@ -391,14 +397,16 @@ vbuf_alloc_vertices( struct draw_stage *stage,
static void
vbuf_flush( struct draw_stage *stage, unsigned flags )
{
- vbuf_flush_indices( stage );
+ struct vbuf_stage *vbuf = vbuf_stage( stage );
+
+ vbuf_flush_indices( vbuf );
stage->point = vbuf_first_point;
stage->line = vbuf_first_line;
stage->tri = vbuf_first_tri;
if (flags & DRAW_FLUSH_BACKEND)
- vbuf_flush_vertices( stage );
+ vbuf_flush_vertices( vbuf );
}