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

    const AUTOMATIC_BATCHING: bool = true;

    // Required methods
    fn entity(&self) -> Entity;
    fn sort_key(&self) -> Self::SortKey;
    fn draw_function(&self) -> DrawFunctionId;
    fn batch_range(&self) -> &Range<u32>;
    fn batch_range_mut(&mut self) -> &mut Range<u32>;
    fn dynamic_offset(&self) -> Option<NonMaxU32>;
    fn dynamic_offset_mut(&mut self) -> &mut Option<NonMaxU32>;

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

An item (entity of the render world) which will be drawn to a texture or the screen, as part of a RenderPhase.

The data required for rendering an entity is extracted from the main world in the ExtractSchedule. Then it has to be queued up for rendering during the RenderSet::Queue, by adding a corresponding phase item to a render phase. Afterwards it will be sorted and rendered automatically in the RenderSet::PhaseSort and RenderSet::Render, respectively.

Required Associated Types§

source

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.

Provided Associated Constants§

source

const AUTOMATIC_BATCHING: bool = true

Whether or not this PhaseItem should be subjected to automatic batching. (Default: true)

Required Methods§

source

fn entity(&self) -> Entity

The corresponding entity that will be drawn.

This is used to fetch the render data of the entity, required by the draw function, from the render world .

source

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

Determines the order in which the items are drawn.

source

fn draw_function(&self) -> DrawFunctionId

Specifies the Draw function used to render the item.

source

fn batch_range(&self) -> &Range<u32>

The range of instances that the batch covers. After doing a batched draw, batch range length phase items will be skipped. This design is to avoid having to restructure the render phase unnecessarily.

source

fn batch_range_mut(&mut self) -> &mut Range<u32>

source

fn dynamic_offset(&self) -> Option<NonMaxU32>

source

fn dynamic_offset_mut(&mut self) -> &mut Option<NonMaxU32>

Provided Methods§

source

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.

Implementors§