150 lines
4.3 KiB
Rust
150 lines
4.3 KiB
Rust
use ecs::World;
|
|
use ui::prelude::*;
|
|
use vulkan_rs::prelude::*;
|
|
|
|
use crate::{
|
|
Result, vri::openvrrendercore::OpenVRRenderCore,
|
|
wsi::vulkanwindowrendercore::VulkanWindowRenderCore, xri::openxrrendercore::OpenXRRenderCore,
|
|
};
|
|
|
|
use std::sync::Arc;
|
|
|
|
use crate::prelude::*;
|
|
|
|
pub trait TScene: Send + Sync + 'static {
|
|
fn process(
|
|
&mut self,
|
|
buffer_recorder: &mut CommandBufferRecorder<'_>,
|
|
images: &TargetMode<Vec<Arc<Image>>>,
|
|
indices: &TargetMode<usize>,
|
|
world: &World,
|
|
) -> Result<()>;
|
|
|
|
fn resize(
|
|
&mut self,
|
|
window_width: f32,
|
|
window_height: f32,
|
|
images: &TargetMode<Vec<Arc<Image>>>,
|
|
) -> Result<()>;
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum RenderCore {
|
|
Wsi(VulkanWindowRenderCore),
|
|
OpenVR(OpenVRRenderCore),
|
|
OpenXR(OpenXRRenderCore),
|
|
}
|
|
|
|
impl RenderCore {
|
|
pub fn next_frame(&mut self, world: &mut World) -> Result<bool> {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.next_frame(world),
|
|
RenderCore::OpenVR(rc) => rc.next_frame(world),
|
|
RenderCore::OpenXR(rc) => rc.next_frame(world),
|
|
}
|
|
}
|
|
|
|
pub fn resize(&mut self, world: &mut World, w: u32, h: u32) -> Result<()> {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.resize(world, w, h),
|
|
RenderCore::OpenVR(rc) => rc.resize(world, w, h),
|
|
RenderCore::OpenXR(rc) => rc.resize(world, w, h),
|
|
}
|
|
}
|
|
|
|
pub fn format(&self) -> VkFormat {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.format(),
|
|
RenderCore::OpenVR(rc) => rc.format(),
|
|
RenderCore::OpenXR(rc) => rc.format(),
|
|
}
|
|
}
|
|
|
|
pub fn image_layout(&self) -> VkImageLayout {
|
|
VK_IMAGE_LAYOUT_PRESENT_SRC_KHR
|
|
}
|
|
|
|
/// lower priority means it is more important
|
|
pub fn add_render_routine<T: TScene>(&mut self, priority: u32) {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.add_render_routine::<T>(priority),
|
|
RenderCore::OpenVR(rc) => rc.add_render_routine::<T>(priority),
|
|
RenderCore::OpenXR(rc) => rc.add_render_routine::<T>(priority),
|
|
}
|
|
}
|
|
|
|
pub fn remove_render_routine<T: TScene>(&mut self) {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.remove_render_routine::<T>(),
|
|
RenderCore::OpenVR(rc) => rc.remove_render_routine::<T>(),
|
|
RenderCore::OpenXR(rc) => rc.remove_render_routine::<T>(),
|
|
}
|
|
}
|
|
|
|
pub fn set_clear_color(&self, color: [f32; 4]) {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.set_clear_color(color),
|
|
RenderCore::OpenVR(rc) => rc.set_clear_color(color),
|
|
RenderCore::OpenXR(rc) => rc.set_clear_color(color),
|
|
}
|
|
}
|
|
|
|
// getter
|
|
pub fn image_count(&self) -> usize {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.image_count(),
|
|
RenderCore::OpenVR(rc) => rc.image_count(),
|
|
RenderCore::OpenXR(rc) => rc.image_count(),
|
|
}
|
|
}
|
|
|
|
pub fn images(&self) -> TargetMode<Vec<Arc<Image>>> {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.images(),
|
|
RenderCore::OpenVR(rc) => rc.images(),
|
|
RenderCore::OpenXR(rc) => rc.images(),
|
|
}
|
|
}
|
|
|
|
pub fn width(&self) -> u32 {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.width(),
|
|
RenderCore::OpenVR(rc) => rc.width(),
|
|
RenderCore::OpenXR(rc) => rc.width(),
|
|
}
|
|
}
|
|
|
|
pub fn height(&self) -> u32 {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.height(),
|
|
RenderCore::OpenVR(rc) => rc.height(),
|
|
RenderCore::OpenXR(rc) => rc.height(),
|
|
}
|
|
}
|
|
|
|
pub fn transformations(&self) -> Option<(VRTransformations, VRTransformations)> {
|
|
match self {
|
|
RenderCore::Wsi(rc) => rc.transformations(),
|
|
RenderCore::OpenVR(rc) => rc.transformations(),
|
|
RenderCore::OpenXR(rc) => rc.transformations(),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl From<VulkanWindowRenderCore> for RenderCore {
|
|
fn from(value: VulkanWindowRenderCore) -> Self {
|
|
Self::Wsi(value)
|
|
}
|
|
}
|
|
|
|
impl From<OpenXRRenderCore> for RenderCore {
|
|
fn from(value: OpenXRRenderCore) -> Self {
|
|
Self::OpenXR(value)
|
|
}
|
|
}
|
|
|
|
impl From<OpenVRRenderCore> for RenderCore {
|
|
fn from(value: OpenVRRenderCore) -> Self {
|
|
Self::OpenVR(value)
|
|
}
|
|
}
|