117 lines
4.3 KiB
Rust
117 lines
4.3 KiB
Rust
use super::{
|
|
state_descriptors::{
|
|
BlendDescriptor, BlendFactor, BlendOperation, ColorStateDescriptor, ColorWrite,
|
|
CompareFunction, CullMode, DepthStencilStateDescriptor, FrontFace, IndexFormat,
|
|
PrimitiveTopology, RasterizationStateDescriptor, StencilStateFaceDescriptor,
|
|
},
|
|
PipelineLayout, StencilStateDescriptor,
|
|
};
|
|
use crate::{shader::ShaderStages, texture::TextureFormat};
|
|
use bevy_reflect::TypeUuid;
|
|
|
|
#[derive(Clone, Debug, TypeUuid)]
|
|
#[uuid = "ebfc1d11-a2a4-44cb-8f12-c49cc631146c"]
|
|
pub struct PipelineDescriptor {
|
|
pub name: Option<String>,
|
|
pub layout: Option<PipelineLayout>,
|
|
pub shader_stages: ShaderStages,
|
|
pub rasterization_state: Option<RasterizationStateDescriptor>,
|
|
|
|
/// The primitive topology used to interpret vertices.
|
|
pub primitive_topology: PrimitiveTopology,
|
|
|
|
/// The effect of draw calls on the color aspect of the output target.
|
|
pub color_states: Vec<ColorStateDescriptor>,
|
|
|
|
/// The effect of draw calls on the depth and stencil aspects of the output target, if any.
|
|
pub depth_stencil_state: Option<DepthStencilStateDescriptor>,
|
|
|
|
/// The format of any index buffers used with this pipeline.
|
|
pub index_format: IndexFormat,
|
|
|
|
/// The number of samples calculated per pixel (for MSAA).
|
|
pub sample_count: u32,
|
|
|
|
/// Bitmask that restricts the samples of a pixel modified by this pipeline.
|
|
pub sample_mask: u32,
|
|
|
|
/// When enabled, produces another sample mask per pixel based on the alpha output value, that
|
|
/// is AND-ed with the sample_mask and the primitive coverage to restrict the set of samples
|
|
/// affected by a primitive.
|
|
/// The implicit mask produced for alpha of zero is guaranteed to be zero, and for alpha of one
|
|
/// is guaranteed to be all 1-s.
|
|
pub alpha_to_coverage_enabled: bool,
|
|
}
|
|
|
|
impl PipelineDescriptor {
|
|
pub fn new(shader_stages: ShaderStages) -> Self {
|
|
PipelineDescriptor {
|
|
name: None,
|
|
layout: None,
|
|
color_states: Vec::new(),
|
|
depth_stencil_state: None,
|
|
shader_stages,
|
|
rasterization_state: None,
|
|
primitive_topology: PrimitiveTopology::TriangleList,
|
|
index_format: IndexFormat::Uint32,
|
|
sample_count: 1,
|
|
sample_mask: !0,
|
|
alpha_to_coverage_enabled: false,
|
|
}
|
|
}
|
|
|
|
pub fn default_config(shader_stages: ShaderStages) -> Self {
|
|
PipelineDescriptor {
|
|
name: None,
|
|
primitive_topology: PrimitiveTopology::TriangleList,
|
|
layout: None,
|
|
index_format: IndexFormat::Uint32,
|
|
sample_count: 1,
|
|
sample_mask: !0,
|
|
alpha_to_coverage_enabled: false,
|
|
rasterization_state: Some(RasterizationStateDescriptor {
|
|
front_face: FrontFace::Ccw,
|
|
cull_mode: CullMode::Back,
|
|
depth_bias: 0,
|
|
depth_bias_slope_scale: 0.0,
|
|
depth_bias_clamp: 0.0,
|
|
clamp_depth: false,
|
|
}),
|
|
depth_stencil_state: Some(DepthStencilStateDescriptor {
|
|
format: TextureFormat::Depth32Float,
|
|
depth_write_enabled: true,
|
|
depth_compare: CompareFunction::Less,
|
|
stencil: StencilStateDescriptor {
|
|
front: StencilStateFaceDescriptor::IGNORE,
|
|
back: StencilStateFaceDescriptor::IGNORE,
|
|
read_mask: 0,
|
|
write_mask: 0,
|
|
},
|
|
}),
|
|
color_states: vec![ColorStateDescriptor {
|
|
format: TextureFormat::default(),
|
|
color_blend: BlendDescriptor {
|
|
src_factor: BlendFactor::SrcAlpha,
|
|
dst_factor: BlendFactor::OneMinusSrcAlpha,
|
|
operation: BlendOperation::Add,
|
|
},
|
|
alpha_blend: BlendDescriptor {
|
|
src_factor: BlendFactor::One,
|
|
dst_factor: BlendFactor::One,
|
|
operation: BlendOperation::Add,
|
|
},
|
|
write_mask: ColorWrite::ALL,
|
|
}],
|
|
shader_stages,
|
|
}
|
|
}
|
|
|
|
pub fn get_layout(&self) -> Option<&PipelineLayout> {
|
|
self.layout.as_ref()
|
|
}
|
|
|
|
pub fn get_layout_mut(&mut self) -> Option<&mut PipelineLayout> {
|
|
self.layout.as_mut()
|
|
}
|
|
}
|