[pango-display-list] Use indexed vertices on GLES
authorNeil Roberts <neil@linux.intel.com>
Fri, 29 May 2009 10:38:03 +0000 (11:38 +0100)
committerNeil Roberts <neil@linux.intel.com>
Mon, 1 Jun 2009 13:50:52 +0000 (14:50 +0100)
Now that CoglVertexBuffers support indices we can use them with GLES
to avoid duplicating vertices. Regular GL still uses GL_QUADS because
it is shown to still have a performance benefit over indices with the
Intel drivers.

clutter/pango/cogl-pango-display-list.c

index b87b609..6d46fa8 100644 (file)
@@ -41,13 +41,6 @@ typedef enum
 typedef struct _CoglPangoDisplayListNode CoglPangoDisplayListNode;
 typedef struct _CoglPangoDisplayListVertex CoglPangoDisplayListVertex;
 
-#ifdef HAVE_CLUTTER_GLX
-#define COGL_PANGO_DISPLAY_LIST_DRAW_MODE GL_QUADS
-#else
-/* GLES doesn't support GL_QUADS so we use GL_TRIANGLES instead */
-#define COGL_PANGO_DISPLAY_LIST_DRAW_MODE GL_TRIANGLES
-#endif
-
 struct _CoglPangoDisplayList
 {
   CoglColor  color;
@@ -184,24 +177,6 @@ _cogl_pango_display_list_add_texture (CoglPangoDisplayList *dl,
   verts->y = y_1;
   verts->t_x = tx_2;
   verts->t_y = ty_1;
-
-#ifndef HAVE_CLUTTER_GLX
-
-  /* GLES doesn't support GL_QUADS so we use GL_TRIANGLES instead with
-     two extra vertices per quad. FIXME: It might be better to use
-     indexed elements here but cogl vertex buffers don't currently
-     support storing the indices */
-
-  g_array_set_size (node->d.texture.verts,
-                    node->d.texture.verts->len + 2);
-  verts = &g_array_index (node->d.texture.verts,
-                          CoglPangoDisplayListVertex,
-                          node->d.texture.verts->len - 6);
-
-  verts[4] = verts[0];
-  verts[5] = verts[2];
-
-#endif /* HAVE_CLUTTER_GLX */
 }
 
 void
@@ -270,9 +245,29 @@ _cogl_pango_display_list_render_texture (CoglHandle material,
       node->d.texture.vertex_buffer = vb;
     }
 
+
+#ifdef CLUTTER_COGL_HAS_GL
+
   cogl_vertex_buffer_draw (node->d.texture.vertex_buffer,
-                           COGL_PANGO_DISPLAY_LIST_DRAW_MODE,
+                           GL_QUADS,
                            0, node->d.texture.verts->len);
+
+#else /* CLUTTER_COGL_HAS_GL */
+  {
+    /* GLES doesn't support GL_QUADS so instead we use a VBO with
+       indexed vertices to generate GL_TRIANGLES from the quads */
+
+    int n_indices = node->d.texture.verts->len / 4 * 6;
+    CoglHandle indices_vbo
+      = cogl_vertex_buffer_indices_get_for_quads (n_indices);
+
+    cogl_vertex_buffer_draw_elements (node->d.texture.vertex_buffer,
+                                      COGL_VERTICES_MODE_TRIANGLES,
+                                      indices_vbo,
+                                      0, node->d.texture.verts->len - 1,
+                                      0, n_indices);
+  }
+#endif /* CLUTTER_COGL_HAS_GL */
 }
 
 void