use crate::{macros::vulkan_enum, pipeline::StateMode};
use std::ops::RangeInclusive;
#[derive(Clone, Debug)]
pub struct DepthStencilState {
pub depth: Option<DepthState>,
pub depth_bounds: Option<DepthBoundsState>,
pub stencil: Option<StencilState>,
}
impl DepthStencilState {
#[inline]
pub fn disabled() -> Self {
Self {
depth: Default::default(),
depth_bounds: Default::default(),
stencil: Default::default(),
}
}
#[inline]
pub fn simple_depth_test() -> Self {
Self {
depth: Some(DepthState {
enable_dynamic: false,
compare_op: StateMode::Fixed(CompareOp::Less),
write_enable: StateMode::Fixed(true),
}),
depth_bounds: Default::default(),
stencil: Default::default(),
}
}
}
impl Default for DepthStencilState {
#[inline]
fn default() -> Self {
DepthStencilState::disabled()
}
}
#[derive(Clone, Copy, Debug)]
pub struct DepthState {
pub enable_dynamic: bool,
pub write_enable: StateMode<bool>,
pub compare_op: StateMode<CompareOp>,
}
impl Default for DepthState {
#[inline]
fn default() -> Self {
Self {
enable_dynamic: false,
write_enable: StateMode::Fixed(false),
compare_op: StateMode::Fixed(CompareOp::Always),
}
}
}
#[derive(Clone, Debug)]
pub struct DepthBoundsState {
pub enable_dynamic: bool,
pub bounds: StateMode<RangeInclusive<f32>>,
}
impl Default for DepthBoundsState {
#[inline]
fn default() -> Self {
Self {
enable_dynamic: false,
bounds: StateMode::Fixed(0.0..=1.0),
}
}
}
#[derive(Clone, Debug)]
pub struct StencilState {
pub enable_dynamic: bool,
pub front: StencilOpState,
pub back: StencilOpState,
}
#[derive(Clone, Copy, Debug)]
pub struct StencilOpState {
pub ops: StateMode<StencilOps>,
pub compare_mask: StateMode<u32>,
pub write_mask: StateMode<u32>,
pub reference: StateMode<u32>,
}
impl Default for StencilOpState {
#[inline]
fn default() -> StencilOpState {
StencilOpState {
ops: StateMode::Fixed(Default::default()),
compare_mask: StateMode::Fixed(u32::MAX),
write_mask: StateMode::Fixed(u32::MAX),
reference: StateMode::Fixed(u32::MAX),
}
}
}
#[derive(Clone, Copy, Debug)]
pub struct StencilOps {
pub fail_op: StencilOp,
pub pass_op: StencilOp,
pub depth_fail_op: StencilOp,
pub compare_op: CompareOp,
}
impl Default for StencilOps {
#[inline]
fn default() -> Self {
Self {
pass_op: StencilOp::Keep,
fail_op: StencilOp::Keep,
depth_fail_op: StencilOp::Keep,
compare_op: CompareOp::Never,
}
}
}
vulkan_enum! {
#[non_exhaustive]
StencilOp = StencilOp(i32);
Keep = KEEP,
Zero = ZERO,
Replace = REPLACE,
IncrementAndClamp = INCREMENT_AND_CLAMP,
DecrementAndClamp = DECREMENT_AND_CLAMP,
Invert = INVERT,
IncrementAndWrap = INCREMENT_AND_WRAP,
DecrementAndWrap = DECREMENT_AND_WRAP,
}
vulkan_enum! {
#[non_exhaustive]
StencilFaces = StencilFaceFlags(u32);
Front = FRONT,
Back = BACK,
FrontAndBack = FRONT_AND_BACK,
}
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub struct DynamicStencilValue {
pub front: u32,
pub back: u32,
}
vulkan_enum! {
#[non_exhaustive]
CompareOp = CompareOp(i32);
Never = NEVER,
Less = LESS,
Equal = EQUAL,
LessOrEqual = LESS_OR_EQUAL,
Greater = GREATER,
NotEqual = NOT_EQUAL,
GreaterOrEqual = GREATER_OR_EQUAL,
Always = ALWAYS,
}