Fix text2d view-visibility (#10100)
# Objective Fixes #9676 Possible alternative to #9708 `Text2dBundles` are not currently drawn because the render-world-only entities for glyphs that are created in `extract_text2d_sprite` are not tracked by the per-view `VisibleEntities`. ## Solution Add an `Option<Entity>` to `ExtractedSprite` that keeps track of the original entity that caused a "glyph entity" to be created. Use that in `queue_sprites` if it exists when checking view visibility. ## Benchmarks Quick benchmarks. Average FPS over 1500 frames. | bench | before fps | after fps | diff | |-|-|-|-| |many_sprites|884.93|879.00|🟡 -0.7%| |bevymark -- --benchmark --waves 100 --per-wave 1000 --mode sprite|75.99|75.93|🟡 -0.1%| |bevymark -- --benchmark --waves 50 --per-wave 1000 --mode mesh2d|32.85|32.58|🟡 -0.8%|
This commit is contained in:
parent
979c4094d4
commit
05c87f3c01
@ -325,6 +325,9 @@ pub struct ExtractedSprite {
|
||||
pub flip_x: bool,
|
||||
pub flip_y: bool,
|
||||
pub anchor: Vec2,
|
||||
/// For cases where additional ExtractedSprites are created during extraction, this stores the
|
||||
/// entity that caused that creation for use in determining visibility.
|
||||
pub original_entity: Option<Entity>,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
@ -390,6 +393,7 @@ pub fn extract_sprites(
|
||||
flip_y: sprite.flip_y,
|
||||
image_handle_id: handle.id(),
|
||||
anchor: sprite.anchor.as_vec(),
|
||||
original_entity: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -425,6 +429,7 @@ pub fn extract_sprites(
|
||||
flip_y: atlas_sprite.flip_y,
|
||||
image_handle_id: texture_atlas.texture.id(),
|
||||
anchor: atlas_sprite.anchor.as_vec(),
|
||||
original_entity: None,
|
||||
},
|
||||
);
|
||||
}
|
||||
@ -550,7 +555,9 @@ pub fn queue_sprites(
|
||||
.reserve(extracted_sprites.sprites.len());
|
||||
|
||||
for (entity, extracted_sprite) in extracted_sprites.sprites.iter() {
|
||||
if !view_entities.contains(entity.index() as usize) {
|
||||
let index = extracted_sprite.original_entity.unwrap_or(*entity).index();
|
||||
|
||||
if !view_entities.contains(index as usize) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@ -85,6 +85,7 @@ pub fn extract_text2d_sprite(
|
||||
windows: Extract<Query<&Window, With<PrimaryWindow>>>,
|
||||
text2d_query: Extract<
|
||||
Query<(
|
||||
Entity,
|
||||
&ViewVisibility,
|
||||
&Text,
|
||||
&TextLayoutInfo,
|
||||
@ -100,7 +101,9 @@ pub fn extract_text2d_sprite(
|
||||
.unwrap_or(1.0);
|
||||
let scaling = GlobalTransform::from_scale(Vec2::splat(scale_factor.recip()).extend(1.));
|
||||
|
||||
for (view_visibility, text, text_layout_info, anchor, global_transform) in text2d_query.iter() {
|
||||
for (original_entity, view_visibility, text, text_layout_info, anchor, global_transform) in
|
||||
text2d_query.iter()
|
||||
{
|
||||
if !view_visibility.get() {
|
||||
continue;
|
||||
}
|
||||
@ -125,8 +128,9 @@ pub fn extract_text2d_sprite(
|
||||
}
|
||||
let atlas = texture_atlases.get(&atlas_info.texture_atlas).unwrap();
|
||||
|
||||
let entity = commands.spawn_empty().id();
|
||||
extracted_sprites.sprites.insert(
|
||||
commands.spawn_empty().id(),
|
||||
entity,
|
||||
ExtractedSprite {
|
||||
transform: transform * GlobalTransform::from_translation(position.extend(0.)),
|
||||
color,
|
||||
@ -136,6 +140,7 @@ pub fn extract_text2d_sprite(
|
||||
flip_x: false,
|
||||
flip_y: false,
|
||||
anchor: Anchor::Center.as_vec(),
|
||||
original_entity: Some(original_entity),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user