diff options
| author | Jon Santmyer <jon@jonsantmyer.com> | 2026-04-22 15:40:32 -0400 |
|---|---|---|
| committer | Jon Santmyer <jon@jonsantmyer.com> | 2026-04-22 15:40:32 -0400 |
| commit | 25255a8b9147d27aa40b28d6aadb62c0ab275d32 (patch) | |
| tree | 2d2ec324de7c0c16c098d85746ab060edb536f76 /src/wgpuctx | |
| parent | 3d3864171785c589872bf23faaaa3a421f56ee4e (diff) | |
| download | systemic4x-25255a8b9147d27aa40b28d6aadb62c0ab275d32.tar.gz systemic4x-25255a8b9147d27aa40b28d6aadb62c0ab275d32.tar.bz2 systemic4x-25255a8b9147d27aa40b28d6aadb62c0ab275d32.zip | |
simplify rendering pipeline. add gridlines to tacmap
Diffstat (limited to 'src/wgpuctx')
| -rw-r--r-- | src/wgpuctx/mod.rs | 71 | ||||
| -rw-r--r-- | src/wgpuctx/pipeline.rs | 17 |
2 files changed, 72 insertions, 16 deletions
diff --git a/src/wgpuctx/mod.rs b/src/wgpuctx/mod.rs index f8aa3ec..5f26a99 100644 --- a/src/wgpuctx/mod.rs +++ b/src/wgpuctx/mod.rs @@ -19,11 +19,10 @@ pub struct WgpuCtx queue: wgpu::Queue, } -pub struct RenderPassBuilder<'encoder> +pub struct SceneCtx<'view> { - label: &'static str, - view: &'encoder wgpu::TextureView, - clear_color: wgpu::Color + view: &'view wgpu::TextureView, + encoder: wgpu::CommandEncoder } impl WgpuCtx @@ -127,11 +126,11 @@ impl WgpuCtx pub fn create_default_encoder( &self, - label: &'static str) + label: Option<&'static str>) -> wgpu::CommandEncoder { self.create_encoder( &wgpu::CommandEncoderDescriptor { - label: Some(label) + label: label } ) } @@ -198,16 +197,53 @@ impl WgpuCtx } //impl WgpuCtx +impl<'view> SceneCtx<'view> +{ + pub fn from_view_default( + wgpuctx: &WgpuCtx, + view: &'view wgpu::TextureView, + label: Option<&'static str>) + -> Self { + Self { + view: view, + encoder: wgpuctx.create_default_encoder(label) + } + } + + pub fn view(&self) -> &'view wgpu::TextureView + { self.view } + + pub fn encoder(&self) -> &wgpu::CommandEncoder + { &self.encoder } + + pub fn encoder_mut(&mut self) -> &mut wgpu::CommandEncoder + { &mut self.encoder } + + pub fn submit( + self, + wgpuctx: &WgpuCtx) + { + wgpuctx.submit_encoder(self.encoder); + } +} + +pub struct RenderPassBuilder<'encoder> +{ + label: Option<&'static str>, + view: &'encoder wgpu::TextureView, + clear_color: Option<wgpu::Color> +} + impl<'encoder> RenderPassBuilder<'encoder> { pub fn new( - label: &'static str, + label: Option<&'static str>, view: &'encoder wgpu::TextureView) -> Self { Self { label: label, view: view, - clear_color: wgpu::Color { r: 0.0, g: 0.0, b: 0.0, a: 1.0 } + clear_color: None } } @@ -215,24 +251,27 @@ impl<'encoder> RenderPassBuilder<'encoder> mut self, color: wgpu::Color) -> Self { - self.clear_color = color; + self.clear_color = Some(color); self } - pub fn build( + pub fn build_from_encoder( self, encoder: &'encoder mut wgpu::CommandEncoder) -> wgpu::RenderPass<'encoder> { encoder.begin_render_pass( &wgpu::RenderPassDescriptor { - label: Some(self.label), + label: self.label, color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: self.view, resolve_target: None, depth_slice: None, ops: wgpu::Operations { - load: wgpu::LoadOp::Clear(self.clear_color), + load: match self.clear_color { + Some(color) => wgpu::LoadOp::Clear(color), + None => wgpu::LoadOp::Load + }, store: wgpu::StoreOp::Store } })], @@ -242,4 +281,10 @@ impl<'encoder> RenderPassBuilder<'encoder> } ) } -} + + pub fn build_from_scene( + self, + scene: &'encoder mut SceneCtx) + -> wgpu::RenderPass<'encoder> + { self.build_from_encoder(scene.encoder_mut()) } +}// impl RenderPassBuilder diff --git a/src/wgpuctx/pipeline.rs b/src/wgpuctx/pipeline.rs index 7606203..0811800 100644 --- a/src/wgpuctx/pipeline.rs +++ b/src/wgpuctx/pipeline.rs @@ -12,7 +12,9 @@ pub struct RenderPipelineBuilder<'a> vertex_comp_options: Option<wgpu::PipelineCompilationOptions<'a>>, fragment_comp_options: Option<wgpu::PipelineCompilationOptions<'a>>, - vertex_buffer_layouts: Vec<wgpu::VertexBufferLayout<'a>> + vertex_buffer_layouts: Vec<wgpu::VertexBufferLayout<'a>>, + + cull_mode: Option<wgpu::Face> } impl<'a> RenderPipelineBuilder<'a> @@ -30,7 +32,9 @@ impl<'a> RenderPipelineBuilder<'a> vertex_comp_options: None, fragment_comp_options: None, - vertex_buffer_layouts: Vec::new() + vertex_buffer_layouts: Vec::new(), + + cull_mode: Some(wgpu::Face::Back) } } @@ -50,6 +54,13 @@ impl<'a> RenderPipelineBuilder<'a> self } + pub fn cull_mode( + mut self, + mode: Option<wgpu::Face> + ) -> Self { + self.cull_mode = mode; self + } + pub fn build( self, label: Option<&'static str>, @@ -101,7 +112,7 @@ impl<'a> RenderPipelineBuilder<'a> topology: wgpu::PrimitiveTopology::TriangleList, strip_index_format: None, front_face: wgpu::FrontFace::Ccw, - cull_mode: Some(wgpu::Face::Back), + cull_mode: self.cull_mode, polygon_mode: wgpu::PolygonMode::Fill, unclipped_depth: false, conservative: false |
