From 35deadc10859761554868340f1e4b900fc8ce188 Mon Sep 17 00:00:00 2001 From: Mauro Gentile <62186646+gents83@users.noreply.github.com> Date: Sat, 3 Sep 2022 00:35:42 +0200 Subject: [PATCH] Depth clear value for web target (#2984) * Fix depth clear value on web * Defaulting to 0. * Added also stencil clear Co-authored-by: Mauro Gentile --- wgpu/src/backend/web.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index 15ed91356e..f816125148 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -2066,10 +2066,15 @@ impl crate::Context for Context { } if let Some(dsa) = &desc.depth_stencil_attachment { + let mut depth_clear_value = 0.0; + let mut stencil_clear_value = 0; let (depth_load_op, depth_store_op) = match dsa.depth_ops { Some(ref ops) => { let load_op = match ops.load { - crate::LoadOp::Clear(_) => web_sys::GpuLoadOp::Clear, + crate::LoadOp::Clear(v) => { + depth_clear_value = v; + web_sys::GpuLoadOp::Clear + } crate::LoadOp::Load => web_sys::GpuLoadOp::Load, }; (load_op, map_store_op(ops.store)) @@ -2079,7 +2084,10 @@ impl crate::Context for Context { let (stencil_load_op, stencil_store_op) = match dsa.stencil_ops { Some(ref ops) => { let load_op = match ops.load { - crate::LoadOp::Clear(_) => web_sys::GpuLoadOp::Clear, + crate::LoadOp::Clear(v) => { + stencil_clear_value = v; + web_sys::GpuLoadOp::Clear + } crate::LoadOp::Load => web_sys::GpuLoadOp::Load, }; (load_op, map_store_op(ops.store)) @@ -2088,8 +2096,10 @@ impl crate::Context for Context { }; let mut mapped_depth_stencil_attachment = web_sys::GpuRenderPassDepthStencilAttachment::new(&dsa.view.id.0); + mapped_depth_stencil_attachment.depth_clear_value(depth_clear_value); mapped_depth_stencil_attachment.depth_load_op(depth_load_op); mapped_depth_stencil_attachment.depth_store_op(depth_store_op); + mapped_depth_stencil_attachment.stencil_clear_value(stencil_clear_value); mapped_depth_stencil_attachment.stencil_load_op(stencil_load_op); mapped_depth_stencil_attachment.stencil_store_op(stencil_store_op); mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment);