Fix various failures to propagate ComputedOutlineDepth.

This commit is contained in:
Robin KAY 2023-05-17 18:43:12 +01:00
parent 3bf83e6531
commit ac9ae75cef
2 changed files with 29 additions and 20 deletions

View File

@ -7,6 +7,7 @@ use crate::uniforms::DepthMode;
pub struct ComputedOutlineDepth { pub struct ComputedOutlineDepth {
pub(crate) world_origin: Vec3, pub(crate) world_origin: Vec3,
pub(crate) depth_mode: DepthMode, pub(crate) depth_mode: DepthMode,
pub(crate) inherited: Option<Entity>,
} }
/// A component which specifies how the outline depth should be computed. /// A component which specifies how the outline depth should be computed.
@ -27,23 +28,25 @@ pub struct InheritOutlineDepth;
pub(crate) fn compute_outline_depth( pub(crate) fn compute_outline_depth(
mut root_query: Query< mut root_query: Query<
( (
Entity,
&mut ComputedOutlineDepth, &mut ComputedOutlineDepth,
&GlobalTransform, &GlobalTransform,
Changed<GlobalTransform>, Changed<GlobalTransform>,
Option<(&SetOutlineDepth, Changed<SetOutlineDepth>)>, Option<(&SetOutlineDepth, Changed<SetOutlineDepth>)>,
Option<(&Children, Changed<Children>)>, Option<&Children>,
), ),
Without<InheritOutlineDepth>, Without<InheritOutlineDepth>,
>, >,
mut computed_query: Query< mut computed_query: Query<&mut ComputedOutlineDepth, With<InheritOutlineDepth>>,
(&mut ComputedOutlineDepth, Changed<InheritOutlineDepth>), child_query: Query<&Children>,
With<InheritOutlineDepth>,
>,
child_query: Query<(&Children, Changed<Children>)>,
) { ) {
for (mut computed, transform, changed_transform, set_depth, children) in root_query.iter_mut() { for (entity, mut computed, transform, changed_transform, set_depth, children) in
let mut changed = root_query.iter_mut()
computed.is_added() || changed_transform || set_depth.filter(|(_, c)| *c).is_some(); {
let changed = !computed.depth_mode.is_valid()
|| computed.inherited.is_some()
|| changed_transform
|| set_depth.filter(|(_, c)| *c).is_some();
if changed { if changed {
let (origin, depth_mode) = if let Some((sd, _)) = set_depth { let (origin, depth_mode) = if let Some((sd, _)) = set_depth {
match sd { match sd {
@ -58,13 +61,14 @@ pub(crate) fn compute_outline_depth(
let matrix = transform.compute_matrix(); let matrix = transform.compute_matrix();
computed.world_origin = matrix.project_point3(origin); computed.world_origin = matrix.project_point3(origin);
computed.depth_mode = depth_mode; computed.depth_mode = depth_mode;
computed.inherited = None;
} }
if let Some((cs, changed_children)) = children { if let Some(cs) = children {
changed |= changed_children;
for child in cs.iter() { for child in cs.iter() {
propagate_outline_depth( propagate_outline_depth(
&computed, &computed,
changed, changed,
entity,
*child, *child,
&mut computed_query, &mut computed_query,
&child_query, &child_query,
@ -77,24 +81,23 @@ pub(crate) fn compute_outline_depth(
fn propagate_outline_depth( fn propagate_outline_depth(
root_computed: &ComputedOutlineDepth, root_computed: &ComputedOutlineDepth,
mut changed: bool, mut changed: bool,
parent: Entity,
entity: Entity, entity: Entity,
computed_query: &mut Query< computed_query: &mut Query<&mut ComputedOutlineDepth, With<InheritOutlineDepth>>,
(&mut ComputedOutlineDepth, Changed<InheritOutlineDepth>), child_query: &Query<&Children>,
With<InheritOutlineDepth>,
>,
child_query: &Query<(&Children, Changed<Children>)>,
) { ) {
if let Ok((mut computed, changed_inherit)) = computed_query.get_mut(entity) { if let Ok(mut computed) = computed_query.get_mut(entity) {
changed |= changed_inherit; changed |= !computed.depth_mode.is_valid() | (computed.inherited != Some(parent));
if changed { if changed {
*computed = root_computed.clone(); *computed = root_computed.clone();
computed.inherited = Some(parent);
} }
if let Ok((cs, changed_children)) = child_query.get(entity) { if let Ok(cs) = child_query.get(entity) {
changed |= changed_children;
for child in cs.iter() { for child in cs.iter() {
propagate_outline_depth( propagate_outline_depth(
root_computed, root_computed,
changed, changed,
entity,
*child, *child,
computed_query, computed_query,
child_query, child_query,

View File

@ -46,6 +46,12 @@ pub(crate) enum DepthMode {
Real = 2, Real = 2,
} }
impl DepthMode {
pub fn is_valid(&self) -> bool {
*self != DepthMode::Invalid
}
}
#[derive(Component)] #[derive(Component)]
pub(crate) struct OutlineStencilFlags { pub(crate) struct OutlineStencilFlags {
pub depth_mode: DepthMode, pub depth_mode: DepthMode,