Trait bevy::render::render_phase::SortedPhaseItem

pub trait SortedPhaseItem: PhaseItem {
    type SortKey: Ord;

    // Required method
    fn sort_key(&self) -> Self::SortKey;

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

Represents phase items that must be sorted. The SortKey specifies the order that these items are drawn in. These are placed into a single array, and the array as a whole is then sorted.

An example of a sorted phase item is Transparent3d, which must be sorted back to front in order to correctly render with the painter’s algorithm.

Required Associated Types§

type SortKey: Ord

The type used for ordering the items. The smallest values are drawn first. This order can be calculated using the ViewRangefinder3d, based on the view-space Z value of the corresponding view matrix.

Required Methods§

fn sort_key(&self) -> Self::SortKey

Determines the order in which the items are drawn.

Provided Methods§

fn sort(items: &mut [Self])

Sorts a slice of phase items into render order. Generally if the same type is batched 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.

Object Safety§

This trait is not object safe.