Trait bevy_render::render_phase::PhaseItem

source ·
pub trait PhaseItem: Sized + Send + Sync + 'static {
    const AUTOMATIC_BATCHING: bool = true;

    // Required methods
    fn entity(&self) -> Entity;
    fn draw_function(&self) -> DrawFunctionId;
    fn batch_range(&self) -> &Range<u32>;
    fn batch_range_mut(&mut self) -> &mut Range<u32>;
    fn extra_index(&self) -> PhaseItemExtraIndex;
    fn batch_range_and_extra_index_mut(
        &mut self
    ) -> (&mut Range<u32>, &mut PhaseItemExtraIndex);
}
Expand description

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

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 possibly sorted and rendered automatically in the RenderSet::PhaseSort and RenderSet::Render, respectively.

PhaseItems come in two flavors: BinnedPhaseItems and SortedPhaseItems.

  • Binned phase items have a BinKey which specifies what bin they’re to be placed in. All items in the same bin are eligible to be batched together. The BinKeys are sorted, but the individual bin items aren’t. Binned phase items are good for opaque meshes, in which the order of rendering isn’t important. Generally, binned phase items are faster than sorted phase items.

  • Sorted phase items, on the other hand, are placed into one large buffer and then sorted all at once. This is needed for transparent meshes, which have to be sorted back-to-front to render with the painter’s algorithm. These types of phase items are generally slower than binned phase items.

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 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 extra_index(&self) -> PhaseItemExtraIndex

Returns the PhaseItemExtraIndex.

If present, this is either a dynamic offset or an indirect parameters index.

source

fn batch_range_and_extra_index_mut( &mut self ) -> (&mut Range<u32>, &mut PhaseItemExtraIndex)

Returns a pair of mutable references to both the batch range and extra index.

Object Safety§

This trait is not object safe.

Implementors§