use crate::{
anim_object::render::PipelineData,
renderer::{Vertex, camera_bind_group_layout, transform_bind_group_layout},
};
pub fn create_text_pipeline(
device: &wgpu::Device,
surface_format: wgpu::TextureFormat,
sample_count: u32,
) -> PipelineData {
let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor {
label: Some("text"),
source: wgpu::ShaderSource::Wgsl(include_str!("text.wgsl").into()),
});
let vertex_layout = wgpu::VertexBufferLayout {
array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
step_mode: wgpu::VertexStepMode::Vertex,
attributes: &[
wgpu::VertexAttribute {
offset: 0,
shader_location: 0,
format: wgpu::VertexFormat::Float32x2,
},
wgpu::VertexAttribute {
offset: std::mem::size_of::<[f32; 2]>() as wgpu::BufferAddress,
shader_location: 1,
format: wgpu::VertexFormat::Float32x4,
},
wgpu::VertexAttribute {
offset: std::mem::size_of::<[f32; 6]>() as wgpu::BufferAddress,
shader_location: 2,
format: wgpu::VertexFormat::Float32x2,
},
],
};
let texture_bind_group_layout =
device.create_bind_group_layout(&wgpu::BindGroupLayoutDescriptor {
label: Some("text_texture_bind_group_layout"),
entries: &[
wgpu::BindGroupLayoutEntry {
binding: 0,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Texture {
sample_type: wgpu::TextureSampleType::Float { filterable: true },
view_dimension: wgpu::TextureViewDimension::D2,
multisampled: false,
},
count: None,
},
wgpu::BindGroupLayoutEntry {
binding: 1,
visibility: wgpu::ShaderStages::FRAGMENT,
ty: wgpu::BindingType::Sampler(wgpu::SamplerBindingType::Filtering),
count: None,
},
],
});
let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
immediate_size: 0,
label: Some("text_pipeline_layout"),
bind_group_layouts: &[
Some(&camera_bind_group_layout(device)),
Some(&transform_bind_group_layout(device)),
Some(&texture_bind_group_layout),
],
});
let pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
multiview_mask: None,
cache: None,
label: Some("text_pipeline"),
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
compilation_options: Default::default(),
entry_point: Some("vs_main"),
buffers: &[vertex_layout],
},
fragment: Some(wgpu::FragmentState {
compilation_options: Default::default(),
module: &shader,
entry_point: Some("fs_main"),
targets: &[Some(wgpu::ColorTargetState {
format: surface_format,
blend: Some(wgpu::BlendState::ALPHA_BLENDING),
write_mask: wgpu::ColorWrites::ALL,
})],
}),
primitive: wgpu::PrimitiveState {
topology: wgpu::PrimitiveTopology::TriangleList,
strip_index_format: None,
front_face: wgpu::FrontFace::Ccw,
cull_mode: None,
polygon_mode: wgpu::PolygonMode::Fill,
unclipped_depth: false,
conservative: false,
},
depth_stencil: None,
multisample: wgpu::MultisampleState {
count: sample_count,
mask: !0,
alpha_to_coverage_enabled: false,
},
});
PipelineData {
pipeline,
bind_groups: vec![],
}
}