Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Jul 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pipelined/bevy_pbr2/src/render/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,13 @@ impl Draw for DrawShadowMesh {
&[view_uniform_offset.offset],
);

let transform_bindgroup_key = mesh_meta.mesh_transform_bind_group_key.unwrap();
pass.set_bind_group(
1,
mesh_meta
.into_inner()
.mesh_transform_bind_group
.as_ref()
.get_value(transform_bindgroup_key)
.unwrap(),
&[extracted_mesh.transform_binding_offset],
);
Expand Down
33 changes: 21 additions & 12 deletions pipelined/bevy_pbr2/src/render/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,8 @@ struct MeshDrawInfo {
pub struct MeshMeta {
transform_uniforms: DynamicUniformVec<Mat4>,
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>,
}

Expand Down Expand Up @@ -502,16 +503,21 @@ pub fn queue_meshes(
}

let transform_uniforms = &mesh_meta.transform_uniforms;
mesh_meta.mesh_transform_bind_group.get_or_insert_with(|| {
render_device.create_bind_group(&BindGroupDescriptor {
entries: &[BindGroupEntry {
binding: 0,
resource: transform_uniforms.binding(),
}],
label: None,
layout: &pbr_shaders.mesh_layout,
})
});
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 {
entries: &[BindGroupEntry {
binding: 0,
resource: transform_uniforms.binding(),
}],
label: None,
layout: &pbr_shaders.mesh_layout,
})
},
));
for (entity, view, view_lights, mut transparent_phase) in views.iter_mut() {
// TODO: cache this?
let view_bind_group = render_device.create_bind_group(&BindGroupDescriptor {
Expand Down Expand Up @@ -736,7 +742,10 @@ impl Draw for DrawPbr {
);
pass.set_bind_group(
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],
);
let mesh_draw_info = &mesh_meta.mesh_draw_info[draw_key];
Expand Down