63 lines
1.6 KiB
Rust
63 lines
1.6 KiB
Rust
use crate::create_instance;
|
|
use crate::VALIDATION_ENABLED;
|
|
use ::anyhow::{anyhow, Result};
|
|
use ::thiserror::Error;
|
|
use ::vulkanalia::loader::{LibloadingLoader, LIBRARY};
|
|
use ::vulkanalia::prelude::v1_0::*;
|
|
use ::vulkanalia::vk::ExtDebugUtilsExtension;
|
|
use ::winit::window::Window;
|
|
|
|
/// Our Vulkan app.
|
|
#[derive(Clone, Debug)]
|
|
pub struct App {
|
|
entry: Entry,
|
|
instance: Instance,
|
|
data: AppData,
|
|
}
|
|
|
|
impl App {
|
|
/// Creates our Vulkan app.
|
|
pub unsafe fn create(window: &Window) -> Result<Self> {
|
|
let loader = LibloadingLoader::new(LIBRARY)?;
|
|
let entry = Entry::new(loader).map_err(|b| anyhow!("{}", b))?;
|
|
let mut data = AppData::default();
|
|
let instance = create_instance(window, &entry, &mut data)?;
|
|
|
|
pick_physical_device(&instance, &mut data)?;
|
|
Ok(Self {
|
|
entry,
|
|
instance,
|
|
data,
|
|
})
|
|
}
|
|
|
|
/// Renders a frame for our Vulkan app.
|
|
pub unsafe fn render(&mut self, window: &Window) -> Result<()> {
|
|
Ok(())
|
|
}
|
|
|
|
/// Destroys our Vulkan app.
|
|
pub unsafe fn destroy(&mut self) {
|
|
if VALIDATION_ENABLED {
|
|
self.instance
|
|
.destroy_debug_utils_messenger_ext(self.data.messenger, None);
|
|
}
|
|
|
|
self.instance.destroy_instance(None);
|
|
}
|
|
}
|
|
|
|
/// The Vulkan handles and associated properties used by our Vulkan app.
|
|
#[derive(Clone, Debug, Default)]
|
|
pub struct AppData {
|
|
messenger: vk::DebugUtilsMessengerEXT,
|
|
}
|
|
|
|
#[derive(Debug, Error)]
|
|
#[error("Missing {0}.")]
|
|
pub struct SuitabilityError(pub &'static str);
|
|
|
|
unsafe fn pick_physical_device(instance: &Instance, data: &mut AppData) -> Result<()> {
|
|
Ok(())
|
|
}
|