summaryrefslogtreecommitdiffstats
path: root/src/wgpuctx/pipeline.rs
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-04-15 16:53:58 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-04-15 16:53:58 -0400
commitb5ced3af46c96ceb959fbbf1addfeba3bd4f76d5 (patch)
tree06d06fc9562dc99eede655b53635576f67c37e3b /src/wgpuctx/pipeline.rs
downloadsystemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.tar.gz
systemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.tar.bz2
systemic4x-b5ced3af46c96ceb959fbbf1addfeba3bd4f76d5.zip
first commit. working body rendering
Diffstat (limited to 'src/wgpuctx/pipeline.rs')
-rw-r--r--src/wgpuctx/pipeline.rs121
1 files changed, 121 insertions, 0 deletions
diff --git a/src/wgpuctx/pipeline.rs b/src/wgpuctx/pipeline.rs
new file mode 100644
index 0000000..7606203
--- /dev/null
+++ b/src/wgpuctx/pipeline.rs
@@ -0,0 +1,121 @@
+
+use crate::wgpuctx::WgpuCtx;
+
+pub struct RenderPipelineBuilder<'a>
+{
+ bind_groups: Vec<&'a wgpu::BindGroupLayout>,
+ shader: &'a wgpu::ShaderModule,
+
+ vertex_entry_point: Option<&'static str>,
+ fragment_entry_point: Option<&'static str>,
+
+ vertex_comp_options: Option<wgpu::PipelineCompilationOptions<'a>>,
+ fragment_comp_options: Option<wgpu::PipelineCompilationOptions<'a>>,
+
+ vertex_buffer_layouts: Vec<wgpu::VertexBufferLayout<'a>>
+}
+
+impl<'a> RenderPipelineBuilder<'a>
+{
+ pub fn new(
+ shader: &'a wgpu::ShaderModule)
+ -> Self {
+ Self {
+ bind_groups: Vec::new(),
+ shader: shader,
+
+ vertex_entry_point: Some("vs_main"),
+ fragment_entry_point: Some("fs_main"),
+
+ vertex_comp_options: None,
+ fragment_comp_options: None,
+
+ vertex_buffer_layouts: Vec::new()
+ }
+ }
+
+ pub fn add_bindgroup(
+ mut self,
+ bindgroup: &'a wgpu::BindGroupLayout)
+ -> Self {
+ self.bind_groups.push(bindgroup);
+ self
+ }
+
+ pub fn add_vertex_layout(
+ mut self,
+ layout: wgpu::VertexBufferLayout<'a>)
+ -> Self {
+ self.vertex_buffer_layouts.push(layout);
+ self
+ }
+
+ pub fn build(
+ self,
+ label: Option<&'static str>,
+ wgpuctx: &WgpuCtx)
+ -> wgpu::RenderPipeline
+ {
+ let layout_descr = wgpu::PipelineLayoutDescriptor {
+ label: label,
+ bind_group_layouts: self.bind_groups.as_slice(),
+ push_constant_ranges: &[]
+ };
+
+ let layout = wgpuctx.create_pipeline_layout(&layout_descr);
+
+ wgpuctx.create_render_pipeline(
+ &wgpu::RenderPipelineDescriptor {
+ label: label,
+ layout: Some(&layout),
+ vertex: wgpu::VertexState {
+ module: self.shader,
+ entry_point: self.vertex_entry_point,
+ compilation_options: match self.vertex_comp_options {
+ Some(option) => option,
+ None => wgpu::PipelineCompilationOptions::default()
+ },
+ buffers: self.vertex_buffer_layouts.as_slice()
+ },
+ fragment: Some(wgpu::FragmentState {
+ module: self.shader,
+ entry_point: self.fragment_entry_point,
+ compilation_options: match self.fragment_comp_options {
+ Some(option) => option,
+ None => wgpu::PipelineCompilationOptions::default()
+ },
+ targets: &[Some(wgpu::ColorTargetState {
+ format: wgpuctx.surface_config().format,
+ blend: Some(wgpu::BlendState{
+ color: wgpu::BlendComponent {
+ src_factor: wgpu::BlendFactor::SrcAlpha,
+ dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
+ operation: wgpu::BlendOperation::Add
+ },
+ alpha: wgpu::BlendComponent::OVER
+ }),
+ 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),
+ polygon_mode: wgpu::PolygonMode::Fill,
+ unclipped_depth: false,
+ conservative: false
+ },
+ depth_stencil: None,
+ multisample: wgpu::MultisampleState {
+ count: 1,
+ mask: !0,
+ alpha_to_coverage_enabled: false
+ },
+ multiview: None,
+ cache: None
+
+ }
+ )
+ }
+}