RavEngine
Loading...
Searching...
No Matches
OpenXRIntegration.hpp
1#pragma once
2
3#if __has_include(<openxr/openxr.h>)
4#define RVE_XR_AVAILABLE
5#include "RenderTargetCollection.hpp"
6
7#if RGL_VK_AVAILABLE
8#define XR_USE_GRAPHICS_API_VULKAN
9#include <volk.h>
10#include <RGL/../../src/VkTexture.hpp>
11#endif
12#if _WIN32
13#define XR_USE_GRAPHICS_API_D3D12
14#include <RGL/../../src/D3D12Texture.hpp>
15#include <d3d12.h>
16#endif
17
18#include <openxr/openxr.h>
19#include <openxr/openxr_platform.h>
20#endif
21
22namespace RavEngine {
23#ifdef RVE_XR_AVAILABLE
24 namespace OpenXRIntegration {
25 struct {
26 // required for all XR apps
27 XrInstance instance;
28 XrSession session;
29 XrSystemId systemId;
30 XrSessionState sessionState = XR_SESSION_STATE_UNKNOWN;
31
32 // place space (usually local or stage)
33 XrSpace space;
34
35 // the configs for each display / eye
36 std::vector<XrViewConfigurationView> viewConfigurationViews;
37 std::vector <XrCompositionLayerProjectionView> projectionViews;
38 std::vector<XrView> views;
39
40 union XrSwapchainImage {
41#if RGL_DX12_AVAILABLE
42 XrSwapchainImageD3D12KHR d3d12Image;
43#endif
44#if RGL_VK_AVAILABLE
45 XrSwapchainImageVulkanKHR vkImage;
46#endif
47 };
48
49 // one list of images per eye
50 std::vector<std::vector<XrSwapchainImage>> swapchainImages;
51 std::vector<std::vector<std::unique_ptr<RGL::ITexture>>> rglSwapchainImages;
52 std::vector<std::vector<XrSwapchainImage>> depthSwapchainImages;
53 std::vector<std::vector<RGLTexturePtr>> rglDepthSwapchainImages;
54 // one swapchain per eye, plus depth
55 int64_t swapchain_format, depth_swapchain_format = -1;
56 std::vector<XrSwapchain> swapchains;
57 std::vector<XrSwapchain> depth_swapchains;
58
59 // dpeth layer data
60 struct
61 {
62 std::vector<XrCompositionLayerDepthInfoKHR> infos;
63 bool supported;
64 } depth;
65
66 struct
67 {
68 std::vector<XrSwapchainImage> images;
69 int64_t format;
70 uint32_t swapchain_width, swapchain_height;
71 uint32_t swapchain_length;
72 XrSwapchain swapchain;
73 bool supported;
74 } cylinder;
75
76 union {
77#if RGL_DX12_AVAILABLE
78 XrGraphicsBindingD3D12KHR d3d12Binding;
79#endif
80#if RGL_VK_AVAILABLE
81 XrGraphicsBindingVulkan2KHR vkBinding;
82#endif
83 } graphicsBinding;
84
85 XrSessionState state = XR_SESSION_STATE_UNKNOWN;
86
87 XrDebugUtilsMessengerEXT debugMessenger;
88 XrViewConfigurationType viewConfigurationType;
89
90 inline static PFN_xrCreateDebugUtilsMessengerEXT ext_xrCreateDebugUtilsMessengerEXT = nullptr;
91 inline static PFN_xrDestroyDebugUtilsMessengerEXT ext_xrDestroyDebugUtilsMessengerEXT = nullptr;
92
93 static constexpr XrPosef identity_pose{
94 .orientation = { .x = 0, .y = 0, .z = 0, .w = 1.0 },
95 .position = { .x = 0, .y = 0, .z = 0 }
96 };
97
98 } xr;
99
100 struct OpenXRInitInfo {
101 RGLDevicePtr device;
102 RGLCommandQueuePtr commandQueue;
103 };
104 void init_openxr(const OpenXRInitInfo& initInfo);
105
106 std::vector<RenderViewCollection> CreateRenderTargetCollections();
107
108 void UpdateXRTargetCollections(std::vector<RenderViewCollection>& collections, const std::vector<XrView>& views);
109 std::pair<std::vector<XrView>, XrFrameState> BeginXRFrame();
110 void EndXRFrame(XrFrameState& frameState);
111 };
112#endif
113}
int64 int64_t
Definition fwd.hpp:85
uint32 uint32_t
Definition fwd.hpp:131
Definition Animation.hpp:6