HoviTron Video Pipeline
WindowOpenXR.h
Go to the documentation of this file.
1/* ----------------------
2* Copyright 2023 Université Libre de Bruxelles(ULB), Universidad Politécnica de Madrid(UPM), CREAL, Deutsches Zentrum für Luft - und Raumfahrt(DLR)
3
4* Licensed under the Apache License, Version 2.0 (the "License");
5* you may not use this file except in compliance with the License.
6* You may obtain a copy of the License at < http://www.apache.org/licenses/LICENSE-2.0>
7
8* Unless required by applicable law or agreed to in writing, software
9* distributed under the License is distributed on an "AS IS" BASIS,
10* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11* See the License for the specific language governing permissionsand
12* limitations under the License.
13---------------------- */
14
15
16
17/*****************************************************************/
28#pragma once
29
30#ifdef __ANDROID__
31#include <android/log.h>
32#include <android_native_app_glue.h>
33#else
34#define GLFW_INCLUDE_VULKAN
35#include <GLFW/glfw3.h>
36#endif
37
38#include"WindowAbstract.h"
39#include "SwapchainOpenXR.h"
40#include <mutex>
41
53 public:
54#ifdef __ANDROID__
55 OpenXRWindow(android_app* appAndroid);
56#endif
58 void initWindow() override;
60 void continueInit() override;
62 void cleanUp() override;
64 void cleanUpSurface() override;
66 void mainLoop(VulkanDrawing * vulkanDrawing) override;
68 void createSurface() override;
70 std::vector<const char*> getRequiredExtensions() override;
71 VkBool32 isDeviceSupportingSufaceKHR(VkPhysicalDevice device, int i) override; //not usefull
73 std::vector<const char*> getRequiredDeviceExtensions() override;
74 SwapChainSupportDetails querySwapChainSupport(vk::PhysicalDevice device) override; //not usefull
75 void getFrameBufferSize(int* w, int* h, vk::PhysicalDevice & pDevice) override; //not usefull here
76 bool isSynchroWithSemaphore() override;
78 bool isDepthRecquired() override;
80 const bool useOpenXR() override;
82 vk::Image getSwapchainImage(int view, int index) override;
83
88 void resetOrigin() override;
89
93 void checkForCorrectSize();
95 std::vector<vk::Image> getBlitDestinations(int view, int elem) override;
97 std::vector<vk::Extent2D> getBlitExtentDestinations(int view, int elem) override;
99 virtual std::vector<vk::Semaphore> getSemaphoreWait(int view, int elem) override;
101 virtual std::vector<vk::Semaphore> getSemaphoreSignal(int view, int elem) override;
102
104 void getVulkanPhysicalDevice(VkInstance & vkInstance, VkPhysicalDevice * physicalDevice);
106 void createVulkanDevice(VkPhysicalDevice & physicalDevice, VkDeviceCreateInfo & info, VkDevice * device);
108 void pollEvents(bool* exitRenderLoop, bool* requestRestart);
110 bool isSessionRunning();
112 void setRotation(glm::quat& q, int view);
113
114
116 void setMirror(bool mirrorActivated);
117
118
119
120
121
122
123 private:
124
126 bool mirrorActivated = true;
128 bool depthExtensionAvailable = false;
130 bool quadViewExtensionAvailable = false;
132 bool pauseRendering = false;
133
134 //
143 glm::mat3x3 conversionMat = {0,-1,0, 0,0,1, -1,0,0};
144
146 XrInstance xrInstance = XR_NULL_HANDLE;
148 XrSystemId systemId = XR_NULL_SYSTEM_ID;
150 XrGraphicsBindingVulkan2KHR graphicsBinding ;
152 XrSession xrSession = XR_NULL_HANDLE;
154 std::vector<XrSpace> xrVisualizedSpaces;
156 XrSpace refSpace = XR_NULL_HANDLE;
158 std::vector<XrViewConfigurationView> xrConfViews;
160 std::vector<XrView> xrViews;
162 uint64_t colorSwapchainFormat = 0;
164 uint64_t depthSwapchainFormat = 0;
166 bool runningSession = false;
167
169 XrSessionState xrSessionState{XR_SESSION_STATE_UNKNOWN};
170
171
173 const std::array< XrEnvironmentBlendMode,2> supportedBlendModes {XR_ENVIRONMENT_BLEND_MODE_ADDITIVE, XR_ENVIRONMENT_BLEND_MODE_OPAQUE };
174 XrEnvironmentBlendMode xrBlendMode = XR_ENVIRONMENT_BLEND_MODE_ADDITIVE;
175 const std::array <XrViewConfigurationType, 2> supportedViewConfigurations = { XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO , XR_VIEW_CONFIGURATION_TYPE_PRIMARY_QUAD_VARJO };
176 XrViewConfigurationType xrViewConfType = XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO;
177 XrEventDataBuffer eventDataBuffer;
178 std::vector<char> extensionNames;
179 std::vector<char> deviceExtension;
180
181
182#if __ANDROID__
183
184 const std::vector<const char*> instanceExtensions = {
185 VK_KHR_SURFACE_EXTENSION_NAME,
186 VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
187 };
188 };
189 android_app* appAndroid = nullptr;
190
191#else
192
193 const std::vector<const char*> instanceExtensions = {
194 VK_KHR_SURFACE_EXTENSION_NAME
195 };
196
197 //mirror ressources
198 GLFWwindow* window = nullptr;
199 VkSurfaceKHR surface = VK_NULL_HANDLE;
200 vk::SwapchainKHR mirrorSwapchain;
201 std::vector<vk::Image> mirrorImages;
202 std::vector<vk::Semaphore> mirrorAvailableSemaphore;
203 std::vector<vk::Semaphore> mirrorFinnishedSemaphore;
204 uint32_t mirrorSwapchainSize = 3;
205 uint32_t currentMirror = 0;
206 uint32_t width = 960;
207 uint32_t height = 540;
208
209 bool mirrorShouldRender = true;
210 void cleanUpMirrorSwapchain();
211 void recreateMirror();
212
213 void inputKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mode);
214#endif
215
216
217
218
219 //Rotation and translation
220
221 std::vector<glm::vec3> rotationsOMAF;
222 std::vector<glm::vec3> translationsOMAF;
223 std::vector<glm::vec3> rotationsOpenXR;
224 std::vector<glm::vec3> translationsOpenXR;
225
226 std::vector<glm::quat> quaternionsList;
227
228 glm::vec3 deltaPos = { 0,0,0 };
229 glm::quat deltaQuat = glm::identity<glm::quat>();
230
231 //---------private functions
232 void initOpenXR();
233 const XrEventDataBaseHeader *TryReadNextEvent();
234 void CreateSpaces();
235 void CreateSwapChain();
236 void createMirrorSwapchain();
237 void LogReferenceSpaces();
238 void logViewConfiguration(XrInstance & xrInstance, XrSystemId & systemId);
239 static XrResult GetVulkanGraphicsRequirements2KHR(XrInstance instance, XrSystemId systemId,
240 XrGraphicsRequirementsVulkan2KHR* graphicsRequirements);
241 void renderFrame(VulkanDrawing* vulkanDrawing);
242 void HandleSessionStateChangedEvent(const XrEventDataSessionStateChanged& stateChangedEvent, bool* exitRenderLoop,
243 bool* requestRestart);
244 void selectViewConfiguration();
245 void selectBlendMode();
246 void checkExtensions();
247 void checkKeyboard();
248 void printCoordinates();
249
250
251#ifdef HVT_UDP_CONTROL
252 std::mutex mutex;
253#endif //
254
255
256
257
258
259#if NDEBUG
260 const bool validationXR = false;
261#else
262 const bool validationXR = false;
263#endif
264
265
266const std::vector<const char*> additionalDeviceExtensions = {
267 VK_KHR_SWAPCHAIN_EXTENSION_NAME
268};
269
270
271
272
273};
274
File that contains the SwapchainOpenXR class.
Contain the class WindowAbstract.
The class that manages the drawing operation (manage and record command buffers).
Definition: VulkanDrawing.h:46
Abstraction of the way of the result is displayed (screen or HMD).
Class that take care of the tasks linked to OpenXR (input and display), is used when HMD support is r...
Definition: WindowOpenXR.h:52
std::vector< vk::Extent2D > getBlitExtentDestinations(int view, int elem) override
void checkForCorrectSize()
void setMirror(bool mirrorActivated)
virtual std::vector< vk::Semaphore > getSemaphoreWait(int view, int elem) override
void createVulkanDevice(VkPhysicalDevice &physicalDevice, VkDeviceCreateInfo &info, VkDevice *device)
virtual std::vector< vk::Semaphore > getSemaphoreSignal(int view, int elem) override
void getVulkanPhysicalDevice(VkInstance &vkInstance, VkPhysicalDevice *physicalDevice)
void cleanUpSurface() override
void continueInit() override
bool isSessionRunning()
void initWindow() override
bool isDepthRecquired() override
std::vector< const char * > getRequiredDeviceExtensions() override
vk::Image getSwapchainImage(int view, int index) override
void cleanUp() override
void mainLoop(VulkanDrawing *vulkanDrawing) override
std::vector< vk::Image > getBlitDestinations(int view, int elem) override
void setRotation(glm::quat &q, int view)
void createSurface() override
void framebufferResizeCallback()
const bool useOpenXR() override
VkBool32 isDeviceSupportingSufaceKHR(VkPhysicalDevice device, int i) override
void getFrameBufferSize(int *w, int *h, vk::PhysicalDevice &pDevice) override
bool isSynchroWithSemaphore() override
void resetOrigin() override
std::vector< const char * > getRequiredExtensions() override
SwapChainSupportDetails querySwapChainSupport(vk::PhysicalDevice device) override
void pollEvents(bool *exitRenderLoop, bool *requestRestart)
Struct that contains the capability for the sapchain, the formats and the present mode supported.
Definition: commonVulkan.h:87