summaryrefslogtreecommitdiffstats
path: root/src/wgpuctx/mod.rs
diff options
context:
space:
mode:
authorJon Santmyer <jon@jonsantmyer.com>2026-04-22 15:40:32 -0400
committerJon Santmyer <jon@jonsantmyer.com>2026-04-22 15:40:32 -0400
commit25255a8b9147d27aa40b28d6aadb62c0ab275d32 (patch)
tree2d2ec324de7c0c16c098d85746ab060edb536f76 /src/wgpuctx/mod.rs
parent3d3864171785c589872bf23faaaa3a421f56ee4e (diff)
downloadsystemic4x-25255a8b9147d27aa40b28d6aadb62c0ab275d32.tar.gz
systemic4x-25255a8b9147d27aa40b28d6aadb62c0ab275d32.tar.bz2
systemic4x-25255a8b9147d27aa40b28d6aadb62c0ab275d32.zip
simplify rendering pipeline. add gridlines to tacmap
Diffstat (limited to 'src/wgpuctx/mod.rs')
-rw-r--r--src/wgpuctx/mod.rs71
1 files changed, 58 insertions, 13 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