2021-03-20 14:30:21 +00:00
|
|
|
use crate::{Error, MaskState, Vertex};
|
2020-10-14 18:25:55 +00:00
|
|
|
use enum_map::{enum_map, EnumMap};
|
2020-04-28 14:10:45 +00:00
|
|
|
use wgpu::vertex_attr_array;
|
|
|
|
|
2020-04-28 14:34:07 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ShapePipeline {
|
2020-10-14 18:25:55 +00:00
|
|
|
pub mask_pipelines: EnumMap<MaskState, wgpu::RenderPipeline>,
|
2020-04-28 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct Pipelines {
|
2020-10-17 19:05:16 +00:00
|
|
|
pub color_pipelines: ShapePipeline,
|
2020-10-17 21:39:24 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
pub bitmap_pipelines: ShapePipeline,
|
|
|
|
pub bitmap_layout: wgpu::BindGroupLayout,
|
2020-10-17 21:39:24 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
pub gradient_pipelines: ShapePipeline,
|
|
|
|
pub gradient_layout: wgpu::BindGroupLayout,
|
2020-04-28 14:34:07 +00:00
|
|
|
}
|
|
|
|
|
2020-04-28 20:48:17 +00:00
|
|
|
impl ShapePipeline {
|
2020-10-14 18:25:55 +00:00
|
|
|
pub fn pipeline_for(&self, mask_state: MaskState) -> &wgpu::RenderPipeline {
|
|
|
|
&self.mask_pipelines[mask_state]
|
2020-04-28 20:48:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 14:34:07 +00:00
|
|
|
impl Pipelines {
|
2020-10-15 22:55:19 +00:00
|
|
|
pub fn new(
|
|
|
|
device: &wgpu::Device,
|
|
|
|
msaa_sample_count: u32,
|
|
|
|
sampler_layout: &wgpu::BindGroupLayout,
|
2020-10-16 15:46:40 +00:00
|
|
|
globals_layout: &wgpu::BindGroupLayout,
|
2020-10-15 22:55:19 +00:00
|
|
|
) -> Result<Self, Error> {
|
2021-02-03 19:58:53 +00:00
|
|
|
// TODO: Naga validation errors when encountering push constants currently.
|
|
|
|
// Disable validation for now. Remove this when Naga can swallow it.
|
|
|
|
macro_rules! include_spirv {
|
|
|
|
($($token:tt)*) => {
|
|
|
|
{
|
|
|
|
wgpu::ShaderModuleDescriptor {
|
|
|
|
label: Some($($token)*),
|
|
|
|
source: wgpu::util::make_spirv(include_bytes!($($token)*)),
|
|
|
|
flags: wgpu::ShaderFlags::empty(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
let color_vs = device.create_shader_module(&include_spirv!("../shaders/color.vert.spv"));
|
|
|
|
let color_fs = device.create_shader_module(&include_spirv!("../shaders/color.frag.spv"));
|
2020-08-27 10:32:41 +00:00
|
|
|
let texture_vs =
|
2021-02-03 19:58:53 +00:00
|
|
|
device.create_shader_module(&include_spirv!("../shaders/texture.vert.spv"));
|
2020-08-27 10:32:41 +00:00
|
|
|
let gradient_fs =
|
2021-02-03 19:58:53 +00:00
|
|
|
device.create_shader_module(&include_spirv!("../shaders/gradient.frag.spv"));
|
|
|
|
let bitmap_fs = device.create_shader_module(&include_spirv!("../shaders/bitmap.frag.spv"));
|
2020-08-27 10:32:41 +00:00
|
|
|
|
2021-02-03 19:58:53 +00:00
|
|
|
let vertex_buffers_description = [wgpu::VertexBufferLayout {
|
2021-03-20 14:30:21 +00:00
|
|
|
array_stride: std::mem::size_of::<Vertex>() as u64,
|
2020-08-27 10:32:41 +00:00
|
|
|
step_mode: wgpu::InputStepMode::Vertex,
|
|
|
|
attributes: &vertex_attr_array![
|
|
|
|
0 => Float2,
|
|
|
|
1 => Float4
|
|
|
|
],
|
|
|
|
}];
|
2020-04-28 14:34:07 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
let color_pipelines = create_color_pipelines(
|
|
|
|
&device,
|
|
|
|
&color_vs,
|
|
|
|
&color_fs,
|
|
|
|
msaa_sample_count,
|
|
|
|
&vertex_buffers_description,
|
|
|
|
globals_layout,
|
|
|
|
);
|
|
|
|
|
2020-10-17 21:39:24 +00:00
|
|
|
let bitmap_bind_layout_label = create_debug_label!("Bitmap shape bind group layout");
|
2020-10-17 19:05:16 +00:00
|
|
|
let bitmap_bind_layout =
|
|
|
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
|
|
entries: &[
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
binding: 0,
|
|
|
|
visibility: wgpu::ShaderStage::VERTEX,
|
2020-12-04 18:47:20 +00:00
|
|
|
ty: wgpu::BindingType::Buffer {
|
|
|
|
ty: wgpu::BufferBindingType::Uniform,
|
|
|
|
has_dynamic_offset: false,
|
2020-10-17 19:05:16 +00:00
|
|
|
min_binding_size: None,
|
|
|
|
},
|
|
|
|
count: None,
|
|
|
|
},
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
binding: 1,
|
|
|
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
2020-12-04 18:47:20 +00:00
|
|
|
ty: wgpu::BindingType::Texture {
|
2020-10-17 19:05:16 +00:00
|
|
|
multisampled: false,
|
2020-12-04 18:47:20 +00:00
|
|
|
sample_type: wgpu::TextureSampleType::Float { filterable: true },
|
|
|
|
view_dimension: wgpu::TextureViewDimension::D2,
|
2020-10-17 19:05:16 +00:00
|
|
|
},
|
|
|
|
count: None,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
label: bitmap_bind_layout_label.as_deref(),
|
|
|
|
});
|
|
|
|
|
|
|
|
let bitmap_pipelines = create_bitmap_pipeline(
|
|
|
|
&device,
|
|
|
|
&texture_vs,
|
|
|
|
&bitmap_fs,
|
|
|
|
msaa_sample_count,
|
|
|
|
&vertex_buffers_description,
|
|
|
|
sampler_layout,
|
|
|
|
globals_layout,
|
|
|
|
&bitmap_bind_layout,
|
|
|
|
);
|
|
|
|
|
|
|
|
let gradient_bind_layout_label = create_debug_label!("Gradient shape bind group");
|
|
|
|
let gradient_bind_layout =
|
|
|
|
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
|
|
|
|
entries: &[
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
binding: 0,
|
|
|
|
visibility: wgpu::ShaderStage::VERTEX,
|
2020-12-04 18:47:20 +00:00
|
|
|
ty: wgpu::BindingType::Buffer {
|
|
|
|
ty: wgpu::BufferBindingType::Uniform,
|
|
|
|
has_dynamic_offset: false,
|
2020-10-17 19:05:16 +00:00
|
|
|
min_binding_size: None,
|
|
|
|
},
|
|
|
|
count: None,
|
|
|
|
},
|
|
|
|
wgpu::BindGroupLayoutEntry {
|
|
|
|
binding: 1,
|
|
|
|
visibility: wgpu::ShaderStage::FRAGMENT,
|
2020-12-04 18:47:20 +00:00
|
|
|
ty: wgpu::BindingType::Buffer {
|
|
|
|
ty: wgpu::BufferBindingType::Storage { read_only: true },
|
|
|
|
has_dynamic_offset: false,
|
2020-10-17 19:05:16 +00:00
|
|
|
min_binding_size: None,
|
|
|
|
},
|
|
|
|
count: None,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
label: gradient_bind_layout_label.as_deref(),
|
|
|
|
});
|
|
|
|
|
|
|
|
let gradient_pipelines = create_gradient_pipeline(
|
|
|
|
&device,
|
|
|
|
&texture_vs,
|
|
|
|
&gradient_fs,
|
|
|
|
msaa_sample_count,
|
|
|
|
&vertex_buffers_description,
|
|
|
|
globals_layout,
|
|
|
|
&gradient_bind_layout,
|
|
|
|
);
|
|
|
|
|
2020-04-28 14:34:07 +00:00
|
|
|
Ok(Self {
|
2020-10-17 19:05:16 +00:00
|
|
|
color_pipelines,
|
|
|
|
bitmap_pipelines,
|
|
|
|
bitmap_layout: bitmap_bind_layout,
|
|
|
|
gradient_pipelines,
|
|
|
|
gradient_layout: gradient_bind_layout,
|
2020-04-28 14:34:07 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-27 10:40:56 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-04-28 14:34:07 +00:00
|
|
|
fn create_pipeline_descriptor<'a>(
|
2020-08-27 10:40:56 +00:00
|
|
|
label: Option<&'a str>,
|
2020-04-28 14:10:45 +00:00
|
|
|
vertex_shader: &'a wgpu::ShaderModule,
|
|
|
|
fragment_shader: &'a wgpu::ShaderModule,
|
|
|
|
pipeline_layout: &'a wgpu::PipelineLayout,
|
2021-02-03 19:58:53 +00:00
|
|
|
depth_stencil_state: Option<wgpu::DepthStencilState>,
|
|
|
|
color_target_state: &'a [wgpu::ColorTargetState],
|
|
|
|
vertex_buffer_layout: &'a [wgpu::VertexBufferLayout<'a>],
|
2020-05-01 02:56:07 +00:00
|
|
|
msaa_sample_count: u32,
|
2020-04-28 14:10:45 +00:00
|
|
|
) -> wgpu::RenderPipelineDescriptor<'a> {
|
|
|
|
wgpu::RenderPipelineDescriptor {
|
2020-08-27 10:40:56 +00:00
|
|
|
label,
|
2020-08-27 10:32:41 +00:00
|
|
|
layout: Some(&pipeline_layout),
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex: wgpu::VertexState {
|
2020-04-28 14:10:45 +00:00
|
|
|
module: &vertex_shader,
|
|
|
|
entry_point: "main",
|
2021-02-03 19:58:53 +00:00
|
|
|
buffers: vertex_buffer_layout,
|
2020-04-28 14:10:45 +00:00
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
fragment: Some(wgpu::FragmentState {
|
2020-04-28 14:10:45 +00:00
|
|
|
module: &fragment_shader,
|
|
|
|
entry_point: "main",
|
2021-02-03 19:58:53 +00:00
|
|
|
targets: color_target_state,
|
2020-04-28 14:10:45 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
primitive: wgpu::PrimitiveState {
|
|
|
|
topology: wgpu::PrimitiveTopology::TriangleList,
|
|
|
|
strip_index_format: Some(wgpu::IndexFormat::Uint32),
|
2020-04-28 14:10:45 +00:00
|
|
|
front_face: wgpu::FrontFace::Ccw,
|
|
|
|
cull_mode: wgpu::CullMode::None,
|
2021-02-03 19:58:53 +00:00
|
|
|
polygon_mode: wgpu::PolygonMode::default(),
|
|
|
|
},
|
|
|
|
depth_stencil: depth_stencil_state,
|
|
|
|
multisample: wgpu::MultisampleState {
|
|
|
|
count: msaa_sample_count,
|
|
|
|
mask: !0,
|
|
|
|
alpha_to_coverage_enabled: false,
|
2020-04-28 14:10:45 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-28 20:48:17 +00:00
|
|
|
fn create_color_pipelines(
|
2020-04-28 14:10:45 +00:00
|
|
|
device: &wgpu::Device,
|
|
|
|
vertex_shader: &wgpu::ShaderModule,
|
|
|
|
fragment_shader: &wgpu::ShaderModule,
|
2020-05-01 02:56:07 +00:00
|
|
|
msaa_sample_count: u32,
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_description: &[wgpu::VertexBufferLayout<'_>],
|
2020-10-16 15:46:40 +00:00
|
|
|
globals_layout: &wgpu::BindGroupLayout,
|
2020-04-28 20:48:17 +00:00
|
|
|
) -> ShapePipeline {
|
2020-12-26 00:43:03 +00:00
|
|
|
let transforms_size = std::mem::size_of::<crate::Transforms>() as u32;
|
|
|
|
let colors_size = std::mem::size_of::<crate::ColorAdjustments>() as u32;
|
|
|
|
|
2020-08-27 10:40:56 +00:00
|
|
|
let pipeline_layout_label = create_debug_label!("Color shape pipeline layout");
|
2020-04-28 14:10:45 +00:00
|
|
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
2020-08-27 10:40:56 +00:00
|
|
|
label: pipeline_layout_label.as_deref(),
|
2020-12-26 00:43:03 +00:00
|
|
|
bind_group_layouts: &[globals_layout],
|
|
|
|
push_constant_ranges: &[
|
|
|
|
wgpu::PushConstantRange {
|
|
|
|
stages: wgpu::ShaderStage::VERTEX,
|
|
|
|
range: 0..transforms_size,
|
|
|
|
},
|
|
|
|
wgpu::PushConstantRange {
|
|
|
|
stages: wgpu::ShaderStage::FRAGMENT,
|
|
|
|
range: transforms_size..transforms_size + colors_size,
|
|
|
|
},
|
|
|
|
],
|
2020-04-28 14:10:45 +00:00
|
|
|
});
|
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
let mask_pipelines = enum_map! {
|
|
|
|
MaskState::NoMask => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::NoMask);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Color pipeline no mask").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
write_mask,
|
|
|
|
}],
|
|
|
|
vertex_buffers_description,
|
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Color pipeline draw mask stencil").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
|
|
|
vertex_buffers_description,
|
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 14:10:45 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskedContent => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskedContent);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Color pipeline draw masked content").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
|
|
|
vertex_buffers_description,
|
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|
|
|
|
MaskState::ClearMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::ClearMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Color pipeline clear mask stencil").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
write_mask,
|
|
|
|
}],
|
|
|
|
vertex_buffers_description,
|
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
};
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
ShapePipeline { mask_pipelines }
|
2020-04-28 14:10:45 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-04-28 14:34:07 +00:00
|
|
|
fn create_bitmap_pipeline(
|
2020-04-28 14:10:45 +00:00
|
|
|
device: &wgpu::Device,
|
|
|
|
vertex_shader: &wgpu::ShaderModule,
|
|
|
|
fragment_shader: &wgpu::ShaderModule,
|
2020-05-01 02:56:07 +00:00
|
|
|
msaa_sample_count: u32,
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout: &[wgpu::VertexBufferLayout<'_>],
|
2020-10-15 22:55:19 +00:00
|
|
|
sampler_layout: &wgpu::BindGroupLayout,
|
2020-10-16 15:46:40 +00:00
|
|
|
globals_layout: &wgpu::BindGroupLayout,
|
2020-10-17 19:05:16 +00:00
|
|
|
bitmap_bind_layout: &wgpu::BindGroupLayout,
|
2020-04-28 20:48:17 +00:00
|
|
|
) -> ShapePipeline {
|
2020-08-27 10:40:56 +00:00
|
|
|
let pipeline_layout_label = create_debug_label!("Bitmap shape pipeline layout");
|
2020-04-28 14:10:45 +00:00
|
|
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
2020-08-27 10:40:56 +00:00
|
|
|
label: pipeline_layout_label.as_deref(),
|
2020-12-26 00:43:03 +00:00
|
|
|
bind_group_layouts: &[globals_layout, bitmap_bind_layout, sampler_layout],
|
|
|
|
push_constant_ranges: &[
|
|
|
|
wgpu::PushConstantRange {
|
|
|
|
stages: wgpu::ShaderStage::VERTEX,
|
|
|
|
range: 0..64,
|
|
|
|
},
|
|
|
|
wgpu::PushConstantRange {
|
|
|
|
stages: wgpu::ShaderStage::FRAGMENT,
|
|
|
|
range: 64..96,
|
|
|
|
},
|
2020-10-17 21:39:24 +00:00
|
|
|
],
|
2020-04-28 14:10:45 +00:00
|
|
|
});
|
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
let mask_pipelines = enum_map! {
|
|
|
|
MaskState::NoMask => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::NoMask);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Bitmap pipeline no mask").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-15 22:28:17 +00:00
|
|
|
src_factor: wgpu::BlendFactor::One,
|
2020-10-14 18:25:55 +00:00
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 14:10:45 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Bitmap pipeline draw mask stencil").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskedContent => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskedContent);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Bitmap pipeline draw masked content").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Equal,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-15 22:28:17 +00:00
|
|
|
src_factor: wgpu::BlendFactor::One,
|
2020-10-14 18:25:55 +00:00
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|
|
|
|
MaskState::ClearMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::ClearMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Bitmap pipeline clear mask stencil").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
};
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
ShapePipeline { mask_pipelines }
|
2020-04-28 14:10:45 +00:00
|
|
|
}
|
|
|
|
|
2020-10-17 21:39:24 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2020-04-28 14:34:07 +00:00
|
|
|
fn create_gradient_pipeline(
|
2020-04-28 14:10:45 +00:00
|
|
|
device: &wgpu::Device,
|
|
|
|
vertex_shader: &wgpu::ShaderModule,
|
|
|
|
fragment_shader: &wgpu::ShaderModule,
|
2020-05-01 02:56:07 +00:00
|
|
|
msaa_sample_count: u32,
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout: &[wgpu::VertexBufferLayout<'_>],
|
2020-10-16 15:46:40 +00:00
|
|
|
globals_layout: &wgpu::BindGroupLayout,
|
2020-10-17 19:05:16 +00:00
|
|
|
gradient_bind_layout: &wgpu::BindGroupLayout,
|
2020-04-28 20:48:17 +00:00
|
|
|
) -> ShapePipeline {
|
2020-08-27 10:40:56 +00:00
|
|
|
let pipeline_layout_label = create_debug_label!("Gradient shape pipeline layout");
|
2020-04-28 14:10:45 +00:00
|
|
|
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
|
2020-08-27 10:40:56 +00:00
|
|
|
label: pipeline_layout_label.as_deref(),
|
2020-12-26 00:43:03 +00:00
|
|
|
bind_group_layouts: &[globals_layout, gradient_bind_layout],
|
|
|
|
push_constant_ranges: &[
|
|
|
|
wgpu::PushConstantRange {
|
|
|
|
stages: wgpu::ShaderStage::VERTEX,
|
|
|
|
range: 0..64,
|
|
|
|
},
|
|
|
|
wgpu::PushConstantRange {
|
|
|
|
stages: wgpu::ShaderStage::FRAGMENT,
|
|
|
|
range: 64..96,
|
|
|
|
},
|
|
|
|
],
|
2020-04-28 14:10:45 +00:00
|
|
|
});
|
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
let mask_pipelines = enum_map! {
|
|
|
|
MaskState::NoMask => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::NoMask);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Gradient pipeline no mask").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
MaskState::DrawMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Gradient pipeline draw mask stencil").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
2020-04-28 14:10:45 +00:00
|
|
|
|
2020-10-14 18:25:55 +00:00
|
|
|
|
|
|
|
MaskState::DrawMaskedContent => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::DrawMaskedContent);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Gradient pipeline draw masked content").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Equal,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
2020-08-27 10:32:41 +00:00
|
|
|
},
|
2020-10-14 18:25:55 +00:00
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
},
|
|
|
|
|
|
|
|
MaskState::ClearMaskStencil => {
|
|
|
|
let (stencil, write_mask) = mask_render_state(MaskState::ClearMaskStencil);
|
|
|
|
device.create_render_pipeline(&create_pipeline_descriptor(
|
|
|
|
create_debug_label!("Gradient pipeline clear mask stencil").as_deref(),
|
|
|
|
vertex_shader,
|
|
|
|
fragment_shader,
|
|
|
|
&pipeline_layout,
|
2021-02-03 19:58:53 +00:00
|
|
|
Some(wgpu::DepthStencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Depth24PlusStencil8,
|
|
|
|
depth_write_enabled: true,
|
|
|
|
depth_compare: wgpu::CompareFunction::Always,
|
|
|
|
stencil,
|
2021-02-03 19:58:53 +00:00
|
|
|
bias: Default::default(),
|
|
|
|
clamp_depth: false,
|
2020-10-14 18:25:55 +00:00
|
|
|
}),
|
2021-02-03 19:58:53 +00:00
|
|
|
&[wgpu::ColorTargetState {
|
2020-10-14 18:25:55 +00:00
|
|
|
format: wgpu::TextureFormat::Bgra8Unorm,
|
2021-02-03 19:58:53 +00:00
|
|
|
color_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
2021-02-03 19:58:53 +00:00
|
|
|
alpha_blend: wgpu::BlendState {
|
2020-10-14 18:25:55 +00:00
|
|
|
src_factor: wgpu::BlendFactor::SrcAlpha,
|
|
|
|
dst_factor: wgpu::BlendFactor::OneMinusSrcAlpha,
|
|
|
|
operation: wgpu::BlendOperation::Add,
|
|
|
|
},
|
|
|
|
write_mask,
|
|
|
|
}],
|
2021-02-03 19:58:53 +00:00
|
|
|
vertex_buffers_layout,
|
2020-10-14 18:25:55 +00:00
|
|
|
msaa_sample_count,
|
|
|
|
))
|
|
|
|
}
|
|
|
|
};
|
2020-04-28 20:48:17 +00:00
|
|
|
|
2020-10-17 19:05:16 +00:00
|
|
|
ShapePipeline { mask_pipelines }
|
2020-04-28 14:10:45 +00:00
|
|
|
}
|
2020-10-14 18:25:55 +00:00
|
|
|
|
2021-02-03 19:58:53 +00:00
|
|
|
fn mask_render_state(state: MaskState) -> (wgpu::StencilState, wgpu::ColorWrite) {
|
2020-10-14 18:25:55 +00:00
|
|
|
let (stencil_state, color_write) = match state {
|
|
|
|
MaskState::NoMask => (
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilFaceState {
|
2020-10-14 18:25:55 +00:00
|
|
|
compare: wgpu::CompareFunction::Always,
|
|
|
|
fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
depth_fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
pass_op: wgpu::StencilOperation::Keep,
|
|
|
|
},
|
|
|
|
wgpu::ColorWrite::ALL,
|
|
|
|
),
|
|
|
|
MaskState::DrawMaskStencil => (
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilFaceState {
|
2020-10-14 18:25:55 +00:00
|
|
|
compare: wgpu::CompareFunction::Equal,
|
|
|
|
fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
depth_fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
pass_op: wgpu::StencilOperation::IncrementClamp,
|
|
|
|
},
|
|
|
|
wgpu::ColorWrite::empty(),
|
|
|
|
),
|
|
|
|
MaskState::DrawMaskedContent => (
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilFaceState {
|
2020-10-14 18:25:55 +00:00
|
|
|
compare: wgpu::CompareFunction::Equal,
|
|
|
|
fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
depth_fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
pass_op: wgpu::StencilOperation::Keep,
|
|
|
|
},
|
|
|
|
wgpu::ColorWrite::ALL,
|
|
|
|
),
|
|
|
|
MaskState::ClearMaskStencil => (
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilFaceState {
|
2020-10-14 18:25:55 +00:00
|
|
|
compare: wgpu::CompareFunction::Equal,
|
|
|
|
fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
depth_fail_op: wgpu::StencilOperation::Keep,
|
|
|
|
pass_op: wgpu::StencilOperation::DecrementClamp,
|
|
|
|
},
|
|
|
|
wgpu::ColorWrite::empty(),
|
|
|
|
),
|
|
|
|
};
|
|
|
|
|
|
|
|
(
|
2021-02-03 19:58:53 +00:00
|
|
|
wgpu::StencilState {
|
2020-10-14 18:25:55 +00:00
|
|
|
front: stencil_state.clone(),
|
|
|
|
back: stencil_state,
|
|
|
|
read_mask: 0xff,
|
|
|
|
write_mask: 0xff,
|
|
|
|
},
|
|
|
|
color_write,
|
|
|
|
)
|
|
|
|
}
|