use crate::{
macros::vulkan_enum,
pipeline::{PartialStateMode, StateMode},
DeviceSize,
};
#[derive(Clone, Copy, Debug)]
pub struct InputAssemblyState {
pub topology: PartialStateMode<PrimitiveTopology, PrimitiveTopologyClass>,
pub primitive_restart_enable: StateMode<bool>,
}
impl InputAssemblyState {
#[inline]
pub fn new() -> Self {
Self {
topology: PartialStateMode::Fixed(PrimitiveTopology::TriangleList),
primitive_restart_enable: StateMode::Fixed(false),
}
}
#[inline]
pub fn topology(mut self, topology: PrimitiveTopology) -> Self {
self.topology = PartialStateMode::Fixed(topology);
self
}
#[inline]
pub fn topology_dynamic(mut self, topology_class: PrimitiveTopologyClass) -> Self {
self.topology = PartialStateMode::Dynamic(topology_class);
self
}
#[inline]
pub fn primitive_restart_enable(mut self) -> Self {
self.primitive_restart_enable = StateMode::Fixed(true);
self
}
#[inline]
pub fn primitive_restart_enable_dynamic(mut self) -> Self {
self.primitive_restart_enable = StateMode::Dynamic;
self
}
}
impl Default for InputAssemblyState {
#[inline]
fn default() -> Self {
Self::new()
}
}
vulkan_enum! {
#[non_exhaustive]
PrimitiveTopology = PrimitiveTopology(i32);
PointList = POINT_LIST,
LineList = LINE_LIST,
LineStrip = LINE_STRIP,
TriangleList = TRIANGLE_LIST,
TriangleStrip = TRIANGLE_STRIP,
TriangleFan = TRIANGLE_FAN,
LineListWithAdjacency = LINE_LIST_WITH_ADJACENCY,
LineStripWithAdjacency = LINE_STRIP_WITH_ADJACENCY,
TriangleListWithAdjacency = TRIANGLE_LIST_WITH_ADJACENCY,
TriangleStripWithAdjacency = TRIANGLE_STRIP_WITH_ADJACENCY,
PatchList = PATCH_LIST,
}
impl Default for PrimitiveTopology {
#[inline]
fn default() -> Self {
PrimitiveTopology::TriangleList
}
}
impl PrimitiveTopology {
#[inline]
pub fn class(&self) -> PrimitiveTopologyClass {
match self {
Self::PointList => PrimitiveTopologyClass::Point,
Self::LineList
| Self::LineStrip
| Self::LineListWithAdjacency
| Self::LineStripWithAdjacency => PrimitiveTopologyClass::Line,
Self::TriangleList
| Self::TriangleStrip
| Self::TriangleFan
| Self::TriangleListWithAdjacency
| Self::TriangleStripWithAdjacency => PrimitiveTopologyClass::Triangle,
Self::PatchList => PrimitiveTopologyClass::Patch,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum PrimitiveTopologyClass {
Point,
Line,
Triangle,
Patch,
}
impl PrimitiveTopologyClass {
pub(crate) fn example(&self) -> PrimitiveTopology {
match self {
Self::Point => PrimitiveTopology::PointList,
Self::Line => PrimitiveTopology::LineList,
Self::Triangle => PrimitiveTopology::TriangleList,
Self::Patch => PrimitiveTopology::PatchList,
}
}
}
pub unsafe trait Index {
fn ty() -> IndexType;
}
unsafe impl Index for u8 {
#[inline(always)]
fn ty() -> IndexType {
IndexType::U8
}
}
unsafe impl Index for u16 {
#[inline(always)]
fn ty() -> IndexType {
IndexType::U16
}
}
unsafe impl Index for u32 {
#[inline(always)]
fn ty() -> IndexType {
IndexType::U32
}
}
vulkan_enum! {
#[non_exhaustive]
IndexType = IndexType(i32);
U8 = UINT8_EXT {
device_extensions: [ext_index_type_uint8],
},
U16 = UINT16,
U32 = UINT32,
}
impl IndexType {
#[inline]
pub fn size(&self) -> DeviceSize {
match self {
IndexType::U8 => 1,
IndexType::U16 => 2,
IndexType::U32 => 4,
}
}
}