From 8afa008ec4b393666bb3c506a711b4d50cc4e756 Mon Sep 17 00:00:00 2001 From: Grigori Goronzy Date: Wed, 2 Oct 2013 00:37:55 +0200 Subject: Use glDrawRangeElements instead of glDrawElements This lets us explicitly specify the range of vertices that are used, which the OpenGL driver can use for optimization. Particularly, it results in lower CPU overhead with Mesa-based drivers. Reviewed-by: Alex Deucher Reviewed-by: Zhigang Gong --- glamor/glamor_fill.c | 9 +++++++++ glamor/glamor_gl_dispatch.c | 1 + glamor/glamor_gl_dispatch.h | 1 + glamor/glamor_render.c | 6 ++++++ glamor/glamor_trapezoid.c | 6 ++++++ 5 files changed, 23 insertions(+) (limited to 'glamor') diff --git a/glamor/glamor_fill.c b/glamor/glamor_fill.c index 2f08d7275..fbc87392e 100644 --- a/glamor/glamor_fill.c +++ b/glamor/glamor_fill.c @@ -244,10 +244,19 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color) if (box_cnt == 1) dispatch->glDrawArrays(GL_TRIANGLE_FAN, 0, box_cnt * 4); else +#ifndef GLAMOR_GLES2 + dispatch->glDrawRangeElements(GL_TRIANGLES, + 0, + box_cnt * 4, + box_cnt * 6, + GL_UNSIGNED_SHORT, + NULL); +#else dispatch->glDrawElements(GL_TRIANGLES, box_cnt * 6, GL_UNSIGNED_SHORT, NULL); +#endif nbox -= box_cnt; box += box_cnt; } diff --git a/glamor/glamor_gl_dispatch.c b/glamor/glamor_gl_dispatch.c index f99650425..da99e2627 100644 --- a/glamor/glamor_gl_dispatch.c +++ b/glamor/glamor_gl_dispatch.c @@ -54,6 +54,7 @@ glamor_gl_dispatch_init_impl(struct glamor_gl_dispatch *dispatch, INIT_FUNC(dispatch, glMapBufferRange, get_proc_address); INIT_FUNC(dispatch, glUnmapBuffer, get_proc_address); INIT_FUNC(dispatch, glBlitFramebuffer, get_proc_address); + INIT_FUNC(dispatch, glDrawRangeElements, get_proc_address); #endif INIT_FUNC(dispatch, glViewport, get_proc_address); INIT_FUNC(dispatch, glDrawArrays, get_proc_address); diff --git a/glamor/glamor_gl_dispatch.h b/glamor/glamor_gl_dispatch.h index b3fc3a629..76dadd49e 100644 --- a/glamor/glamor_gl_dispatch.h +++ b/glamor/glamor_gl_dispatch.h @@ -12,6 +12,7 @@ typedef struct glamor_gl_dispatch { /* Elements Array*/ void (*glDrawElements) (GLenum mode, GLsizei count, GLenum type, const GLvoid * indices); + void (*glDrawRangeElements) (GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid * indices); /* Raster functions */ void (*glReadPixels) (GLint x, GLint y, diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c index 27d5dc58c..d2ac38103 100644 --- a/glamor/glamor_render.c +++ b/glamor/glamor_render.c @@ -841,8 +841,14 @@ glamor_flush_composite_rects(ScreenPtr screen) if (!glamor_priv->render_nr_verts) return; +#ifndef GLAMOR_GLES2 + dispatch->glDrawRangeElements(GL_TRIANGLES, 0, glamor_priv->render_nr_verts, + (glamor_priv->render_nr_verts * 3) / 2, + GL_UNSIGNED_SHORT, NULL); +#else dispatch->glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2, GL_UNSIGNED_SHORT, NULL); +#endif glamor_put_dispatch(glamor_priv); } diff --git a/glamor/glamor_trapezoid.c b/glamor/glamor_trapezoid.c index 7c934e346..76b3729cf 100644 --- a/glamor/glamor_trapezoid.c +++ b/glamor/glamor_trapezoid.c @@ -1543,8 +1543,14 @@ _glamor_generate_trapezoid_with_shader(ScreenPtr screen, PicturePtr picture, glamor_priv->vb, GL_DYNAMIC_DRAW); } +#ifndef GLAMOR_GLES2 + dispatch->glDrawRangeElements(GL_TRIANGLES, 0, glamor_priv->render_nr_verts, + (glamor_priv->render_nr_verts * 3) / 2, + GL_UNSIGNED_SHORT, NULL); +#else dispatch->glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2, GL_UNSIGNED_SHORT, NULL); +#endif } dispatch->glBindBuffer(GL_ARRAY_BUFFER, 0); -- cgit v1.2.3