wisp/render/
triangle_pipeline.rs1use crate::application::Application;
7
8pub(crate) struct TrianglePipeline {
10 pipeline: wgpu::RenderPipeline,
11}
12
13impl TrianglePipeline {
14 pub(crate) fn new(app: &Application, output_format: wgpu::TextureFormat) -> Self {
15 let device = app.device();
16 let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
17 label: Some("wisp::triangle"),
18 source: wgpu::ShaderSource::Wgsl(include_str!("../../shaders/triangle.wgsl").into()),
19 });
20
21 let layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
22 label: Some("wisp::triangle layout"),
23 bind_group_layouts: &[],
24 push_constant_ranges: &[],
25 });
26
27 let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
28 label: Some("wisp::triangle pipeline"),
29 layout: Some(&layout),
30 vertex: wgpu::VertexState {
31 module: &shader,
32 entry_point: Some("main_vs"),
33 buffers: &[],
34 compilation_options: wgpu::PipelineCompilationOptions::default(),
35 },
36 fragment: Some(wgpu::FragmentState {
37 module: &shader,
38 entry_point: Some("main_fs"),
39 targets: &[Some(wgpu::ColorTargetState {
40 format: output_format,
41 blend: Some(wgpu::BlendState::ALPHA_BLENDING),
42 write_mask: wgpu::ColorWrites::ALL,
43 })],
44 compilation_options: wgpu::PipelineCompilationOptions::default(),
45 }),
46 primitive: wgpu::PrimitiveState::default(),
47 depth_stencil: None,
48 multisample: wgpu::MultisampleState::default(),
49 multiview: None,
50 cache: None,
51 });
52
53 Self { pipeline }
54 }
55
56 pub(crate) fn draw(&self, pass: &mut wgpu::RenderPass<'_>) {
57 pass.set_pipeline(&self.pipeline);
58 pass.draw(0..3, 0..1);
59 }
60}