UI Material: each material should have its own buffer (#10422)

# Objective

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

## Solution

- have a buffer per material
This commit is contained in:
François 2023-11-07 10:51:40 +01:00 committed by Carter Anderson
parent e6695d5e20
commit 07d6a12f46

View File

@ -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,
@ -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,
}
}
}
@ -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 = ();
@ -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>>;
@ -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>>,