evan 2026.1.4
Evan
Loading...
Searching...
No Matches
IXrPlatform.cpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** XrPlatform
6*/
7
8#include "evan/openxr/IXrPlatform.hpp"
9#include "evan/openxr/XrDeviceBackend.hpp"
10#include "evan/CheckedCast.hpp"
11#include "evan/openxr/XrError.hpp"
12
14// Public Methods //
16
18{
19 return _shouldClose;
20}
21
22std::vector<std::shared_ptr<utility::event::Event>>
24{
25 this->getLogger().info() << "Polling OpenXR events";
26 _lastError = Error::Ok;
27
31
32 std::vector<std::shared_ptr<utility::event::Event>> events =
33 xrDeviceBackend.pollActions();
34
35 while (xrPollEvent(xrDeviceBackend._XrInstance, &eventDataBuffer)
36 == XR_SUCCESS) {
37 switch (eventDataBuffer.type) {
39 this->getLogger().info()
40 << "Processing session state changed event";
42 *reinterpret_cast<XrEventDataSessionStateChanged *>(
44 processSessionStateChangedEvent(sessionStateChangedEvent,
46 break;
47 }
49 this->getLogger().info()
50 << "Instance loss pending event received";
51 _shouldClose = true;
52 _lastError = Error::RuntimeLost;
53 break;
54 }
55 default:
56 this->getLogger().warning()
57 << "Unhandled event type: " << eventDataBuffer.type;
58 break;
59 }
61 }
62 return events;
63}
64
65std::shared_ptr<evan::ADeviceBackend>
67{
68 return std::make_shared<XrDeviceBackend>(*this);
69}
70
71std::shared_ptr<evan::ASwapchainContext>
73 const DeviceContext &deviceContext) const
74{
75 auto swapchainContext =
76
77 std::make_shared<XrSwapchainContext>(deviceContext);
78
79 utility::graphic::ViewF view;
80 view.setClippingPlanes(1.0f, 4000.0f);
81
82 this->getLogger().error()
83 << "Created swapchain context with view: " << view;
84
85 swapchainContext->setView(0, view);
86 swapchainContext->setView(1, view);
87
88 return swapchainContext;
89}
90
92// Protected Methods //
94
98{
99 this->getLogger().info() << "Processing session state changed event";
100
101 switch (eventData.state) {
105 sessionBeginInfo.primaryViewConfigurationType =
106 xrDeviceBackend.getViewConfigurationType();
108 != XR_SUCCESS) {
109 this->getLogger().error() << "Failed to begin session";
110 break;
111 }
112 xrDeviceBackend._sessionRunning = true;
113 break;
114 }
116 if (xrEndSession(xrDeviceBackend._session) != XR_SUCCESS) {
117 this->getLogger().error() << "Failed to end session";
118 break;
119 }
120 xrDeviceBackend._sessionRunning = false;
121 break;
123 _shouldClose = true;
124 break;
126 _shouldClose = true;
127 _lastError = mapSessionState(eventData.state);
128 break;
130 break;
132 break;
134 break;
136 break;
137 default:
138 break;
139 }
140}
Abstract base class for Vulkan device backends.
Represents the device context for the engine, managing Vulkan-related resources and operations.
void processSessionStateChangedEvent(const XrEventDataSessionStateChanged &eventData, XrDeviceBackend &xrDeviceBackend)
Process an OpenXR session state change event.
bool shouldClose() const override
Check if the OpenXR platform should close.
std::shared_ptr< ASwapchainContext > createSwapchainContext(const DeviceContext &deviceContext) const override
Create a swapchain context for the OpenXR platform.
virtual std::vector< std::shared_ptr< utility::event::Event > > pollEvents(ADeviceBackend &deviceBackend) override
Poll for OpenXR events and handle them accordingly.
std::shared_ptr< ADeviceBackend > createDeviceBackend() const override
Create a device context for the OpenXR platform.
The XrDeviceBackend class is responsible for managing the OpenXR device backend, including instance c...
Small result wrapper used by helpers that must return both a status and a value (e....
Definition Error.hpp:89