diff --git a/cogl/cogl-material-private.h b/cogl/cogl-material-private.h index c70ea304f..a9cf77a17 100644 --- a/cogl/cogl-material-private.h +++ b/cogl/cogl-material-private.h @@ -204,6 +204,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 diff --git a/cogl/cogl-material.c b/cogl/cogl-material.c index 48de2a77d..35e898f77 100644 --- a/cogl/cogl-material.c +++ b/cogl/cogl-material.c @@ -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); diff --git a/cogl/cogl-primitives.c b/cogl/cogl-primitives.c index 1215725ec..726cebaf4 100644 --- a/cogl/cogl-primitives.c +++ b/cogl/cogl-primitives.c @@ -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