61 lines
1.5 KiB
Rust
61 lines
1.5 KiB
Rust
|
use std::sync::{Arc, Mutex};
|
||
|
|
||
|
use vulkan_rs::prelude::*;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
|
||
|
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()),
|
||
|
}
|
||
|
}
|
||
|
}
|