31#include <android/log.h>
32#include <android_native_app_glue.h>
34#define GLFW_INCLUDE_VULKAN
35#include <GLFW/glfw3.h>
55 OpenXRWindow(android_app* appAndroid);
99 virtual std::vector<vk::Semaphore>
getSemaphoreWait(
int view,
int elem)
override;
106 void createVulkanDevice(VkPhysicalDevice & physicalDevice, VkDeviceCreateInfo & info, VkDevice * device);
108 void pollEvents(
bool* exitRenderLoop,
bool* requestRestart);
126 bool mirrorActivated =
true;
128 bool depthExtensionAvailable =
false;
130 bool quadViewExtensionAvailable =
false;
132 bool pauseRendering =
false;
143 glm::mat3x3 conversionMat = {0,-1,0, 0,0,1, -1,0,0};
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;
169 XrSessionState xrSessionState{XR_SESSION_STATE_UNKNOWN};
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;
184 const std::vector<const char*> instanceExtensions = {
185 VK_KHR_SURFACE_EXTENSION_NAME,
186 VK_KHR_ANDROID_SURFACE_EXTENSION_NAME
189 android_app* appAndroid =
nullptr;
193 const std::vector<const char*> instanceExtensions = {
194 VK_KHR_SURFACE_EXTENSION_NAME
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;
209 bool mirrorShouldRender =
true;
210 void cleanUpMirrorSwapchain();
211 void recreateMirror();
213 void inputKeyCallback(GLFWwindow* window,
int key,
int scancode,
int action,
int mode);
221 std::vector<glm::vec3> rotationsOMAF;
222 std::vector<glm::vec3> translationsOMAF;
223 std::vector<glm::vec3> rotationsOpenXR;
224 std::vector<glm::vec3> translationsOpenXR;
226 std::vector<glm::quat> quaternionsList;
228 glm::vec3 deltaPos = { 0,0,0 };
229 glm::quat deltaQuat = glm::identity<glm::quat>();
233 const XrEventDataBaseHeader *TryReadNextEvent();
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);
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();
251#ifdef HVT_UDP_CONTROL
260 const bool validationXR =
false;
262 const bool validationXR =
false;
266const std::vector<const char*> additionalDeviceExtensions = {
267 VK_KHR_SWAPCHAIN_EXTENSION_NAME
File that contains the SwapchainOpenXR class.
Contain the class WindowAbstract.
The class that manages the drawing operation (manage and record command buffers).
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...
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
void initWindow() override
bool isDepthRecquired() override
std::vector< const char * > getRequiredDeviceExtensions() override
vk::Image getSwapchainImage(int view, int index) 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.