use crate::format::Format;
use crate::pipeline::graphics::vertex_input::VertexInputState;
use crate::pipeline::graphics::vertex_input::VertexMemberTy;
use crate::shader::ShaderInterface;
use std::error;
use std::fmt;
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::Error for IncompatibleVertexDefinitionError {}
impl fmt::Display for IncompatibleVertexDefinitionError {
#[inline]
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {
IncompatibleVertexDefinitionError::MissingAttribute { .. } => {
write!(fmt, "an attribute is missing",)
}
IncompatibleVertexDefinitionError::FormatMismatch { .. } => {
write!(fmt, "the format of an attribute does not match")
}
}
}
}