use std::sync::OnceLock;
mod ctypes;
pub mod error;
pub mod include;
pub mod limits;
mod program;
mod shader;
static COMPILER_INSTANCE: OnceLock<Option<Compiler>> = OnceLock::new();
#[derive(Debug)]
pub struct Compiler;
pub use crate::ctypes::*;
pub use program::Program;
pub use shader::*;
impl Compiler {
pub fn acquire() -> Option<&'static Self> {
COMPILER_INSTANCE
.get_or_init(|| {
unsafe {
if glslang_sys::glslang_initialize_process() == 0 {
return None;
}
};
Some(Self)
})
.as_ref()
}
pub fn create_shader(&self, input: ShaderInput) -> Result<Shader<'_>, error::GlslangError> {
Shader::new(&self, input)
}
pub fn create_program(&self) -> Program<'_> {
Program::new(&self)
}
}
impl Drop for Compiler {
fn drop(&mut self) {
unsafe {
glslang_sys::glslang_finalize_process();
}
}
}