[PATCH 10/10] glamor: Use vbo for solid boxes.
Markus Wick
markus at selfnet.de
Tue Mar 18 01:42:56 PDT 2014
---
glamor/glamor_fill.c | 40 ++++++++++++----------------------------
1 file changed, 12 insertions(+), 28 deletions(-)
diff --git a/glamor/glamor_fill.c b/glamor/glamor_fill.c
index 2fa726e..3286aa1 100644
--- a/glamor/glamor_fill.c
+++ b/glamor/glamor_fill.c
@@ -190,9 +190,6 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color)
glamor_screen_private *glamor_priv = glamor_get_screen_private(screen);
glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
GLfloat xscale, yscale;
- float stack_vertices[32];
- float *vertices = stack_vertices;
- int valid_nbox = ARRAY_SIZE(stack_vertices) / (4 * 2);
glamor_set_destination_pixmap_priv_nc(pixmap_priv);
@@ -203,39 +200,29 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color)
pixmap_priv_get_dest_scale(pixmap_priv, &xscale, &yscale);
- if (nbox > valid_nbox) {
- int allocated_nbox;
- float *new_vertices;
-
- if (nbox > GLAMOR_COMPOSITE_VBO_VERT_CNT / 6)
- allocated_nbox = GLAMOR_COMPOSITE_VBO_VERT_CNT / 6;
- else
- allocated_nbox = nbox;
- new_vertices = malloc(allocated_nbox * 4 * 2 * sizeof(float));
- if (new_vertices) {
- vertices = new_vertices;
- valid_nbox = allocated_nbox;
- }
- }
-
- glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
- GL_FALSE, 2 * sizeof(float), vertices);
glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
while (nbox) {
int box_cnt, i;
- float *next_box;
+ float *vertices;
+ char *vbo_offset;
- next_box = vertices;
- box_cnt = nbox > valid_nbox ? valid_nbox : nbox;
+ box_cnt = MIN(nbox, GLAMOR_COMPOSITE_VBO_VERT_CNT / 6);
+
+ vertices = glamor_get_vbo_space(screen,
+ box_cnt * 4 * 2 * sizeof(float),
+ &vbo_offset);
+ glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
+ GL_FALSE, 2 * sizeof(float), vbo_offset);
for (i = 0; i < box_cnt; i++) {
glamor_set_normalize_vcoords(pixmap_priv, xscale, yscale,
box[i].x1, box[i].y1,
box[i].x2, box[i].y2,
glamor_priv->yInverted,
- next_box);
- next_box += 4 * 2;
+ vertices);
+ vertices += 4 * 2;
}
+ glamor_put_vbo_space(screen);
if (box_cnt == 1)
glDrawArrays(GL_TRIANGLE_FAN, 0, box_cnt * 4);
else {
@@ -251,9 +238,6 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color)
box += box_cnt;
}
- if (vertices != stack_vertices)
- free(vertices);
-
glDisableVertexAttribArray(GLAMOR_VERTEX_POS);
glamor_put_context(glamor_priv);
glamor_priv->state = RENDER_STATE;
--
1.9.0
More information about the xorg-devel
mailing list