Add "standard config" to pipeline builder

This commit is contained in:
Carter Anderson 2020-02-17 20:43:50 -08:00
parent ad7acb111a
commit e0e0e41c33
3 changed files with 26 additions and 24 deletions

View File

@ -6,14 +6,11 @@ Here is the current list of planned features. All items are sorted in approximat
* Text * Text
* Styling * Styling
* Rendering * Rendering
* Render Graph V2
* Textures * Textures
* Physically based rendering * Physically based rendering
* Skeletal animation * Skeletal animation
* Macro to produce vertex buffer attributes (and maybe descriptors) from structs * Macro to produce vertex buffer attributes (and maybe descriptors) from structs
* Add runtime type safety to uniform bindings (and maybe compile time) * Add runtime type safety to uniform bindings (and maybe compile time)
* Dynamic / user defined shaders
* consider using shaderc-rs. but this introduces compile complexity and requires other C++ build systems
* Error Handling * Error Handling
* Custom error type? * Custom error type?
* Remove as many panics / unwraps as possible * Remove as many panics / unwraps as possible

View File

@ -4,7 +4,7 @@ use bevy::{
render_graph::{ render_graph::{
resource_name, resource_providers::UniformResourceProvider, PipelineDescriptor, resource_name, resource_providers::UniformResourceProvider, PipelineDescriptor,
}, },
Shader, ShaderStage, Vertex, Shader, ShaderStage,
}, },
}; };
@ -60,23 +60,7 @@ fn main() {
} }
"#, "#,
)) ))
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor { .with_standard_config()
format: wgpu::TextureFormat::Depth32Float,
depth_write_enabled: true,
depth_compare: wgpu::CompareFunction::Less,
stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE,
stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE,
stencil_read_mask: 0,
stencil_write_mask: 0,
})
.add_color_state(wgpu::ColorStateDescriptor {
format: wgpu::TextureFormat::Bgra8UnormSrgb,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
})
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
.add_draw_target(resource_name::draw_target::ASSIGNED_MESHES)
.build(), .build(),
) )
}) })
@ -95,7 +79,7 @@ fn setup(world: &mut World) {
.add_archetype(MeshMaterialEntity::<MyMaterial> { .add_archetype(MeshMaterialEntity::<MyMaterial> {
mesh: cube_handle, mesh: cube_handle,
renderable: Renderable { renderable: Renderable {
pipelines: vec![Handle::new(2)], pipelines: vec![Handle::new(2)], // TODO: make this pipeline assignment cleaner
..Default::default() ..Default::default()
}, },
material: MyMaterial { material: MyMaterial {

View File

@ -1,6 +1,6 @@
use crate::{asset::{AssetStorage, Handle}, render::{ use crate::{asset::{AssetStorage, Handle}, render::{
render_graph::{BindGroup, PipelineLayout}, render_graph::{BindGroup, PipelineLayout, resource_name},
shader::{Shader, ShaderStages}, shader::{Shader, ShaderStages}, Vertex,
}}; }};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
@ -206,4 +206,25 @@ impl<'a> PipelineBuilder<'a> {
self.pipeline.sample_mask = sample_mask; self.pipeline.sample_mask = sample_mask;
self self
} }
pub fn with_standard_config(self) -> Self {
self
.with_depth_stencil_state(wgpu::DepthStencilStateDescriptor {
format: wgpu::TextureFormat::Depth32Float,
depth_write_enabled: true,
depth_compare: wgpu::CompareFunction::Less,
stencil_front: wgpu::StencilStateFaceDescriptor::IGNORE,
stencil_back: wgpu::StencilStateFaceDescriptor::IGNORE,
stencil_read_mask: 0,
stencil_write_mask: 0,
})
.add_color_state(wgpu::ColorStateDescriptor {
format: wgpu::TextureFormat::Bgra8UnormSrgb,
color_blend: wgpu::BlendDescriptor::REPLACE,
alpha_blend: wgpu::BlendDescriptor::REPLACE,
write_mask: wgpu::ColorWrite::ALL,
})
.add_vertex_buffer_descriptor(Vertex::get_vertex_buffer_descriptor())
.add_draw_target(resource_name::draw_target::ASSIGNED_MESHES)
}
} }