Skip to content

Commit

Permalink
UI Material: each material should have its own buffer (bevyengine#10422)
Browse files Browse the repository at this point in the history
# Objective

- When having several UI Material, nodes are not correctly placed

## Solution

- have a buffer per material
  • Loading branch information
mockersf authored Nov 7, 2023
1 parent 49cff08 commit aaef557
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions crates/bevy_ui/src/render/ui_material_pipeline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ where
.init_resource::<ExtractedUiMaterials<M>>()
.init_resource::<ExtractedUiMaterialNodes<M>>()
.init_resource::<RenderUiMaterials<M>>()
.init_resource::<UiMaterialMeta>()
.init_resource::<UiMaterialMeta<M>>()
.init_resource::<SpecializedRenderPipelines<UiMaterialPipeline<M>>>()
.add_systems(
ExtractSchedule,
Expand Down Expand Up @@ -98,16 +98,18 @@ where
}

#[derive(Resource)]
pub struct UiMaterialMeta {
pub struct UiMaterialMeta<M: UiMaterial> {
vertices: BufferVec<UiMaterialVertex>,
view_bind_group: Option<BindGroup>,
marker: PhantomData<M>,
}

impl Default for UiMaterialMeta {
impl<M: UiMaterial> Default for UiMaterialMeta<M> {
fn default() -> Self {
Self {
vertices: BufferVec::new(BufferUsages::VERTEX),
view_bind_group: Default::default(),
marker: PhantomData,
}
}
}
Expand Down Expand Up @@ -261,7 +263,7 @@ pub type DrawUiMaterial<M> = (

pub struct SetMatUiViewBindGroup<M: UiMaterial, const I: usize>(PhantomData<M>);
impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P> for SetMatUiViewBindGroup<M, I> {
type Param = SRes<UiMaterialMeta>;
type Param = SRes<UiMaterialMeta<M>>;
type ViewWorldQuery = Read<ViewUniformOffset>;
type ItemWorldQuery = ();

Expand Down Expand Up @@ -307,7 +309,7 @@ impl<P: PhaseItem, M: UiMaterial, const I: usize> RenderCommand<P>

pub struct DrawUiMaterialNode<M>(PhantomData<M>);
impl<P: PhaseItem, M: UiMaterial> RenderCommand<P> for DrawUiMaterialNode<M> {
type Param = SRes<UiMaterialMeta>;
type Param = SRes<UiMaterialMeta<M>>;
type ViewWorldQuery = ();
type ItemWorldQuery = Read<UiMaterialBatch<M>>;

Expand Down Expand Up @@ -429,7 +431,7 @@ pub fn prepare_uimaterial_nodes<M: UiMaterial>(
mut commands: Commands,
render_device: Res<RenderDevice>,
render_queue: Res<RenderQueue>,
mut ui_meta: ResMut<UiMaterialMeta>,
mut ui_meta: ResMut<UiMaterialMeta<M>>,
mut extracted_uinodes: ResMut<ExtractedUiMaterialNodes<M>>,
view_uniforms: Res<ViewUniforms>,
ui_material_pipeline: Res<UiMaterialPipeline<M>>,
Expand Down

0 comments on commit aaef557

Please sign in to comment.