vbo: implement primitive merging for glBegin/End sequences
authorBrian Paul <brianp@vmware.com>
Sat, 4 May 2013 01:00:07 +0000 (19:00 -0600)
committerBrian Paul <brianp@vmware.com>
Sat, 4 May 2013 01:00:07 +0000 (19:00 -0600)
commit4ea05bcba66cb0d49cbad20158b41864a20a73b9
treede6816913b5064297fbd591253f61aa2da4cf8c7
parent3702d2508249bb264ab502c0093dbbc10b0b02fa
vbo: implement primitive merging for glBegin/End sequences

A surprising number of apps and benchmarks have poor code like this:

glBegin(GL_LINE_STRIP);
glVertex(v1);
glVertex(v2);
glEnd();
// Possibly some no-op state changes here
glBegin(GL_LINE_STRIP);
glVertex(v3);
glVertex(v4);
glEnd();
// repeat many, many times.

The above sequence can be converted into:

glBegin(GL_LINES);
glVertex(v1);
glVertex(v2);
glVertex(v3);
glVertex(v4);
glEnd();

Similarly for GL_POINTS, GL_TRIANGLES, etc.

Merging was already implemented for GL_QUADS in the display list code.
Now other prim types are handled and it's also done for immediate mode.

In one case:
                                 before   after
-----------------------------------------------
number of st_draw_vbo() calls:     141      45
number of _mesa_prims issued:     7520     632

Reviewed-by: Eric Anholt <eric@anholt.net>
Reviewed-by: José Fonseca <jfonseca@vmware.com>
src/mesa/vbo/vbo_exec_api.c
src/mesa/vbo/vbo_save_api.c