use concinnity_core::platform::Platform;
pub fn current() -> Platform {
#[cfg(backend_metal)]
{
Platform::Metal
}
#[cfg(backend_dx)]
{
Platform::Hlsl
}
#[cfg(backend_vk)]
{
Platform::Glsl
}
#[cfg(not(any(backend_metal, backend_dx, backend_vk)))]
{
native_platform(std::env::consts::OS)
}
}
#[cfg(any(test, not(any(backend_metal, backend_dx, backend_vk))))]
fn native_platform(target_os: &str) -> Platform {
match target_os {
"macos" => Platform::Metal,
"windows" => Platform::Hlsl,
_ => Platform::Glsl,
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_backend_resolves_to_one_platform() {
let platform = current();
assert!(["metal", "hlsl", "glsl"].contains(&platform.key()));
}
#[test]
fn every_target_has_a_native_platform() {
assert_eq!(native_platform("macos"), Platform::Metal);
assert_eq!(native_platform("windows"), Platform::Hlsl);
assert_eq!(native_platform("linux"), Platform::Glsl);
}
}