cogl-primitives: Ensure the mipmaps for a layer before logging quads
authorNeil Roberts <neil@linux.intel.com>
Thu, 14 Jan 2010 17:57:43 +0000 (17:57 +0000)
committerNeil Roberts <neil@linux.intel.com>
Mon, 18 Jan 2010 09:22:11 +0000 (09:22 +0000)
With the atlas texture backend ensuring the mipmaps can make it become
a completely different texture which will have different texture
coordinates or may even be sliced. Therefore we need to ensure the
mipmaps before deciding which quads to log in the journal. This adds a
new private function to cogl-material which ensures the mipmaps if
needed.

clutter/cogl/cogl/cogl-material-private.h
clutter/cogl/cogl/cogl-material.c
clutter/cogl/cogl/cogl-primitives.c

index c70ea30..a9cf77a 100644 (file)
@@ -205,6 +205,12 @@ typedef enum _CoglMaterialLayerFlags
 gulong _cogl_material_layer_get_flags (CoglHandle layer_handle);
 
 /*
+ * Ensures the mipmaps are available for the texture in the layer if
+ * the filter settings would require it
+ */
+void _cogl_material_layer_ensure_mipmaps (CoglHandle layer_handler);
+
+/*
  * CoglMaterialFlushFlag:
  * @COGL_MATERIAL_FLUSH_FALLBACK_MASK: The fallback_layers member is set to
  *      a guint32 mask of the layers that can't be supported with the user
index 48de2a7..35e898f 100644 (file)
@@ -1326,6 +1326,19 @@ _cogl_material_layer_flush_gl_sampler_state (CoglMaterialLayer  *layer,
   _cogl_matrix_stack_flush_to_gl (unit->matrix_stack, COGL_MATRIX_TEXTURE);
 }
 
+void
+_cogl_material_layer_ensure_mipmaps (CoglHandle layer_handle)
+{
+  CoglMaterialLayer *layer;
+
+  layer = _cogl_material_layer_pointer_from_handle (layer_handle);
+
+  if (layer->texture &&
+      (is_mipmap_filter (layer->min_filter) ||
+       is_mipmap_filter (layer->mag_filter)))
+    _cogl_texture_ensure_mipmaps (layer->texture);
+}
+
 /*
  * _cogl_material_flush_layers_gl_state:
  * @fallback_mask: is a bitmask of the material layers that need to be
@@ -1397,6 +1410,8 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
 #endif
       CoglTextureUnit   *unit;
 
+      _cogl_material_layer_ensure_mipmaps (layer_handle);
+
       new_gl_layer_info.layer0_overridden =
         layer0_override_texture ? TRUE : FALSE;
       new_gl_layer_info.fallback =
@@ -1407,10 +1422,6 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material,
       tex_handle = layer->texture;
       if (tex_handle != COGL_INVALID_HANDLE)
         {
-          if (is_mipmap_filter (layer->min_filter)
-              || is_mipmap_filter (layer->mag_filter))
-            _cogl_texture_ensure_mipmaps (tex_handle);
-
           _cogl_texture_set_filters (tex_handle,
                                      layer->min_filter,
                                      layer->mag_filter);
index 1215725..726ceba 100644 (file)
@@ -401,6 +401,12 @@ _cogl_rectangles_with_multitexture_coords (
          != COGL_MATERIAL_LAYER_TYPE_TEXTURE)
        continue;
 
+      /* We need to ensure the mipmaps are ready before deciding
+         anything else about the texture because it could become
+         something completely different if it needs to be migrated out
+         of the atlas */
+      _cogl_material_layer_ensure_mipmaps (layer);
+
       tex_handle = cogl_material_layer_get_texture (layer);
 
       /* COGL_INVALID_HANDLE textures are handled by