use std::sync::Arc;
use std::borrow::Cow;
use vulkano::instance::{Instance, InstanceCreationError, ApplicationInfo, Version};
use vulkano::instance::InstanceExtensions;
use super::{ENGINE_NAME, ENGINE_VERSION};
pub struct Context {
pub(super) instance: Arc<Instance>
}
impl Context {
pub fn new() -> Result<Context, InstanceCreationError> { Context::create(None, None, vulkano_win::required_extensions()) }
pub fn with_app_info(name: &str, version: Version) -> Result<Context, InstanceCreationError> { Context::create(Some(name), Some(version), vulkano_win::required_extensions()) }
}
#[cfg(feature = "expose-underlying-vulkano")]
impl Context {
#[inline(always)]
pub fn instance(&self) -> &Arc<Instance> { self.instance }
}
impl Context {
fn create(
application_name: Option<&str>,
application_version: Option<Version>,
extensions: InstanceExtensions
) -> Result<Context, InstanceCreationError> {
let application_name: Option<Cow<str>> = match application_name {
Some(name) => Some(Cow::from(name)),
None => None,
};
let app_info = ApplicationInfo {
application_name,
application_version,
engine_name: Some(Cow::from(ENGINE_NAME)),
engine_version: Some(ENGINE_VERSION),
};
let instance = Instance::new(Some(&app_info), &extensions, None)?;
Ok(Context { instance })
}
}