Fixed issue where transform buffer wasn't creating new bindings on resize. (#7)

This commit is contained in:
John 2021-07-01 19:03:33 -04:00 committed by Carter Anderson
parent 7c57725a63
commit 5d0655f84c
2 changed files with 23 additions and 13 deletions

View File

@ -433,12 +433,13 @@ impl Draw for DrawShadowMesh {
&[view_uniform_offset.offset], &[view_uniform_offset.offset],
); );
let transform_bindgroup_key = mesh_meta.mesh_transform_bind_group_key.unwrap();
pass.set_bind_group( pass.set_bind_group(
1, 1,
mesh_meta mesh_meta
.into_inner() .into_inner()
.mesh_transform_bind_group .mesh_transform_bind_group
.as_ref() .get_value(transform_bindgroup_key)
.unwrap(), .unwrap(),
&[extracted_mesh.transform_binding_offset], &[extracted_mesh.transform_binding_offset],
); );

View File

@ -420,7 +420,8 @@ struct MeshDrawInfo {
pub struct MeshMeta { pub struct MeshMeta {
transform_uniforms: DynamicUniformVec<Mat4>, transform_uniforms: DynamicUniformVec<Mat4>,
material_bind_groups: FrameSlabMap<BufferId, BindGroup>, material_bind_groups: FrameSlabMap<BufferId, BindGroup>,
mesh_transform_bind_group: Option<BindGroup>, mesh_transform_bind_group: FrameSlabMap<BufferId, BindGroup>,
mesh_transform_bind_group_key: Option<FrameSlabMapKey<BufferId, BindGroup>>,
mesh_draw_info: Vec<MeshDrawInfo>, mesh_draw_info: Vec<MeshDrawInfo>,
} }
@ -502,7 +503,11 @@ pub fn queue_meshes(
} }
let transform_uniforms = &mesh_meta.transform_uniforms; let transform_uniforms = &mesh_meta.transform_uniforms;
mesh_meta.mesh_transform_bind_group.get_or_insert_with(|| { mesh_meta.mesh_transform_bind_group.next_frame();
mesh_meta.mesh_transform_bind_group_key =
Some(mesh_meta.mesh_transform_bind_group.get_or_insert_with(
transform_uniforms.uniform_buffer().unwrap().id(),
|| {
render_device.create_bind_group(&BindGroupDescriptor { render_device.create_bind_group(&BindGroupDescriptor {
entries: &[BindGroupEntry { entries: &[BindGroupEntry {
binding: 0, binding: 0,
@ -511,7 +516,8 @@ pub fn queue_meshes(
label: None, label: None,
layout: &pbr_shaders.mesh_layout, layout: &pbr_shaders.mesh_layout,
}) })
}); },
));
for (entity, view, view_lights, mut transparent_phase) in views.iter_mut() { for (entity, view, view_lights, mut transparent_phase) in views.iter_mut() {
// TODO: cache this? // TODO: cache this?
let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor { let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor {
@ -736,7 +742,10 @@ impl Draw for DrawPbr {
); );
pass.set_bind_group( pass.set_bind_group(
1, 1,
mesh_meta.mesh_transform_bind_group.as_ref().unwrap(), mesh_meta
.mesh_transform_bind_group
.get_value(mesh_meta.mesh_transform_bind_group_key.unwrap())
.unwrap(),
&[extracted_mesh.transform_binding_offset], &[extracted_mesh.transform_binding_offset],
); );
let mesh_draw_info = &mesh_meta.mesh_draw_info[draw_key]; let mesh_draw_info = &mesh_meta.mesh_draw_info[draw_key];