ui/src/context_interface.rs

67 lines
1.7 KiB
Rust
Raw Normal View History

2023-01-16 11:58:59 +00:00
use std::sync::{Arc, Mutex};
use vulkan_rs::prelude::*;
2023-01-16 12:27:54 +00:00
#[cfg(feature = "audio")]
use audio::*;
2023-01-16 11:58:59 +00:00
pub trait ContextInterface: Send + Sync {
fn device(&self) -> &Arc<Device>;
fn queue(&self) -> &Arc<Mutex<Queue>>;
fn format(&self) -> VkFormat;
fn image_layout(&self) -> VkImageLayout;
fn image_count(&self) -> usize;
fn images(&self) -> TargetMode<Vec<Arc<Image>>>;
fn width(&self) -> u32;
fn height(&self) -> u32;
2023-01-16 12:27:54 +00:00
#[cfg(feature = "audio")]
2023-01-16 13:08:54 +00:00
fn sound_handler(&self) -> std::sync::MutexGuard<'_, SoundHandler>;
2023-01-16 11:58:59 +00:00
}
pub enum TargetMode<T> {
Mono(T),
Stereo(T, T),
}
impl<T> TargetMode<T> {
pub fn mono(&self) -> &T {
match self {
TargetMode::Mono(s) => s,
TargetMode::Stereo(_, _) => panic!("Expected another target mode"),
}
}
pub fn mono_mut(&mut self) -> &mut T {
match self {
TargetMode::Mono(s) => s,
TargetMode::Stereo(_, _) => panic!("Expected another target mode"),
}
}
pub fn stereo(&self) -> (&T, &T) {
match self {
TargetMode::Mono(_) => panic!("Expected another target mode"),
TargetMode::Stereo(l, r) => (l, r),
}
}
pub fn stereo_mut(&mut self) -> (&mut T, &mut T) {
match self {
TargetMode::Mono(_) => panic!("Expected another target mode"),
TargetMode::Stereo(l, r) => (l, r),
}
}
}
impl<T: Clone> Clone for TargetMode<T> {
fn clone(&self) -> TargetMode<T> {
match self {
TargetMode::Mono(t) => TargetMode::Mono(t.clone()),
TargetMode::Stereo(lhs, rhs) => TargetMode::Stereo(lhs.clone(), rhs.clone()),
}
}
}