diff options
Diffstat (limited to 'src/wgpuctx/mod.rs')
| -rw-r--r-- | src/wgpuctx/mod.rs | 71 |
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 |
