Add `Context::current_pass_index` (#7276)

This can be used by developers who wants to add diagnostics when there
is a multi-pass egui frame.
This commit is contained in:
Emil Ernerfeldt 2025-06-30 10:41:27 +02:00 committed by GitHub
parent 2525546fef
commit d770cd53a6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 16 additions and 1 deletions

View File

@ -1539,6 +1539,9 @@ impl Context {
/// The total number of completed passes (usually there is one pass per rendered frame). /// The total number of completed passes (usually there is one pass per rendered frame).
/// ///
/// Starts at zero, and is incremented for each completed pass inside of [`Self::run`] (usually once). /// Starts at zero, and is incremented for each completed pass inside of [`Self::run`] (usually once).
///
/// If you instead want to know which pass index this is within the current frame,
/// use [`Self::current_pass_index`].
pub fn cumulative_pass_nr(&self) -> u64 { pub fn cumulative_pass_nr(&self) -> u64 {
self.cumulative_pass_nr_for(self.viewport_id()) self.cumulative_pass_nr_for(self.viewport_id())
} }
@ -1554,6 +1557,18 @@ impl Context {
}) })
} }
/// The index of the current pass in the current frame, starting at zero.
///
/// Usually this is zero, but if something called [`Self::request_discard`] to do multi-pass layout,
/// then this will be incremented for each pass.
///
/// This just reads the value of [`PlatformOutput::num_completed_passes`].
///
/// To know the total number of passes ever completed, use [`Self::cumulative_pass_nr`].
pub fn current_pass_index(&self) -> usize {
self.output(|o| o.num_completed_passes)
}
/// Call this if there is need to repaint the UI, i.e. if you are showing an animation. /// Call this if there is need to repaint the UI, i.e. if you are showing an animation.
/// ///
/// If this is called at least once in a frame, then there will be another frame right after this. /// If this is called at least once in a frame, then there will be another frame right after this.
@ -1726,7 +1741,7 @@ impl Context {
/// This means the first pass will look glitchy, and ideally should not be shown to the user. /// This means the first pass will look glitchy, and ideally should not be shown to the user.
/// So [`crate::Grid`] calls [`Self::request_discard`] to cover up this glitches. /// So [`crate::Grid`] calls [`Self::request_discard`] to cover up this glitches.
/// ///
/// There is a limit to how many passes egui will perform, set by [`Options::max_passes`]. /// There is a limit to how many passes egui will perform, set by [`Options::max_passes`] (default=2).
/// Therefore, the request might be declined. /// Therefore, the request might be declined.
/// ///
/// You can check if the current pass will be discarded with [`Self::will_discard`]. /// You can check if the current pass will be discarded with [`Self::will_discard`].