use static dispatch in add_resource_provider

This commit is contained in:
Carter Anderson 2020-03-09 12:07:16 -07:00
parent 7d3f271cfa
commit 440d883322
4 changed files with 17 additions and 12 deletions

View file

@ -23,7 +23,7 @@ fn main() {
.setup_world(setup)
.setup_render_graph(|builder, pipeline_storage, shader_storage| {
builder
.add_resource_provider(Box::new(UniformResourceProvider::<MyMaterial>::new()))
.add_resource_provider(UniformResourceProvider::<MyMaterial>::new())
.add_pipeline_to_pass(
resource_name::pass::MAIN,
pipeline_storage,

View file

@ -147,13 +147,13 @@ impl AppBuilder {
.add_draw_target(MeshesDrawTarget::default())
.add_draw_target(AssignedMeshesDrawTarget::default())
.add_draw_target(UiDrawTarget::default())
.add_resource_provider(Box::new(CameraResourceProvider::default()))
.add_resource_provider(Box::new(Camera2dResourceProvider::default()))
.add_resource_provider(Box::new(LightResourceProvider::new(10)))
.add_resource_provider(Box::new(UiResourceProvider::new()))
.add_resource_provider(Box::new(MeshResourceProvider::new()))
.add_resource_provider(Box::new(UniformResourceProvider::<StandardMaterial>::new()))
.add_resource_provider(Box::new(UniformResourceProvider::<LocalToWorld>::new()))
.add_resource_provider(CameraResourceProvider::default())
.add_resource_provider(Camera2dResourceProvider::default())
.add_resource_provider(LightResourceProvider::new(10))
.add_resource_provider(UiResourceProvider::new())
.add_resource_provider(MeshResourceProvider::new())
.add_resource_provider(UniformResourceProvider::<StandardMaterial>::new())
.add_resource_provider(UniformResourceProvider::<LocalToWorld>::new())
.add_forward_pass()
.add_forward_pipeline(pipeline_storage, shader_storage)
.add_ui_pipeline(pipeline_storage, shader_storage)

View file

@ -10,7 +10,7 @@ pub trait ForwardPassBuilder {
impl ForwardPassBuilder for RenderGraphBuilder {
fn add_forward_pass(self) -> Self {
self.add_resource_provider(Box::new(FrameTextureResourceProvider::new(
self.add_resource_provider(FrameTextureResourceProvider::new(
resource_name::texture::DEPTH,
TextureDescriptor {
size: wgpu::Extent3d {
@ -25,7 +25,7 @@ impl ForwardPassBuilder for RenderGraphBuilder {
format: wgpu::TextureFormat::Depth32Float,
usage: wgpu::TextureUsage::OUTPUT_ATTACHMENT,
},
)))
))
.add_pass(
resource_name::pass::MAIN,
PassDescriptor {

View file

@ -86,8 +86,13 @@ impl RenderGraphBuilder {
self
}
pub fn add_resource_provider(mut self, resource_provider: Box<dyn ResourceProvider>) -> Self {
self.render_graph.resource_providers.push(resource_provider);
pub fn add_resource_provider<T>(mut self, resource_provider: T) -> Self
where
T: ResourceProvider + 'static,
{
self.render_graph
.resource_providers
.push(Box::new(resource_provider));
self
}