wireframe_pipeline.rs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. use wgpu::{include_wgsl, BlendState, ColorTargetState, RenderPipeline, RenderPipelineDescriptor, SurfaceConfiguration};
  2. use crate::object;
  3. pub fn new(device: &wgpu::Device, config: &SurfaceConfiguration,camera_bind_group_layout: &wgpu::BindGroupLayout, diffuse_bind_group_layout: &wgpu::BindGroupLayout, visu_bind_group_layout: &wgpu::BindGroupLayout)-> RenderPipeline{
  4. let wireframe_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor{
  5. label: Some("Wireframe Pipeline Layout"),
  6. bind_group_layouts: &[
  7. &camera_bind_group_layout,
  8. &diffuse_bind_group_layout,
  9. &visu_bind_group_layout,
  10. ],
  11. push_constant_ranges: &[]
  12. });
  13. let shader_module = device.create_shader_module(include_wgsl!("../shaders/plane_shader.wgsl"));
  14. let wireframe_pipeline = device.create_render_pipeline(&RenderPipelineDescriptor{
  15. label: Some("Wireframe Pipeline"),
  16. layout: Some(&wireframe_layout),
  17. vertex: wgpu::VertexState {
  18. module: &shader_module,
  19. entry_point: "vs_main".into(),
  20. buffers: &[
  21. object::Vertex::desc(),
  22. ],
  23. },
  24. primitive: wgpu::PrimitiveState{
  25. topology: wgpu::PrimitiveTopology::TriangleList,
  26. strip_index_format: None,
  27. front_face: wgpu::FrontFace::Ccw,
  28. cull_mode: None,
  29. unclipped_depth: false,
  30. polygon_mode: wgpu::PolygonMode::Line, //Or wgpu::PolygonMode::Fill
  31. conservative: false
  32. },
  33. depth_stencil: None,
  34. multisample: wgpu::MultisampleState{
  35. count: 1,
  36. mask: !0,
  37. alpha_to_coverage_enabled: false,
  38. },
  39. fragment: Some(wgpu::FragmentState{
  40. module: &shader_module,
  41. entry_point: "fs_main",
  42. targets: &[Some(ColorTargetState{
  43. format: config.format,
  44. blend: Some(BlendState::REPLACE),
  45. write_mask: wgpu::ColorWrites::ALL
  46. })]
  47. }),
  48. multiview: None
  49. });
  50. return wireframe_pipeline
  51. }