mirror of
https://github.com/guilhermewerner/wgpu-renderer
synced 2025-06-16 13:54:21 +00:00
Update model.rs
This commit is contained in:
47
src/model.rs
47
src/model.rs
@ -61,11 +61,25 @@ pub struct Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub trait DrawModel<'a> {
|
pub trait DrawModel<'a> {
|
||||||
fn draw_mesh(&mut self, mesh: &'a Mesh);
|
fn draw_mesh(
|
||||||
|
&mut self,
|
||||||
|
mesh: &'a Mesh,
|
||||||
|
material: &'a Material,
|
||||||
|
camera_bind_group: &'a wgpu::BindGroup,
|
||||||
|
);
|
||||||
fn draw_mesh_instanced(
|
fn draw_mesh_instanced(
|
||||||
&mut self,
|
&mut self,
|
||||||
mesh: &'a Mesh,
|
mesh: &'a Mesh,
|
||||||
|
material: &'a Material,
|
||||||
instances: Range<u32>,
|
instances: Range<u32>,
|
||||||
|
camera_bind_group: &'a wgpu::BindGroup,
|
||||||
|
);
|
||||||
|
fn draw_model(&mut self, model: &'a Model, camera_bind_group: &'a wgpu::BindGroup);
|
||||||
|
fn draw_model_instanced(
|
||||||
|
&mut self,
|
||||||
|
model: &'a Model,
|
||||||
|
instances: Range<u32>,
|
||||||
|
camera_bind_group: &'a wgpu::BindGroup,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,17 +87,42 @@ impl<'a, 'b> DrawModel<'b> for wgpu::RenderPass<'a>
|
|||||||
where
|
where
|
||||||
'b: 'a,
|
'b: 'a,
|
||||||
{
|
{
|
||||||
fn draw_mesh(&mut self, mesh: &'b Mesh) {
|
fn draw_mesh(
|
||||||
self.draw_mesh_instanced(mesh, 0..1);
|
&mut self,
|
||||||
|
mesh: &'b Mesh,
|
||||||
|
material: &'b Material,
|
||||||
|
camera_bind_group: &'b wgpu::BindGroup,
|
||||||
|
) {
|
||||||
|
self.draw_mesh_instanced(mesh, material, 0..1, camera_bind_group);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_mesh_instanced(
|
fn draw_mesh_instanced(
|
||||||
&mut self,
|
&mut self,
|
||||||
mesh: &'b Mesh,
|
mesh: &'b Mesh,
|
||||||
|
material: &'b Material,
|
||||||
instances: Range<u32>,
|
instances: Range<u32>,
|
||||||
){
|
camera_bind_group: &'b wgpu::BindGroup,
|
||||||
|
) {
|
||||||
self.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
|
self.set_vertex_buffer(0, mesh.vertex_buffer.slice(..));
|
||||||
self.set_index_buffer(mesh.index_buffer.slice(..), wgpu::IndexFormat::Uint32);
|
self.set_index_buffer(mesh.index_buffer.slice(..), wgpu::IndexFormat::Uint32);
|
||||||
|
self.set_bind_group(0, &material.bind_group, &[]);
|
||||||
|
self.set_bind_group(1, camera_bind_group, &[]);
|
||||||
self.draw_indexed(0..mesh.num_elements, 0, instances);
|
self.draw_indexed(0..mesh.num_elements, 0, instances);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_model(&mut self, model: &'b Model, camera_bind_group: &'b wgpu::BindGroup) {
|
||||||
|
self.draw_model_instanced(model, 0..1, camera_bind_group);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn draw_model_instanced(
|
||||||
|
&mut self,
|
||||||
|
model: &'b Model,
|
||||||
|
instances: Range<u32>,
|
||||||
|
camera_bind_group: &'b wgpu::BindGroup,
|
||||||
|
) {
|
||||||
|
for mesh in &model.meshes {
|
||||||
|
let material = &model.materials[mesh.material];
|
||||||
|
self.draw_mesh_instanced(mesh, material, instances.clone(), camera_bind_group);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user