From ac9ae75cef966119809cb54e828fda7f89f0dcbe Mon Sep 17 00:00:00 2001 From: Robin KAY Date: Wed, 17 May 2023 18:43:12 +0100 Subject: [PATCH] Fix various failures to propagate ComputedOutlineDepth. --- src/computed.rs | 43 +++++++++++++++++++++++-------------------- src/uniforms.rs | 6 ++++++ 2 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/computed.rs b/src/computed.rs index 69b6dfe..abce7d6 100644 --- a/src/computed.rs +++ b/src/computed.rs @@ -7,6 +7,7 @@ use crate::uniforms::DepthMode; pub struct ComputedOutlineDepth { pub(crate) world_origin: Vec3, pub(crate) depth_mode: DepthMode, + pub(crate) inherited: Option, } /// A component which specifies how the outline depth should be computed. @@ -27,23 +28,25 @@ pub struct InheritOutlineDepth; pub(crate) fn compute_outline_depth( mut root_query: Query< ( + Entity, &mut ComputedOutlineDepth, &GlobalTransform, Changed, Option<(&SetOutlineDepth, Changed)>, - Option<(&Children, Changed)>, + Option<&Children>, ), Without, >, - mut computed_query: Query< - (&mut ComputedOutlineDepth, Changed), - With, - >, - child_query: Query<(&Children, Changed)>, + mut computed_query: Query<&mut ComputedOutlineDepth, With>, + child_query: Query<&Children>, ) { - for (mut computed, transform, changed_transform, set_depth, children) in root_query.iter_mut() { - let mut changed = - computed.is_added() || changed_transform || set_depth.filter(|(_, c)| *c).is_some(); + for (entity, mut computed, transform, changed_transform, set_depth, children) in + root_query.iter_mut() + { + let changed = !computed.depth_mode.is_valid() + || computed.inherited.is_some() + || changed_transform + || set_depth.filter(|(_, c)| *c).is_some(); if changed { let (origin, depth_mode) = if let Some((sd, _)) = set_depth { match sd { @@ -58,13 +61,14 @@ pub(crate) fn compute_outline_depth( let matrix = transform.compute_matrix(); computed.world_origin = matrix.project_point3(origin); computed.depth_mode = depth_mode; + computed.inherited = None; } - if let Some((cs, changed_children)) = children { - changed |= changed_children; + if let Some(cs) = children { for child in cs.iter() { propagate_outline_depth( &computed, changed, + entity, *child, &mut computed_query, &child_query, @@ -77,24 +81,23 @@ pub(crate) fn compute_outline_depth( fn propagate_outline_depth( root_computed: &ComputedOutlineDepth, mut changed: bool, + parent: Entity, entity: Entity, - computed_query: &mut Query< - (&mut ComputedOutlineDepth, Changed), - With, - >, - child_query: &Query<(&Children, Changed)>, + computed_query: &mut Query<&mut ComputedOutlineDepth, With>, + child_query: &Query<&Children>, ) { - if let Ok((mut computed, changed_inherit)) = computed_query.get_mut(entity) { - changed |= changed_inherit; + if let Ok(mut computed) = computed_query.get_mut(entity) { + changed |= !computed.depth_mode.is_valid() | (computed.inherited != Some(parent)); if changed { *computed = root_computed.clone(); + computed.inherited = Some(parent); } - if let Ok((cs, changed_children)) = child_query.get(entity) { - changed |= changed_children; + if let Ok(cs) = child_query.get(entity) { for child in cs.iter() { propagate_outline_depth( root_computed, changed, + entity, *child, computed_query, child_query, diff --git a/src/uniforms.rs b/src/uniforms.rs index b72aa4c..3fc5e03 100644 --- a/src/uniforms.rs +++ b/src/uniforms.rs @@ -46,6 +46,12 @@ pub(crate) enum DepthMode { Real = 2, } +impl DepthMode { + pub fn is_valid(&self) -> bool { + *self != DepthMode::Invalid + } +} + #[derive(Component)] pub(crate) struct OutlineStencilFlags { pub depth_mode: DepthMode,