Begin refactor
This commit is contained in:
parent
fb70d20fbe
commit
bbd2ef7b53
8 changed files with 83 additions and 62 deletions
66
src/lib.rs
66
src/lib.rs
|
@ -16,6 +16,8 @@ mod model;
|
|||
mod resources;
|
||||
mod texture;
|
||||
|
||||
mod render;
|
||||
|
||||
use model::{DrawLight, DrawModel, Vertex};
|
||||
|
||||
const NUM_INSTANCES_PER_ROW: u32 = 10;
|
||||
|
@ -156,66 +158,6 @@ struct State {
|
|||
mouse_pressed: bool,
|
||||
}
|
||||
|
||||
fn create_render_pipeline(
|
||||
device: &wgpu::Device,
|
||||
layout: &wgpu::PipelineLayout,
|
||||
color_format: wgpu::TextureFormat,
|
||||
depth_format: Option<wgpu::TextureFormat>,
|
||||
vertex_layouts: &[wgpu::VertexBufferLayout],
|
||||
shader: wgpu::ShaderModuleDescriptor,
|
||||
) -> wgpu::RenderPipeline {
|
||||
let shader = device.create_shader_module(&shader);
|
||||
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some(&format!("{:?}", shader)),
|
||||
layout: Some(layout),
|
||||
vertex: wgpu::VertexState {
|
||||
module: &shader,
|
||||
entry_point: "vs_main",
|
||||
buffers: vertex_layouts,
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &shader,
|
||||
entry_point: "fs_main",
|
||||
targets: &[wgpu::ColorTargetState {
|
||||
format: color_format,
|
||||
blend: Some(wgpu::BlendState {
|
||||
alpha: wgpu::BlendComponent::REPLACE,
|
||||
color: wgpu::BlendComponent::REPLACE,
|
||||
}),
|
||||
write_mask: wgpu::ColorWrites::ALL,
|
||||
}],
|
||||
}),
|
||||
primitive: wgpu::PrimitiveState {
|
||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
strip_index_format: None,
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: Some(wgpu::Face::Back),
|
||||
// Setting this to anything other than Fill requires Features::NON_FILL_POLYGON_MODE
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
// Requires Features::DEPTH_CLIP_CONTROL
|
||||
unclipped_depth: false,
|
||||
// Requires Features::CONSERVATIVE_RASTERIZATION
|
||||
conservative: false,
|
||||
},
|
||||
depth_stencil: depth_format.map(|format| wgpu::DepthStencilState {
|
||||
format,
|
||||
depth_write_enabled: true,
|
||||
depth_compare: wgpu::CompareFunction::Less,
|
||||
stencil: wgpu::StencilState::default(),
|
||||
bias: wgpu::DepthBiasState::default(),
|
||||
}),
|
||||
multisample: wgpu::MultisampleState {
|
||||
count: 1,
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
// If the pipeline will be used with a multiview render pass, this
|
||||
// indicates how many array layers the attachments will have.
|
||||
multiview: None,
|
||||
})
|
||||
}
|
||||
|
||||
impl State {
|
||||
async fn new(window: &Window) -> Self {
|
||||
let size = window.inner_size();
|
||||
|
@ -443,7 +385,7 @@ impl State {
|
|||
label: Some("Normal Shader"),
|
||||
source: wgpu::ShaderSource::Wgsl(include_str!("shader.wgsl").into()),
|
||||
};
|
||||
create_render_pipeline(
|
||||
render::create_render_pipeline(
|
||||
&device,
|
||||
&render_pipeline_layout,
|
||||
config.format,
|
||||
|
@ -463,7 +405,7 @@ impl State {
|
|||
label: Some("Light Shader"),
|
||||
source: wgpu::ShaderSource::Wgsl(include_str!("light.wgsl").into()),
|
||||
};
|
||||
create_render_pipeline(
|
||||
render::create_render_pipeline(
|
||||
&device,
|
||||
&layout,
|
||||
config.format,
|
||||
|
|
3
src/render/mod.rs
Normal file
3
src/render/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
mod pipelines;
|
||||
|
||||
pub use pipelines::utils::create_render_pipeline;
|
7
src/render/pipelines/light.rs
Normal file
7
src/render/pipelines/light.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub struct LightPipeline {
|
||||
pipeline: wgpu::RenderPipeline
|
||||
}
|
||||
|
||||
impl LightPipeline {
|
||||
|
||||
}
|
7
src/render/pipelines/mod.rs
Normal file
7
src/render/pipelines/mod.rs
Normal file
|
@ -0,0 +1,7 @@
|
|||
pub mod utils;
|
||||
|
||||
pub struct GlobalBindLayout {
|
||||
texture: wgpu::BindGroupLayout,
|
||||
light: wgpu::BindGroupLayout,
|
||||
camera: wgpu::BindGroupLayout
|
||||
}
|
3
src/render/pipelines/model.rs
Normal file
3
src/render/pipelines/model.rs
Normal file
|
@ -0,0 +1,3 @@
|
|||
pub struct ModelPipeline {
|
||||
pipeline: wgpu::RenderPipeline
|
||||
}
|
59
src/render/pipelines/utils.rs
Normal file
59
src/render/pipelines/utils.rs
Normal file
|
@ -0,0 +1,59 @@
|
|||
pub fn create_render_pipeline(
|
||||
device: &wgpu::Device,
|
||||
layout: &wgpu::PipelineLayout,
|
||||
color_format: wgpu::TextureFormat,
|
||||
depth_format: Option<wgpu::TextureFormat>,
|
||||
vertex_layouts: &[wgpu::VertexBufferLayout],
|
||||
shader: wgpu::ShaderModuleDescriptor,
|
||||
) -> wgpu::RenderPipeline {
|
||||
let shader = device.create_shader_module(&shader);
|
||||
|
||||
device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some(&format!("{:?}", shader)),
|
||||
layout: Some(layout),
|
||||
vertex: wgpu::VertexState {
|
||||
module: &shader,
|
||||
entry_point: "vs_main",
|
||||
buffers: vertex_layouts,
|
||||
},
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &shader,
|
||||
entry_point: "fs_main",
|
||||
targets: &[wgpu::ColorTargetState {
|
||||
format: color_format,
|
||||
blend: Some(wgpu::BlendState {
|
||||
alpha: wgpu::BlendComponent::REPLACE,
|
||||
color: wgpu::BlendComponent::REPLACE,
|
||||
}),
|
||||
write_mask: wgpu::ColorWrites::ALL,
|
||||
}],
|
||||
}),
|
||||
primitive: wgpu::PrimitiveState {
|
||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
strip_index_format: None,
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: Some(wgpu::Face::Back),
|
||||
// Setting this to anything other than Fill requires Features::NON_FILL_POLYGON_MODE
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
// Requires Features::DEPTH_CLIP_CONTROL
|
||||
unclipped_depth: false,
|
||||
// Requires Features::CONSERVATIVE_RASTERIZATION
|
||||
conservative: false,
|
||||
},
|
||||
depth_stencil: depth_format.map(|format| wgpu::DepthStencilState {
|
||||
format,
|
||||
depth_write_enabled: true,
|
||||
depth_compare: wgpu::CompareFunction::Less,
|
||||
stencil: wgpu::StencilState::default(),
|
||||
bias: wgpu::DepthBiasState::default(),
|
||||
}),
|
||||
multisample: wgpu::MultisampleState {
|
||||
count: 1,
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
// If the pipeline will be used with a multiview render pass, this
|
||||
// indicates how many array layers the attachments will have.
|
||||
multiview: None,
|
||||
})
|
||||
}
|
0
src/render/renderer/mod.rs
Normal file
0
src/render/renderer/mod.rs
Normal file
0
src/render/renderer/vertex.rs
Normal file
0
src/render/renderer/vertex.rs
Normal file
Loading…
Reference in a new issue