[clutter/wip/pango-share-atlas: 8/14] cogl-pango-render: Add the base texture to the display list



commit 9cb45144a89e03baa746fa62ccd5972378baee08
Author: Neil Roberts <neil linux intel com>
Date:   Wed Mar 30 13:48:34 2011 +0100

    cogl-pango-render: Add the base texture to the display list
    
    When rendering a glyph from a texture, instead of adding the glyph's
    texture handle to the display list it now retrieves the base texture
    using _cogl_texture_foreach_subtexture_in_region and adds that
    instead. That way the display can recognise that glyphs in the global
    atlas are sharing the same texture and combine them into one VBO.

 clutter/cogl/pango/cogl-pango-render.c |   62 ++++++++++++++++++++++++++------
 1 files changed, 51 insertions(+), 11 deletions(-)
---
diff --git a/clutter/cogl/pango/cogl-pango-render.c b/clutter/cogl/pango/cogl-pango-render.c
index 3af154a..0d6f477 100644
--- a/clutter/cogl/pango/cogl-pango-render.c
+++ b/clutter/cogl/pango/cogl-pango-render.c
@@ -35,6 +35,7 @@
 #include <cairo.h>
 
 #include "cogl/cogl-debug.h"
+#include "cogl/cogl-texture-private.h"
 #include "cogl-pango-private.h"
 #include "cogl-pango-glyph-cache.h"
 #include "cogl-pango-display-list.h"
@@ -85,26 +86,65 @@ struct _CoglPangoRendererQdata
 static void
 _cogl_pango_ensure_glyph_cache_for_layout_line (PangoLayoutLine *line);
 
+typedef struct
+{
+  CoglPangoDisplayList *display_list;
+  float x1, y1, x2, y2;
+} CoglPangoRendererSliceCbData;
+
+void
+cogl_pango_renderer_slice_cb (CoglHandle handle,
+                              const float *slice_coords,
+                              const float *virtual_coords,
+                              void *user_data)
+{
+  CoglPangoRendererSliceCbData *data = user_data;
+
+  /* Note: this assumes that there is only one slice containing the
+     whole texture and it doesn't attempt to split up the vertex
+     coordinates based on the virtual_coords */
+
+  _cogl_pango_display_list_add_texture (data->display_list,
+                                        handle,
+                                        data->x1,
+                                        data->y1,
+                                        data->x2,
+                                        data->y2,
+                                        slice_coords[0],
+                                        slice_coords[1],
+                                        slice_coords[2],
+                                        slice_coords[3]);
+}
+
 static void
 cogl_pango_renderer_draw_glyph (CoglPangoRenderer        *priv,
                                 CoglPangoGlyphCacheValue *cache_value,
                                 float                     x1,
                                 float                     y1)
 {
-  float x2, y2;
+  CoglPangoRendererSliceCbData data;
 
   g_return_if_fail (priv->display_list != NULL);
 
-  x2 = x1 + (float) cache_value->draw_width;
-  y2 = y1 + (float) cache_value->draw_height;
-
-  _cogl_pango_display_list_add_texture (priv->display_list,
-                                        cache_value->texture,
-                                        x1, y1, x2, y2,
-                                        cache_value->tx1,
-                                        cache_value->ty1,
-                                        cache_value->tx2,
-                                        cache_value->ty2);
+  data.display_list = priv->display_list;
+  data.x1 = x1;
+  data.y1 = y1;
+  data.x2 = x1 + (float) cache_value->draw_width;
+  data.y2 = y1 + (float) cache_value->draw_height;
+
+  /* We iterate the internal sub textures of the texture so that we
+     can get a pointer to the base texture even if the texture is in
+     the global atlas. That way the display list can recognise that
+     the neighbouring glyphs are coming from the same atlas and bundle
+     them together into a single VBO */
+
+  _cogl_texture_foreach_sub_texture_in_region (cache_value->texture,
+                                               cache_value->tx1,
+                                               cache_value->ty1,
+                                               cache_value->tx2,
+                                               cache_value->ty2,
+                                               cogl_pango_renderer_slice_cb,
+                                               &data);
 }
 
 static void cogl_pango_renderer_finalize (GObject *object);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]