using pipeline
This commit is contained in:
+38
-35
@@ -48,52 +48,51 @@ impl App {
|
||||
};
|
||||
let swapchain = device.create_swap_chain(&surface, &swapchain_desc);
|
||||
|
||||
// Create pipeline
|
||||
let vert_module = device.create_shader_module(&wgpu::include_spirv!(".bin\\shader.vert.spv"));
|
||||
let frag_module = device.create_shader_module(&wgpu::include_spirv!(".bin\\shader.frag.spv"));
|
||||
// Pipeline stuff
|
||||
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
||||
label: Some("Render Pipeline Layout"),
|
||||
bind_group_layouts: &[],
|
||||
push_constant_ranges: &[],
|
||||
});
|
||||
let vert_state = wgpu::VertexState { //vert
|
||||
module: &device.create_shader_module(&wgpu::include_spirv!(".bin\\shader.vert.spv")),
|
||||
entry_point: "main",
|
||||
buffers: &[],
|
||||
};
|
||||
let frag_state = wgpu::FragmentState { // frag
|
||||
module: &device.create_shader_module(&wgpu::include_spirv!(".bin\\shader.frag.spv")),
|
||||
entry_point: "main",
|
||||
targets: &[wgpu::ColorTargetState {
|
||||
format: swapchain_desc.format,
|
||||
alpha_blend: wgpu::BlendState::REPLACE,
|
||||
color_blend: wgpu::BlendState::REPLACE,
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
};
|
||||
let prim_state = wgpu::PrimitiveState { // primitive
|
||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
strip_index_format: None,
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
};
|
||||
let multisample_state = wgpu::MultisampleState { // multisample
|
||||
count: 1,
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
};
|
||||
|
||||
// Create pipeline
|
||||
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
|
||||
label: Some("Render Pipeline"),
|
||||
layout: Some(&pipeline_layout),
|
||||
// Vertex shader
|
||||
vertex: wgpu::VertexState {
|
||||
module: &vert_module,
|
||||
entry_point: "main",
|
||||
buffers: &[],
|
||||
},
|
||||
// Fragment shader
|
||||
fragment: Some(wgpu::FragmentState {
|
||||
module: &frag_module,
|
||||
entry_point: "main",
|
||||
targets: &[wgpu::ColorTargetState {
|
||||
format: swapchain_desc.format,
|
||||
alpha_blend: wgpu::BlendState::REPLACE,
|
||||
color_blend: wgpu::BlendState::REPLACE,
|
||||
write_mask: wgpu::ColorWrite::ALL,
|
||||
}],
|
||||
}),
|
||||
// Other
|
||||
primitive: wgpu::PrimitiveState {
|
||||
topology: wgpu::PrimitiveTopology::TriangleList,
|
||||
strip_index_format: None,
|
||||
front_face: wgpu::FrontFace::Ccw,
|
||||
cull_mode: wgpu::CullMode::Back,
|
||||
polygon_mode: wgpu::PolygonMode::Fill,
|
||||
},
|
||||
vertex: vert_state,
|
||||
fragment: Some(frag_state),
|
||||
primitive: prim_state,
|
||||
depth_stencil: None,
|
||||
multisample: wgpu::MultisampleState {
|
||||
count: 1,
|
||||
mask: !0,
|
||||
alpha_to_coverage_enabled: false,
|
||||
},
|
||||
multisample: multisample_state,
|
||||
});
|
||||
|
||||
|
||||
// Save values in app
|
||||
Self { surface, device, queue, swapchain_desc, swapchain, pipeline }
|
||||
}
|
||||
@@ -133,7 +132,8 @@ impl App {
|
||||
store: true,
|
||||
};
|
||||
|
||||
let _render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor { label: Some("Render Pass"),
|
||||
let mut render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
|
||||
label: Some("Render Pass"),
|
||||
color_attachments: &[
|
||||
wgpu::RenderPassColorAttachmentDescriptor {
|
||||
attachment: &frame.view,
|
||||
@@ -143,6 +143,9 @@ impl App {
|
||||
],
|
||||
depth_stencil_attachment: None,
|
||||
});
|
||||
|
||||
render_pass.set_pipeline(&self.pipeline);
|
||||
render_pass.draw(0..3, 0..1);
|
||||
}
|
||||
|
||||
// Submit encoder (command buffer)
|
||||
|
||||
Reference in New Issue
Block a user