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
17
bool
evan::IXrPlatform::shouldClose
()
const
18
{
19
return
_shouldClose
;
20
}
21
22
std::vector<std::shared_ptr<utility::event::Event>>
23
evan::IXrPlatform::pollEvents
(
ADeviceBackend
&
deviceBackend
)
24
{
25
this->
getLogger
().info() <<
"Polling OpenXR events"
;
26
_lastError = Error::Ok;
27
28
XrEventDataBuffer
eventDataBuffer
{
XR_TYPE_EVENT_DATA_BUFFER
};
29
evan::XrDeviceBackend
&
xrDeviceBackend
=
30
evan::checkedCast<evan::XrDeviceBackend>
(
deviceBackend
);
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) {
38
case
XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED
: {
39
this->
getLogger
().info()
40
<<
"Processing session state changed event"
;
41
auto
sessionStateChangedEvent
=
42
*
reinterpret_cast<
XrEventDataSessionStateChanged
*
>
(
43
&
eventDataBuffer
);
44
processSessionStateChangedEvent(
sessionStateChangedEvent
,
45
xrDeviceBackend
);
46
break
;
47
}
48
case
XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING
: {
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
}
60
eventDataBuffer
= {
XR_TYPE_EVENT_DATA_BUFFER
};
61
}
62
return
events
;
63
}
64
65
std::shared_ptr<evan::ADeviceBackend>
66
evan::IXrPlatform::createDeviceBackend
()
const
67
{
68
return
std::make_shared<XrDeviceBackend>(*
this
);
69
}
70
71
std::shared_ptr<evan::ASwapchainContext>
72
evan::IXrPlatform::createSwapchainContext
(
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
95
void
evan::IXrPlatform::processSessionStateChangedEvent
(
96
const
XrEventDataSessionStateChanged
&
eventData
,
97
evan::XrDeviceBackend
&
xrDeviceBackend
)
98
{
99
this->
getLogger
().info() <<
"Processing session state changed event"
;
100
101
switch
(
eventData
.state) {
102
case
XR_SESSION_STATE_READY
: {
103
XrSessionBeginInfo
sessionBeginInfo
;
104
sessionBeginInfo
.type =
XR_TYPE_SESSION_BEGIN_INFO
;
105
sessionBeginInfo
.primaryViewConfigurationType =
106
xrDeviceBackend
.getViewConfigurationType();
107
if
(
xrBeginSession
(
xrDeviceBackend
._session, &
sessionBeginInfo
)
108
!=
XR_SUCCESS
) {
109
this->
getLogger
().error() <<
"Failed to begin session"
;
110
break
;
111
}
112
xrDeviceBackend
._sessionRunning =
true
;
113
break
;
114
}
115
case
XR_SESSION_STATE_STOPPING
:
116
if
(
xrEndSession
(
xrDeviceBackend
._session) !=
XR_SUCCESS
) {
117
this->
getLogger
().error() <<
"Failed to end session"
;
118
break
;
119
}
120
xrDeviceBackend
._sessionRunning =
false
;
121
break
;
122
case
XR_SESSION_STATE_EXITING
:
123
_shouldClose =
true
;
124
break
;
125
case
XR_SESSION_STATE_LOSS_PENDING
:
126
_shouldClose =
true
;
127
_lastError = mapSessionState(
eventData
.state);
128
break
;
129
case
XR_SESSION_STATE_FOCUSED
:
130
break
;
131
case
XR_SESSION_STATE_VISIBLE
:
132
break
;
133
case
XR_SESSION_STATE_SYNCHRONIZED
:
134
break
;
135
case
XR_SESSION_STATE_IDLE
:
136
break
;
137
default
:
138
break
;
139
}
140
}
evan::ADeviceBackend
Abstract base class for Vulkan device backends.
Definition
ADeviceBackend.hpp:48
evan::DeviceContext
Represents the device context for the engine, managing Vulkan-related resources and operations.
Definition
DeviceContext.hpp:39
evan::IXrPlatform::_shouldClose
bool _shouldClose
Definition
IXrPlatform.hpp:188
evan::IXrPlatform::processSessionStateChangedEvent
void processSessionStateChangedEvent(const XrEventDataSessionStateChanged &eventData, XrDeviceBackend &xrDeviceBackend)
Process an OpenXR session state change event.
Definition
IXrPlatform.cpp:95
evan::IXrPlatform::shouldClose
bool shouldClose() const override
Check if the OpenXR platform should close.
Definition
IXrPlatform.cpp:17
evan::IXrPlatform::createSwapchainContext
std::shared_ptr< ASwapchainContext > createSwapchainContext(const DeviceContext &deviceContext) const override
Create a swapchain context for the OpenXR platform.
Definition
IXrPlatform.cpp:72
evan::IXrPlatform::pollEvents
virtual std::vector< std::shared_ptr< utility::event::Event > > pollEvents(ADeviceBackend &deviceBackend) override
Poll for OpenXR events and handle them accordingly.
Definition
IXrPlatform.cpp:23
evan::IXrPlatform::createDeviceBackend
std::shared_ptr< ADeviceBackend > createDeviceBackend() const override
Create a device context for the OpenXR platform.
Definition
IXrPlatform.cpp:66
evan::XrDeviceBackend
The XrDeviceBackend class is responsible for managing the OpenXR device backend, including instance c...
Definition
XrDeviceBackend.hpp:39
evan::Result
Small result wrapper used by helpers that must return both a status and a value (e....
Definition
Error.hpp:89
sources
openxr
IXrPlatform.cpp
Generated by
1.9.8