use crate::{
image,
pass,
pso::{
input_assembler::{AttributeDesc, InputAssemblerDesc, Primitive, VertexBufferDesc},
output_merger::{ColorBlendDesc, DepthStencilDesc, Face},
BasePipeline,
EntryPoint,
PipelineCreationFlags,
State,
},
Backend,
};
use std::ops::Range;
#[derive(Clone, Copy, Debug, Hash, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Rect {
pub x: i16,
pub y: i16,
pub w: i16,
pub h: i16,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ClearRect {
pub rect: Rect,
pub layers: Range<image::Layer>,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Viewport {
pub rect: Rect,
pub depth: Range<f32>,
}
pub type ColorValue = [f32; 4];
pub type DepthValue = f32;
pub type StencilValue = u32;
#[derive(Clone, Debug)]
pub struct GraphicsShaderSet<'a, B: Backend> {
pub vertex: EntryPoint<'a, B>,
pub hull: Option<EntryPoint<'a, B>>,
pub domain: Option<EntryPoint<'a, B>>,
pub geometry: Option<EntryPoint<'a, B>>,
pub fragment: Option<EntryPoint<'a, B>>,
}
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BakedStates {
pub viewport: Option<Viewport>,
pub scissor: Option<Rect>,
pub blend_color: Option<ColorValue>,
pub depth_bounds: Option<Range<f32>>,
}
#[derive(Debug)]
pub struct GraphicsPipelineDesc<'a, B: Backend> {
pub shaders: GraphicsShaderSet<'a, B>,
pub rasterizer: Rasterizer,
pub vertex_buffers: Vec<VertexBufferDesc>,
pub attributes: Vec<AttributeDesc>,
pub input_assembler: InputAssemblerDesc,
pub blender: BlendDesc,
pub depth_stencil: DepthStencilDesc,
pub multisampling: Option<Multisampling>,
pub baked_states: BakedStates,
pub layout: &'a B::PipelineLayout,
pub subpass: pass::Subpass<'a, B>,
pub flags: PipelineCreationFlags,
pub parent: BasePipeline<'a, B::GraphicsPipeline>,
}
impl<'a, B: Backend> GraphicsPipelineDesc<'a, B> {
pub fn new(
shaders: GraphicsShaderSet<'a, B>,
primitive: Primitive,
rasterizer: Rasterizer,
layout: &'a B::PipelineLayout,
subpass: pass::Subpass<'a, B>,
) -> Self {
GraphicsPipelineDesc {
shaders,
rasterizer,
vertex_buffers: Vec::new(),
attributes: Vec::new(),
input_assembler: InputAssemblerDesc::new(primitive),
blender: BlendDesc::default(),
depth_stencil: DepthStencilDesc::default(),
multisampling: None,
baked_states: BakedStates::default(),
layout,
subpass,
flags: PipelineCreationFlags::empty(),
parent: BasePipeline::None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum PolygonMode {
Point,
Line,
Fill,
}
#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub enum FrontFace {
Clockwise,
CounterClockwise,
}
#[derive(Copy, Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct DepthBias {
pub const_factor: f32,
pub clamp: f32,
pub slope_factor: f32,
}
#[derive(Copy, Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct Rasterizer {
pub polygon_mode: PolygonMode,
pub cull_face: Face,
pub front_face: FrontFace,
pub depth_clamping: bool,
pub depth_bias: Option<State<DepthBias>>,
pub conservative: bool,
pub line_width: State<f32>,
}
impl Rasterizer {
pub const FILL: Self = Rasterizer {
polygon_mode: PolygonMode::Fill,
cull_face: Face::NONE,
front_face: FrontFace::CounterClockwise,
depth_clamping: false,
depth_bias: None,
conservative: false,
line_width: State::Static(1.0),
};
}
#[derive(Clone, Debug, Default, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct BlendDesc {
pub logic_op: Option<LogicOp>,
pub targets: Vec<ColorBlendDesc>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[allow(missing_docs)]
pub enum LogicOp {
Clear = 0,
And = 1,
AndReverse = 2,
Copy = 3,
AndInverted = 4,
NoOp = 5,
Xor = 6,
Or = 7,
Nor = 8,
Equivalent = 9,
Invert = 10,
OrReverse = 11,
CopyInverted = 12,
OrInverted = 13,
Nand = 14,
Set = 15,
}
pub type SampleMask = u64;
#[derive(Clone, Debug, PartialEq)]
pub struct Multisampling {
pub rasterization_samples: image::NumSamples,
pub sample_shading: Option<f32>,
pub sample_mask: SampleMask,
pub alpha_coverage: bool,
pub alpha_to_one: bool,
}