[PATCH 2/8] glamor/xv: add vbo support

Eric Anholt eric at anholt.net
Mon Jan 18 17:15:14 PST 2016


Dave Airlie <airlied at gmail.com> writes:

> From: Dave Airlie <airlied at redhat.com>
>
> This converts the Xv code to using VBOs instead of
> client ptrs. This is necessary to move towards using
> the core profile later.
>
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  glamor/glamor_xv.c | 31 +++++++++++++++++++++----------
>  1 file changed, 21 insertions(+), 10 deletions(-)
>
> diff --git a/glamor/glamor_xv.c b/glamor/glamor_xv.c
> index 85e6528..d9db574 100644
> --- a/glamor/glamor_xv.c
> +++ b/glamor/glamor_xv.c
> @@ -245,7 +245,6 @@ glamor_xv_render(glamor_port_private *port_priv)
>      PixmapPtr pixmap = port_priv->pPixmap;
>      glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
>      glamor_pixmap_private *src_pixmap_priv[3];
> -    float vertices[32], texcoords[8];
>      BoxPtr box = REGION_RECTS(&port_priv->clip);
>      int nBox = REGION_NUM_RECTS(&port_priv->clip);
>      int dst_x_off, dst_y_off;
> @@ -260,6 +259,8 @@ glamor_xv_render(glamor_port_private *port_priv)
>      float bright, cont, gamma;
>      int ref = port_priv->transform_index;
>      GLint uloc, sampler_loc;
> +    GLfloat *v;
> +    char *vbo_offset;
>  
>      if (!glamor_priv->xv_prog)
>          glamor_init_xv_shader(screen);
> @@ -335,16 +336,13 @@ glamor_xv_render(glamor_port_private *port_priv)
>      sampler_loc = glGetUniformLocation(glamor_priv->xv_prog, "v_sampler");
>      glUniform1i(sampler_loc, 2);
>  
> -    glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
> -                          GL_FLOAT, GL_FALSE,
> -                          2 * sizeof(float), texcoords);
> +    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
>      glEnableVertexAttribArray(GLAMOR_VERTEX_SOURCE);
>  
> -    glVertexAttribPointer(GLAMOR_VERTEX_POS, 2, GL_FLOAT,
> -                          GL_FALSE, 2 * sizeof(float), vertices);
> -
> -    glEnableVertexAttribArray(GLAMOR_VERTEX_POS);
>      glEnable(GL_SCISSOR_TEST);
> +
> +    v = glamor_get_vbo_space(screen, 16 * sizeof(GLfloat) * nBox, &vbo_offset);
> +
>      for (i = 0; i < nBox; i++) {
>          float off_x = box[i].x1 - port_priv->drw_x;
>          float off_y = box[i].y1 - port_priv->drw_y;
> @@ -352,6 +350,7 @@ glamor_xv_render(glamor_port_private *port_priv)
>          float diff_y = (float) port_priv->src_h / (float) port_priv->dst_h;
>          float srcx, srcy, srcw, srch;
>          int dstx, dsty, dstw, dsth;
> +        GLfloat *ptr = v + (i * 16);
>  
>          dstx = box[i].x1 + dst_x_off;
>          dsty = box[i].y1 + dst_y_off;
> @@ -369,7 +368,7 @@ glamor_xv_render(glamor_port_private *port_priv)
>                                       dsty,
>                                       dstx + dstw,
>                                       dsty + dsth * 2,
> -                                     vertices);
> +                                     ptr);
>  
>          glamor_set_normalize_tcoords(src_pixmap_priv[0],
>                                       src_xscale[0],
> @@ -378,16 +377,28 @@ glamor_xv_render(glamor_port_private *port_priv)
>                                       srcy,
>                                       srcx + srcw,
>                                       srcy + srch * 2,
> -                                     texcoords);
> +                                     ptr + 8);
> +
> +
> +        glVertexAttribPointer(GLAMOR_VERTEX_POS, 2,
> +                              GL_FLOAT, GL_FALSE,
> +                              2 * sizeof(float), vbo_offset);
> +
> +        glVertexAttribPointer(GLAMOR_VERTEX_SOURCE, 2,
> +                              GL_FLOAT, GL_FALSE,
> +                              2 * sizeof(float), vbo_offset + 8 * sizeof(GLfloat));
>  
>          glScissor(dstx, dsty, dstw, dsth);
>          glDrawArrays(GL_TRIANGLE_FAN, 0, 3);
> +        vbo_offset += 16 * sizeof(GLfloat);

You could move the pointer setup out of the loop, s/0/i * 4/ in
glDrawArrays(), and then drop the vbo_offset math, I think.  With that
changed, the first two are:

Reviewed-by: Eric Anholt <eric at anholt.net>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg-devel/attachments/20160118/048bfcd8/attachment.sig>


More information about the xorg-devel mailing list