use crate::{
format::Format,
pipeline::graphics::vertex_input::{VertexInputState, VertexMemberTy},
shader::ShaderInterface,
};
use std::{
error::Error,
fmt::{Display, Error as FmtError, Formatter},
};
pub unsafe trait VertexDefinition {
fn definition(
&self,
interface: &ShaderInterface,
) -> Result<VertexInputState, IncompatibleVertexDefinitionError>;
}
unsafe impl VertexDefinition for VertexInputState {
fn definition(
&self,
_interface: &ShaderInterface,
) -> Result<VertexInputState, IncompatibleVertexDefinitionError> {
Ok(self.clone())
}
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum IncompatibleVertexDefinitionError {
MissingAttribute {
attribute: String,
},
FormatMismatch {
attribute: String,
shader: (Format, usize),
definition: (VertexMemberTy, usize),
},
}
impl Error for IncompatibleVertexDefinitionError {}
impl Display for IncompatibleVertexDefinitionError {
fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), FmtError> {
match self {
IncompatibleVertexDefinitionError::MissingAttribute { .. } => {
write!(f, "an attribute is missing")
}
IncompatibleVertexDefinitionError::FormatMismatch { .. } => {
write!(f, "the format of an attribute does not match")
}
}
}
}