From 9e9fcf578063b4155aab4adab83f8d956bde5d1a Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 4 Feb 2015 14:38:15 -0800 Subject: [PATCH] glamor: Add a helper function for the common GL_QUADS fallback pattern. We should do better than this with an index buffer, but for now at least make it so that we don't have to copy the same code to new places. Signed-off-by: Eric Anholt Reviewed-by: Keith Packard --- glamor/glamor_copy.c | 8 +------- glamor/glamor_rects.c | 9 +-------- glamor/glamor_spans.c | 9 +-------- glamor/glamor_utils.h | 17 +++++++++++++++++ 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/glamor/glamor_copy.c b/glamor/glamor_copy.c index 2ea270c4b..e2d52041f 100644 --- a/glamor/glamor_copy.c +++ b/glamor/glamor_copy.c @@ -387,13 +387,7 @@ glamor_copy_fbo_fbo_draw(DrawablePtr src, src_box->x2 - src_box->x1, src_box->y2 - src_box->y1); - if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) - glDrawArrays(GL_QUADS, 0, nbox * 4); - else { - int i; - for (i = 0; i < nbox; i++) - glDrawArrays(GL_TRIANGLE_FAN, i*4, 4); - } + glamor_glDrawArrays_GL_QUADS(glamor_priv, nbox); } } glDisable(GL_SCISSOR_TEST); diff --git a/glamor/glamor_rects.c b/glamor/glamor_rects.c index c8c92be17..c378e4a30 100644 --- a/glamor/glamor_rects.c +++ b/glamor/glamor_rects.c @@ -126,14 +126,7 @@ glamor_poly_fill_rect_gl(DrawablePtr drawable, if (glamor_priv->glsl_version >= 130) glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, nrect); else { - if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { - glDrawArrays(GL_QUADS, 0, nrect * 4); - } else { - int i; - for (i = 0; i < nrect; i++) { - glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); - } - } + glamor_glDrawArrays_GL_QUADS(glamor_priv, nrect); } } } diff --git a/glamor/glamor_spans.c b/glamor/glamor_spans.c index 7138db5a0..b358c60bd 100644 --- a/glamor/glamor_spans.c +++ b/glamor/glamor_spans.c @@ -134,14 +134,7 @@ glamor_fill_spans_gl(DrawablePtr drawable, if (glamor_priv->glsl_version >= 130) glDrawArraysInstanced(GL_TRIANGLE_STRIP, 0, 4, n); else { - if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { - glDrawArrays(GL_QUADS, 0, 4 * n); - } else { - int i; - for (i = 0; i < n; i++) { - glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); - } - } + glamor_glDrawArrays_GL_QUADS(glamor_priv, nbox); } } } diff --git a/glamor/glamor_utils.h b/glamor/glamor_utils.h index 6a3bd2942..0927ffb06 100644 --- a/glamor/glamor_utils.h +++ b/glamor/glamor_utils.h @@ -1393,4 +1393,21 @@ glamor_make_current(glamor_screen_private *glamor_priv) } } +/** + * Helper function for implementing draws with GL_QUADS on GLES2, + * where we don't have them. + */ +static inline void +glamor_glDrawArrays_GL_QUADS(glamor_screen_private *glamor_priv, unsigned count) +{ + if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) { + glDrawArrays(GL_QUADS, 0, count * 4); + } else { + unsigned i; + for (i = 0; i < count; i++) + glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); + } +} + + #endif