#[derive(Debug, Clone)]
pub struct RenderDevice {
pub gpu: Option<String>,
pub gpu_error: Option<String>,
}
#[must_use]
pub fn render_device() -> RenderDevice {
#[cfg(feature = "gpu")]
{
match kallo_gpu::describe_adapter() {
Ok(gpu) => RenderDevice {
gpu: Some(gpu),
gpu_error: None,
},
Err(error) => RenderDevice {
gpu: None,
gpu_error: Some(error.to_string()),
},
}
}
#[cfg(not(feature = "gpu"))]
{
RenderDevice {
gpu: None,
gpu_error: Some("this build has no GPU backend".to_owned()),
}
}
}
#[cfg(test)]
mod tests {
use super::render_device;
#[test]
fn an_adapter_is_either_named_or_its_absence_explained() {
let device = render_device();
assert_ne!(device.gpu.is_some(), device.gpu_error.is_some());
}
}