[PATCH 04/15] glamor: Drop a bunch of GLES2 ifdefs.

Eric Anholt eric at anholt.net
Mon Feb 3 20:03:29 CET 2014


Now that we're using epoxy, we can write code using both desktop and
ES symbols and decide what to use at runtime.

Signed-off-by: Eric Anholt <eric at anholt.net>
---
 glamor/glamor.c           | 40 +++++++++++++++++++---------------------
 glamor/glamor_copyarea.c  | 15 ++++++---------
 glamor/glamor_fill.c      | 16 +++++++++-------
 glamor/glamor_render.c    | 34 ++++++++++++++++++----------------
 glamor/glamor_trapezoid.c | 20 ++++++++++----------
 5 files changed, 62 insertions(+), 63 deletions(-)

diff --git a/glamor/glamor.c b/glamor/glamor.c
index ba2a1f4..a91c3ff 100644
--- a/glamor/glamor.c
+++ b/glamor/glamor.c
@@ -329,26 +329,29 @@ glamor_init(ScreenPtr screen, unsigned int flags)
         goto fail;;
     }
 
+    if (epoxy_is_desktop_gl())
+        glamor_priv->gl_flavor = GLAMOR_GL_DESKTOP;
+    else
+        glamor_priv->gl_flavor = GLAMOR_GL_ES2;
+
     gl_version = glamor_gl_get_version();
 
-#ifndef GLAMOR_GLES2
-    if (gl_version < GLAMOR_GL_VERSION_ENCODE(1, 3)) {
-        ErrorF("Require OpenGL version 1.3 or latter.\n");
-        goto fail;
-    }
-#else
-    if (gl_version < GLAMOR_GL_VERSION_ENCODE(2, 0)) {
-        ErrorF("Require Open GLES2.0 or latter.\n");
-        goto fail;
-    }
-#endif
+    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+        if (gl_version < GLAMOR_GL_VERSION_ENCODE(1, 3)) {
+            ErrorF("Require OpenGL version 1.3 or latter.\n");
+            goto fail;
+        }
+    } else {
+        if (gl_version < GLAMOR_GL_VERSION_ENCODE(2, 0)) {
+            ErrorF("Require Open GLES2.0 or latter.\n");
+            goto fail;
+        }
 
-#ifdef GLAMOR_GLES2
-    if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) {
-        ErrorF("GL_EXT_texture_format_BGRA8888 required\n");
-        goto fail;
+        if (!glamor_gl_has_extension("GL_EXT_texture_format_BGRA8888")) {
+            ErrorF("GL_EXT_texture_format_BGRA8888 required\n");
+            goto fail;
+        }
     }
-#endif
 
     glamor_priv->has_pack_invert =
         glamor_gl_has_extension("GL_MESA_pack_invert");
@@ -361,11 +364,6 @@ glamor_init(ScreenPtr screen, unsigned int flags)
 
     glamor_set_debug_level(&glamor_debug_level);
 
-#ifdef GLAMOR_GLES2
-    glamor_priv->gl_flavor = GLAMOR_GL_ES2;
-#else
-    glamor_priv->gl_flavor = GLAMOR_GL_DESKTOP;
-#endif
     /* If we are using egl screen, call egl screen init to
      * register correct close screen function. */
     if (flags & GLAMOR_USE_EGL_SCREEN) {
diff --git a/glamor/glamor_copyarea.c b/glamor/glamor_copyarea.c
index 498a06e..8cc7cad 100644
--- a/glamor/glamor_copyarea.c
+++ b/glamor/glamor_copyarea.c
@@ -31,7 +31,6 @@
  *
  * GC CopyArea implementation
  */
-#ifndef GLAMOR_GLES2
 static Bool
 glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
                             DrawablePtr dst,
@@ -117,7 +116,6 @@ glamor_copy_n_to_n_fbo_blit(DrawablePtr src,
     glamor_priv->state = BLIT_STATE;
     return TRUE;
 }
-#endif
 
 static Bool
 glamor_copy_n_to_n_textured(DrawablePtr src,
@@ -170,10 +168,10 @@ glamor_copy_n_to_n_textured(DrawablePtr src,
 
     glActiveTexture(GL_TEXTURE0);
     glBindTexture(GL_TEXTURE_2D, src_pixmap_priv->base.fbo->tex);
-#ifndef GLAMOR_GLES2
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
-    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
-#endif
+    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
+    }
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
@@ -266,15 +264,14 @@ __glamor_copy_n_to_n(DrawablePtr src,
            box[0].x1, box[0].y1,
            box[0].x2 - box[0].x1, box[0].y2 - box[0].y1,
            dx, dy, src_pixmap, dst_pixmap);
-#ifndef GLAMOR_GLES2
-    if (!overlaped &&
+    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP &&
+        !overlaped &&
         (glamor_priv->state != RENDER_STATE
          || !src_pixmap_priv->base.gl_tex || !dst_pixmap_priv->base.gl_tex)
         && glamor_copy_n_to_n_fbo_blit(src, dst, gc, box, nbox, dx, dy)) {
         ret = TRUE;
         goto done;
     }
-#endif
     glamor_calculate_boxes_bound(&bound, box, nbox);
 
     /*  Overlaped indicate the src and dst are the same pixmap. */
diff --git a/glamor/glamor_fill.c b/glamor/glamor_fill.c
index c9bd519..d1c16ad 100644
--- a/glamor/glamor_fill.c
+++ b/glamor/glamor_fill.c
@@ -240,13 +240,15 @@ _glamor_solid_boxes(PixmapPtr pixmap, BoxPtr box, int nbox, float *color)
         }
         if (box_cnt == 1)
             glDrawArrays(GL_TRIANGLE_FAN, 0, box_cnt * 4);
-        else
-#ifndef GLAMOR_GLES2
-            glDrawRangeElements(GL_TRIANGLES, 0, box_cnt * 4, box_cnt * 6,
-                                GL_UNSIGNED_SHORT, NULL);
-#else
-            glDrawElements(GL_TRIANGLES, box_cnt * 6, GL_UNSIGNED_SHORT, NULL);
-#endif
+        else {
+            if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+                glDrawRangeElements(GL_TRIANGLES, 0, box_cnt * 4, box_cnt * 6,
+                                    GL_UNSIGNED_SHORT, NULL);
+            } else {
+                glDrawElements(GL_TRIANGLES, box_cnt * 6, GL_UNSIGNED_SHORT,
+                               NULL);
+            }
+        }
         nbox -= box_cnt;
         box += box_cnt;
     }
diff --git a/glamor/glamor_render.c b/glamor/glamor_render.c
index ecc4606..cad0c53 100644
--- a/glamor/glamor_render.c
+++ b/glamor/glamor_render.c
@@ -535,14 +535,16 @@ glamor_set_composite_texture(glamor_screen_private *glamor_priv, int unit,
     repeat_type = picture->repeatType;
     switch (picture->repeatType) {
     case RepeatNone:
-#ifndef GLAMOR_GLES2
-        /* XXX  GLES2 doesn't support GL_CLAMP_TO_BORDER. */
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
-#else
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
-        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-#endif
+        if (glamor_priv->gl_flavor == GLAMOR_GL_ES2) {
+            /* XXX  GLES2 doesn't support GL_CLAMP_TO_BORDER. */
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
+                            GL_CLAMP_TO_BORDER);
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
+                            GL_CLAMP_TO_BORDER);
+        } else {
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+        }
         break;
     case RepeatNormal:
         glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
@@ -807,14 +809,14 @@ glamor_flush_composite_rects(ScreenPtr screen)
     if (!glamor_priv->render_nr_verts)
         return;
 
-#ifndef GLAMOR_GLES2
-    glDrawRangeElements(GL_TRIANGLES, 0, glamor_priv->render_nr_verts,
-                        (glamor_priv->render_nr_verts * 3) / 2,
-                        GL_UNSIGNED_SHORT, NULL);
-#else
-    glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2,
-                   GL_UNSIGNED_SHORT, NULL);
-#endif
+    if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+        glDrawRangeElements(GL_TRIANGLES, 0, glamor_priv->render_nr_verts,
+                            (glamor_priv->render_nr_verts * 3) / 2,
+                            GL_UNSIGNED_SHORT, NULL);
+    } else {
+        glDrawElements(GL_TRIANGLES, (glamor_priv->render_nr_verts * 3) / 2,
+                       GL_UNSIGNED_SHORT, NULL);
+    }
     glamor_put_context(glamor_priv);
 }
 
diff --git a/glamor/glamor_trapezoid.c b/glamor/glamor_trapezoid.c
index e64c19d..7bc925a 100644
--- a/glamor/glamor_trapezoid.c
+++ b/glamor/glamor_trapezoid.c
@@ -1554,16 +1554,16 @@ _glamor_generate_trapezoid_with_shader(ScreenPtr screen, PicturePtr picture,
                          glamor_priv->vb, GL_DYNAMIC_DRAW);
         }
 
-#ifndef GLAMOR_GLES2
-        glDrawRangeElements(GL_TRIANGLES, 0,
-                            glamor_priv->render_nr_verts,
-                            (glamor_priv->render_nr_verts * 3) / 2,
-                            GL_UNSIGNED_SHORT, NULL);
-#else
-        glDrawElements(GL_TRIANGLES,
-                       (glamor_priv->render_nr_verts * 3) / 2,
-                       GL_UNSIGNED_SHORT, NULL);
-#endif
+        if (glamor_priv->gl_flavor == GLAMOR_GL_DESKTOP) {
+            glDrawRangeElements(GL_TRIANGLES, 0,
+                                glamor_priv->render_nr_verts,
+                                (glamor_priv->render_nr_verts * 3) / 2,
+                                GL_UNSIGNED_SHORT, NULL);
+        } else {
+            glDrawElements(GL_TRIANGLES,
+                           (glamor_priv->render_nr_verts * 3) / 2,
+                           GL_UNSIGNED_SHORT, NULL);
+        }
     }
 
     glBindBuffer(GL_ARRAY_BUFFER, 0);
-- 
1.9.rc1



More information about the xorg-devel mailing list