vltk 0.1.2

A simplified toolkit for creating applications using Vulkan
Documentation
//!# VlTk
//! ### A simplified toolkit for creating applications using Vulkan
//!
//! # Introduction
//! VLTK is an open source, multi-platform, simple toolkit for the Rust language for developing Vulkan applications.
//! This library provides only drawing tools using Vulkan.
//! Therefore, you can use your preferred library for windowing.
//!
//! # Compile VlTk
//! ## *Vulkan SDK is required for build*
//! ```bash
//! git clone https://github.com/OvertimeCoder/VlTk.git
//! cd VlTk
//! cargo build
//! ```
//!
//! # Example
//! ```bash
//! git clone https://github.com/OvertimeCoder/VlTk.git
//! cd VlTk
//! cargo run --example triangle
//! ```
//!
//! # Dependencies
//!  - [ash](https://github.com/ash-rs/ash)
//!  - [ash-window](https://github.com/ash-rs/ash)
//!  - [winit](https://github.com/rust-windowing/winit)
//!  - [raw-window-handle](https://github.com/rust-windowing/raw-window-handle)

/// Vulkan context creation, etc.
pub mod vk;

/// Error handling
pub mod error;
pub mod platform;

use ash::extensions::khr::Surface;
#[cfg(feature = "winit")]
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};

// Implementations

use crate::error::{ErrorKind, VlTkError};
use crate::vk::{Vk, VkContext};
#[cfg(feature = "winit")]
use winit::window::Window;
/// Trait for applications that use Vulkan
pub trait VkApplication<T> {
    /// Application Entry Points
    fn run(&mut self) {
        let vk = Vk {};
        VkApplication::init_vulkan(self, vk);
        VkApplication::main_loop(self, vk);
        VkApplication::clean_up(self, vk);
    }
    /// Initialize Vulkan (also initialize windows, etc. as needed)
    fn init_vulkan(&mut self, vk: Vk) -> VkContext;
    /// Main Loop
    fn main_loop(&mut self, vk: Vk);
    /// Use as needed, e.g., to discard context
    fn clean_up(&mut self, vk: Vk);
}

/// Extended Trait for winit
#[cfg(feature = "winit")]
pub trait WindowExt {
    fn use_vk(&self, context: &VkContext) -> Result<vk::Surface, VlTkError>;
}

#[cfg(feature = "winit")]
impl WindowExt for Window {
    /// Enable Vulkan(VlTk) in winit window
    fn use_vk(&self, context: &VkContext) -> Result<vk::Surface, VlTkError> {
        unsafe {
            let surface = match ash_window::create_surface(
                &context.entry,
                &context.instance,
                self.raw_display_handle(),
                self.raw_window_handle(),
                None,
            ) {
                Ok(surface) => surface,
                Err(err) => return Err(VlTkError::new(ErrorKind::VkInitialize, err)),
            };
            let surface_fn: Surface = Surface::new(&context.entry, &context.instance);

            Ok(vk::Surface::new(surface_fn, surface))
        }
    }
}