-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Text2d visibility fix #9708
Text2d visibility fix #9708
Changes from all commits
fb0f05e
edfdbaf
068098f
87c1b1e
0b76079
033d1c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -333,6 +333,27 @@ pub struct ExtractedSprites { | |
pub sprites: SparseSet<Entity, ExtractedSprite>, | ||
} | ||
|
||
/// Allows extraction of multiply sprites for a single entity that all share that entity's id for visibility resolution. | ||
/// Not designed for efficiency, extracting sprite entities individually should be more performant. | ||
#[derive(Resource, Default)] | ||
pub struct ExtractedSpriteBatches { | ||
ickshonpe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/// maps the entity id for each batch to a range of indices into `sprite_ids` | ||
pub batches: SparseSet<Entity, Range<usize>>, | ||
/// set of all the extracted sprites from every batch | ||
pub sprites: SparseSet<Entity, ExtractedSprite>, | ||
/// ids of empty entities used to identify the individual sprites in each batch | ||
pub sprite_ids: Vec<Entity>, | ||
} | ||
|
||
impl ExtractedSpriteBatches { | ||
/// Clear all batches | ||
pub fn clear(&mut self) { | ||
self.batches.clear(); | ||
self.sprites.clear(); | ||
self.sprite_ids.clear(); | ||
} | ||
} | ||
|
||
#[derive(Resource, Default)] | ||
pub struct SpriteAssetEvents { | ||
pub images: Vec<AssetEvent<Image>>, | ||
|
@@ -505,6 +526,7 @@ pub fn queue_sprites( | |
pipeline_cache: Res<PipelineCache>, | ||
msaa: Res<Msaa>, | ||
extracted_sprites: Res<ExtractedSprites>, | ||
extracted_batches: Res<ExtractedSpriteBatches>, | ||
mut views: Query<( | ||
&mut RenderPhase<Transparent2d>, | ||
&VisibleEntities, | ||
|
@@ -559,7 +581,7 @@ pub fn queue_sprites( | |
|
||
transparent_phase | ||
.items | ||
.reserve(extracted_sprites.sprites.len()); | ||
.reserve(extracted_sprites.sprites.len() + extracted_batches.sprites.len()); | ||
|
||
for (entity, extracted_sprite) in extracted_sprites.sprites.iter() { | ||
if !view_entities.contains(entity.index() as usize) { | ||
|
@@ -590,6 +612,38 @@ pub fn queue_sprites( | |
}); | ||
} | ||
} | ||
|
||
for (batch_entity, sprite_entities) in extracted_batches.batches.iter() { | ||
if !view_entities.contains(batch_entity.index() as usize) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This could use a bit of a comment: it's really quite unusual to care about the index of an Entity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original code wasn't commented either, I'm confident these changes work and don't mess anything up but I don't know enough about the rendering internals to be explaining anything to anyone I think. |
||
continue; | ||
} | ||
for sprite_entity in &extracted_batches.sprite_ids[sprite_entities.clone()] { | ||
let extracted_sprite = extracted_batches.sprites.get(*sprite_entity).unwrap(); | ||
// These items will be sorted by depth with other phase items | ||
let sort_key = FloatOrd(extracted_sprite.transform.translation().z); | ||
|
||
// Add the item to the render phase | ||
if extracted_sprite.color != Color::WHITE { | ||
transparent_phase.add(Transparent2d { | ||
draw_function: draw_sprite_function, | ||
pipeline: colored_pipeline, | ||
entity: *sprite_entity, | ||
sort_key, | ||
// batch_size will be calculated in prepare_glyphs | ||
batch_size: 0, | ||
}); | ||
} else { | ||
transparent_phase.add(Transparent2d { | ||
draw_function: draw_sprite_function, | ||
pipeline, | ||
entity: *sprite_entity, | ||
sort_key, | ||
// batch_size will be calculated in prepare_glyphs | ||
batch_size: 0, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
@@ -605,6 +659,7 @@ pub fn prepare_sprites( | |
mut image_bind_groups: ResMut<ImageBindGroups>, | ||
gpu_images: Res<RenderAssets<Image>>, | ||
extracted_sprites: Res<ExtractedSprites>, | ||
extracted_batches: Res<ExtractedSpriteBatches>, | ||
mut phases: Query<&mut RenderPhase<Transparent2d>>, | ||
events: Res<SpriteAssetEvents>, | ||
) { | ||
|
@@ -648,7 +703,11 @@ pub fn prepare_sprites( | |
// Compatible items share the same entity. | ||
for item_index in 0..transparent_phase.items.len() { | ||
let item = &transparent_phase.items[item_index]; | ||
let Some(extracted_sprite) = extracted_sprites.sprites.get(item.entity) else { | ||
let Some(extracted_sprite) = extracted_sprites | ||
.sprites | ||
.get(item.entity) | ||
.or_else(|| extracted_batches.sprites.get(item.entity)) | ||
else { | ||
// If there is a phase item that is not a sprite, then we must start a new | ||
// batch to draw the other phase item(s) and to respect draw order. This can be | ||
// done by invalidating the batch_image_handle | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a typo here (multiply -> multiple). I'm also leaving a suggestion to rephrase the comment, hopefully it still conveys the same meaning.