Trait bevy::render::render_phase::PhaseItem
source · 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§
sourcetype SortKey: Ord
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§
sourceconst AUTOMATIC_BATCHING: bool = true
const AUTOMATIC_BATCHING: bool = true
Whether or not this PhaseItem
should be subjected to automatic batching. (Default: true
)
Required Methods§
sourcefn entity(&self) -> Entity
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 .
sourcefn draw_function(&self) -> DrawFunctionId
fn draw_function(&self) -> DrawFunctionId
Specifies the Draw
function used to render the item.
sourcefn batch_range(&self) -> &Range<u32>
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.
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 Methods§
sourcefn sort(items: &mut [Self])
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.