Skip to content

Commit

Permalink
Fix UI borders (bevyengine#10078)
Browse files Browse the repository at this point in the history
# Objective

Fixes bevyengine#10069

## Solution

Extracted UI nodes were previously stored in a `SparseSet` and had a
predictable iteration order. UI borders and outlines relied on this. Now
they are stored in a HashMap and that is no longer true.

This adds `entity.index()` to the sort key for `TransparentUi` so that
the iteration order is predictable and the "border entities" that get
spawned during extraction are guaranteed to get drawn after their
respective container nodes again.

I **think** that everything still works for overlapping ui nodes etc,
because the z value / primary sort is still controlled by the "ui
stack."

Text above is just my current understanding. A rendering expert should
check this out.

I will do some more testing when I can.
  • Loading branch information
rparrett authored and ameknite committed Nov 6, 2023
1 parent f6baf03 commit 3ca672f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion crates/bevy_ui/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,10 @@ pub fn queue_uinodes(
draw_function,
pipeline,
entity: *entity,
sort_key: FloatOrd(extracted_uinode.stack_index as f32),
sort_key: (
FloatOrd(extracted_uinode.stack_index as f32),
entity.index(),
),
// batch_range will be calculated in prepare_uinodes
batch_range: 0..0,
dynamic_offset: None,
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_ui/src/render/render_pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl Node for UiPassNode {
}

pub struct TransparentUi {
pub sort_key: FloatOrd,
pub sort_key: (FloatOrd, u32),
pub entity: Entity,
pub pipeline: CachedRenderPipelineId,
pub draw_function: DrawFunctionId,
Expand All @@ -97,7 +97,7 @@ pub struct TransparentUi {
}

impl PhaseItem for TransparentUi {
type SortKey = FloatOrd;
type SortKey = (FloatOrd, u32);

#[inline]
fn entity(&self) -> Entity {
Expand Down

0 comments on commit 3ca672f

Please sign in to comment.