From 021265e634d4b6ee5fa279693e02d3976ef43feb Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Sun, 8 Aug 2010 13:41:15 +0100 Subject: [PATCH] material: fix initialization of sparse properties In _cogl_material_pre_change_notify we need to identify if it's a sparse property being changed and if so initialize the state group if the given material isn't currently the authority for it. Previously we were unconditionally calling _cogl_material_initialize_state which would e.g. NULL the layer differences list of a material each time a layer change was notified. It would also call _cogl_material_initialize_state for non-sparse properties which should always be valid at this point so the function has been renamed to _cogl_material_initialize_sparse_state to make this clearer with a corresponding g_return_if_fail check. --- cogl/cogl-material.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/cogl/cogl-material.c b/cogl/cogl-material.c index 0bc515e80..85a3ce8ee 100644 --- a/cogl/cogl-material.c +++ b/cogl/cogl-material.c @@ -916,13 +916,15 @@ check_for_blending_change: } static void -_cogl_material_initialize_state (CoglMaterial *dest, - CoglMaterial *src, - CoglMaterialState state) +_cogl_material_initialize_sparse_state (CoglMaterial *dest, + CoglMaterial *src, + CoglMaterialState state) { if (dest == src) return; + g_return_if_fail (state & COGL_MATERIAL_STATE_ALL_SPARSE); + if (state != COGL_MATERIAL_STATE_LAYERS) _cogl_material_copy_differences (dest, src, state); else @@ -1087,14 +1089,15 @@ _cogl_material_pre_change_notify (CoglMaterial *material, material->age++; - /* If the material isn't already an authority for the state group - * being modified then we need to initialize the corresponding - * state. */ - if (change & COGL_MATERIAL_STATE_ALL_SPARSE) - authority = _cogl_material_get_authority (material, change); - else - authority = material; - _cogl_material_initialize_state (material, authority, change); + /* If changing a sparse property and if the material isn't already an + * authority for the state group being modified then we need to + * initialize the corresponding state. */ + if (change & COGL_MATERIAL_STATE_ALL_SPARSE && + !(material->differences & change)) + { + authority = _cogl_material_get_authority (material, change); + _cogl_material_initialize_sparse_state (material, authority, change); + } /* Each material has a sorted cache of the layers it depends on * which will need updating via _cogl_material_update_layers_cache