logo
pub trait PhaseItem: 'static + Send + Sync {
    type SortKey: Ord;

    fn sort_key(&self) -> Self::SortKey;
    fn draw_function(&self) -> DrawFunctionId;

    fn sort(items: &mut [Self]) { ... }
}
Expand description

An item which will be drawn to the screen. A phase item should be queued up for rendering during the RenderStage::Queue stage. Afterwards it will be sorted and rendered automatically in the RenderStage::PhaseSort stage and RenderStage::Render stage, respectively.

Required Associated Types

The type used for ordering the items. The smallest values are drawn first.

Required Methods

Determines the order in which the items are drawn during the corresponding RenderPhase.

Specifies the Draw function used to render the item.

Provided Methods

Sorts a slice of phase items into render order. Generally if the same type implements BatchedPhaseItem, this should use a stable sort like slice::sort_by_key. In almost all other cases, this should not be altered from the default, which uses a unstable sort, as this provides the best balance of CPU and GPU performance.

Implementers can optionally not sort the list at all. This is generally advisable if and only if the renderer supports a depth prepass, which is by default not supported by the rest of Bevy’s first party rendering crates. Even then, this may have a negative impact on GPU-side performance due to overdraw.

It’s advised to always profile for performance changes when changing this implementation.

Implementors