1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::error::ShaderCompileError;
use librashader_preprocess::ShaderSource;

#[cfg(feature = "unstable-naga")]
mod naga;

mod shaderc;

pub use crate::front::shaderc::GlslangCompilation;

#[cfg(feature = "unstable-naga")]
pub use crate::front::naga::NagaCompilation;

/// Trait for types that can compile shader sources into a compilation unit.
pub trait ShaderCompilation: Sized {
    /// Compile the input shader source file into a compilation unit.
    fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError>;
}

impl<T: for<'a> TryFrom<&'a ShaderSource, Error = ShaderCompileError>> ShaderCompilation for T {
    fn compile(source: &ShaderSource) -> Result<Self, ShaderCompileError> {
        source.try_into()
    }
}