From 0e99fa7a1e0191328b0616b5a901fb1ab14dd1fb Mon Sep 17 00:00:00 2001 From: Robert Bragg Date: Mon, 13 Sep 2010 23:05:49 +0100 Subject: [PATCH] material: pass material owner for layer pre changes When notifying a backend about a layer being modified we now pass the layers current owner for reference. NB: Although a layer can indirectly be referenced by multiple layers, a layer is considered immutable once it has dependants, so there is only ever one material associated with a layer being modified. Passing the material pointer to the backends layer_pre_change callback can be useful for backends that associate their private state with materials and may need to update that state in response to layer changes. --- cogl/cogl-material-arbfp.c | 11 ++++++++++- cogl/cogl-material-private.h | 3 ++- cogl/cogl-material.c | 7 ++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/cogl/cogl-material-arbfp.c b/cogl/cogl-material-arbfp.c index 7a81a846d..e64234816 100644 --- a/cogl/cogl-material-arbfp.c +++ b/cogl/cogl-material-arbfp.c @@ -1073,10 +1073,19 @@ _cogl_material_backend_arbfp_material_set_parent_notify ( NULL); } +/* NB: layers are considered immutable once they have any dependants + * so although multiple materials can end up depending on a single + * static layer, we can guarantee that if a layer is being *changed* + * then it can only have one material depending on it. + * + * XXX: Don't forget this is *pre* change, we can't read the new value + * yet! + */ static void _cogl_material_backend_arbfp_layer_pre_change_notify ( + CoglMaterial *owner, CoglMaterialLayer *layer, - CoglMaterialLayerState changes) + CoglMaterialLayerState change) { /* TODO: we could be saving snippets of texture combine code along * with each layer and then when a layer changes we would just free diff --git a/cogl/cogl-material-private.h b/cogl/cogl-material-private.h index ca260c2ee..e5e62988e 100644 --- a/cogl/cogl-material-private.h +++ b/cogl/cogl-material-private.h @@ -557,7 +557,8 @@ typedef struct _CoglMaterialBackend CoglMaterialState change, const CoglColor *new_color); void (*material_set_parent_notify) (CoglMaterial *material); - void (*layer_pre_change_notify) (CoglMaterialLayer *layer, + void (*layer_pre_change_notify) (CoglMaterial *owner, + CoglMaterialLayer *layer, CoglMaterialLayerState change); void (*free_priv) (CoglMaterial *material); diff --git a/cogl/cogl-material.c b/cogl/cogl-material.c index a8ecf461a..557bcb217 100644 --- a/cogl/cogl-material.c +++ b/cogl/cogl-material.c @@ -1418,7 +1418,8 @@ _cogl_material_prune_to_n_layers (CoglMaterial *material, int n) } static void -_cogl_material_backend_layer_change_notify (CoglMaterialLayer *layer, +_cogl_material_backend_layer_change_notify (CoglMaterial *owner, + CoglMaterialLayer *layer, CoglMaterialLayerState change) { int i; @@ -1433,7 +1434,7 @@ _cogl_material_backend_layer_change_notify (CoglMaterialLayer *layer, _cogl_material_backends[i]->layer_pre_change_notify) { const CoglMaterialBackend *backend = _cogl_material_backends[i]; - backend->layer_pre_change_notify (layer, change); + backend->layer_pre_change_notify (owner, layer, change); } } } @@ -1594,7 +1595,7 @@ _cogl_material_layer_pre_change_notify (CoglMaterial *required_owner, * this layer (required_owner), and there are no other layers * dependant on this layer so it's ok to modify it. */ - _cogl_material_backend_layer_change_notify (layer, change); + _cogl_material_backend_layer_change_notify (required_owner, layer, change); /* If the layer being changed is the same as the last layer we * flushed to the corresponding texture unit then we keep a track of