[PATCH 3/3] glamor: Add a helper function for the common GL_QUADS fallback pattern.
Eric Anholt
eric at anholt.net
Wed Feb 4 17:25:12 PST 2015
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 <eric at anholt.net>
---
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 2ea270c..e2d5204 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 c8c92be..c378e4a 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 7138db5..b358c60 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 6a3bd29..0927ffb 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
--
2.1.4
More information about the xorg-devel
mailing list