Blender V4.3
GHOST_XrEvent.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2020-2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <iostream>
10
11#include "GHOST_C-api.h"
12#include "GHOST_XrContext.hh"
13#include "GHOST_Xr_intern.hh"
14
15static bool GHOST_XrEventPollNext(XrInstance instance, XrEventDataBuffer &r_event_data)
16{
17 /* (Re-)initialize as required by specification. */
18 r_event_data.type = XR_TYPE_EVENT_DATA_BUFFER;
19 r_event_data.next = nullptr;
20
21 return (xrPollEvent(instance, &r_event_data) == XR_SUCCESS);
22}
23
24GHOST_TSuccess GHOST_XrEventsHandle(GHOST_XrContextHandle xr_contexthandle)
25{
26 if (xr_contexthandle == nullptr) {
27 return GHOST_kFailure;
28 }
29
30 GHOST_XrContext &xr_context = *(GHOST_XrContext *)xr_contexthandle;
31 XrEventDataBuffer event_buffer; /* Structure big enough to hold all possible events. */
32
33 while (GHOST_XrEventPollNext(xr_context.getInstance(), event_buffer)) {
34 XrEventDataBaseHeader *event = (XrEventDataBaseHeader *)&event_buffer;
35
36 switch (event->type) {
37 case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED:
38 xr_context.handleSessionStateChange((XrEventDataSessionStateChanged &)*event);
39 return GHOST_kSuccess;
40 case XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING:
41 GHOST_XrContextDestroy(xr_contexthandle);
42 return GHOST_kSuccess;
43 default:
44 if (xr_context.isDebugMode()) {
45 printf("Unhandled event: %i\n", event->type);
46 }
47 return GHOST_kFailure;
48 }
49 }
50
51 return GHOST_kFailure;
52}
GHOST C-API function and type declarations.
GHOST_TSuccess
Definition GHOST_Types.h:87
@ GHOST_kFailure
Definition GHOST_Types.h:87
@ GHOST_kSuccess
Definition GHOST_Types.h:87
static bool GHOST_XrEventPollNext(XrInstance instance, XrEventDataBuffer &r_event_data)
GHOST_TSuccess GHOST_XrEventsHandle(GHOST_XrContextHandle xr_contexthandle)
void GHOST_XrContextDestroy(GHOST_XrContextHandle xr_contexthandle)
Definition GHOST_Xr.cc:38
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object instance
Main GHOST container to manage OpenXR through.
XrInstance getInstance() const
void handleSessionStateChange(const XrEventDataSessionStateChanged &lifecycle)
bool isDebugMode() const
#define printf