Change GpuViewSize from component to resource.

This commit is contained in:
Robin KAY 2022-06-14 07:46:26 +01:00
parent a960850611
commit 448b61fc4e
1 changed files with 10 additions and 14 deletions

View File

@ -113,7 +113,6 @@ struct ViewSizeUniformOffset {
pub offset: u32, pub offset: u32,
} }
#[derive(Component)]
struct GpuViewSize { struct GpuViewSize {
bind_group: BindGroup, bind_group: BindGroup,
} }
@ -165,24 +164,24 @@ type DrawOutline = (
SetItemPipeline, SetItemPipeline,
SetMeshViewBindGroup<0>, SetMeshViewBindGroup<0>,
SetMeshBindGroup<1>, SetMeshBindGroup<1>,
SetOutlineViewBindGroup<2>, SetViewSizeBindGroup<2>,
SetOutlineBindGroup<3>, SetOutlineBindGroup<3>,
DrawMesh, DrawMesh,
); );
struct SetOutlineViewBindGroup<const I: usize>(); struct SetViewSizeBindGroup<const I: usize>();
impl<const I: usize> EntityRenderCommand for SetOutlineViewBindGroup<I> { impl<const I: usize> EntityRenderCommand for SetViewSizeBindGroup<I> {
type Param = SQuery<(Read<ViewSizeUniformOffset>, Read<GpuViewSize>)>; type Param = (SRes<GpuViewSize>, SQuery<Read<ViewSizeUniformOffset>>);
#[inline] #[inline]
fn render<'w>( fn render<'w>(
view: Entity, view: Entity,
_item: Entity, _item: Entity,
view_query: SystemParamItem<'w, '_, Self::Param>, (gpu_view_size, offset_query): SystemParamItem<'w, '_, Self::Param>,
pass: &mut TrackedRenderPass<'w>, pass: &mut TrackedRenderPass<'w>,
) -> RenderCommandResult { ) -> RenderCommandResult {
let (view_size_uniform, gpu_view_size) = view_query.get_inner(view).unwrap(); let uniform_offset = offset_query.get_inner(view).unwrap();
pass.set_bind_group(I, &gpu_view_size.bind_group, &[view_size_uniform.offset]); pass.set_bind_group(I, &gpu_view_size.into_inner().bind_group, &[uniform_offset.offset]);
RenderCommandResult::Success RenderCommandResult::Success
} }
@ -236,7 +235,6 @@ fn prepare_view_size_uniforms(
let view_size_uniforms = ViewSizeUniformOffset { let view_size_uniforms = ViewSizeUniformOffset {
offset: view_size_uniforms.uniforms.push(view_size_uniform.clone()), offset: view_size_uniforms.uniforms.push(view_size_uniform.clone()),
}; };
commands.entity(entity).insert(view_size_uniforms); commands.entity(entity).insert(view_size_uniforms);
} }
@ -253,11 +251,9 @@ fn prepare_view_size_uniforms(
label: Some("outline_view_size_bind_group"), label: Some("outline_view_size_bind_group"),
layout: &outline_pipeline.view_size_bind_group_layout, layout: &outline_pipeline.view_size_bind_group_layout,
}); });
for (entity, _) in views.iter() { commands.insert_resource(GpuViewSize {
commands.entity(entity).insert(GpuViewSize { bind_group: bind_group.clone(),
bind_group: bind_group.clone(), });
});
}
} }
} }