Skyscraper 2.0
XrViewConfiguration.h
Go to the documentation of this file.
1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#pragma once
5
6namespace xr {
7 // The properties of a view configuration that's immutable for a system
9 XrViewConfigurationType Type;
10 XrBool32 FovMutable;
11 XrEnvironmentBlendMode BlendMode;
12 std::vector<XrEnvironmentBlendMode> SupportedBlendModes;
13 };
14
15 // The state of a view configuration that's changing during a session but immutable for a frame
17 XrViewConfigurationType Type;
18 std::vector<XrViewConfigurationView> ViewConfigViews;
19 std::vector<XrView> Views;
20 bool Active;
21 };
22
23 constexpr bool IsPrimaryViewConfigurationType(XrViewConfigurationType type) {
24 return type == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO || type == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_MONO ||
25 type == XR_VIEW_CONFIGURATION_TYPE_PRIMARY_QUAD_VARJO;
26 }
27
28 inline ViewProperties CreateViewProperties(XrInstance instance,
29 XrSystemId systemId,
30 XrViewConfigurationType viewConfigurationType,
31 const std::vector<XrEnvironmentBlendMode>& appSupportedEnvironmentBlendModes) {
32 XrViewConfigurationProperties viewConfigProperties{XR_TYPE_VIEW_CONFIGURATION_PROPERTIES};
33 CHECK_XRCMD(xrGetViewConfigurationProperties(instance, systemId, viewConfigurationType, &viewConfigProperties));
34
35 ViewProperties properties{};
36 properties.Type = viewConfigurationType;
37 properties.FovMutable = viewConfigProperties.fovMutable;
38 properties.SupportedBlendModes = xr::EnumerateEnvironmentBlendModes(instance, systemId, viewConfigurationType);
39 properties.BlendMode = xr::PickEnvironmentBlendMode(properties.SupportedBlendModes, appSupportedEnvironmentBlendModes);
40
41 return properties;
42 }
43
44 inline ViewConfigurationState CreateViewConfigurationState(XrViewConfigurationType viewConfigurationType,
45 XrInstance instance,
46 XrSystemId systemId) {
48 state.Type = viewConfigurationType;
49 state.ViewConfigViews = xr::EnumerateViewConfigurationViews(instance, systemId, viewConfigurationType);
50 state.Views.resize(state.ViewConfigViews.size(), {XR_TYPE_VIEW});
51
52 return state;
53 }
54
55 inline bool IsRecommendedSwapchainSizeChanged(const std::vector<XrViewConfigurationView>& oldConfigs,
56 const std::vector<XrViewConfigurationView>& newConfigs) {
57 assert(oldConfigs.size() == newConfigs.size());
58 size_t end = (std::min)(oldConfigs.size(), newConfigs.size());
59 for (size_t i = 0; i < end; i++) {
60 if ((oldConfigs[i].recommendedImageRectWidth != newConfigs[i].recommendedImageRectWidth) ||
61 (oldConfigs[i].recommendedImageRectHeight != newConfigs[i].recommendedImageRectHeight)) {
62 return true;
63 }
64 }
65 return false;
66 }
67} // namespace xr
#define CHECK_XRCMD(cmd)
Definition XrError.h:14
The xr::DispatchTable struct contains all available PFN pointers to xr functions including those in a...
std::vector< XrEnvironmentBlendMode > EnumerateEnvironmentBlendModes(XrInstance instance, XrSystemId systemId, XrViewConfigurationType viewConfigType)
Definition XrEnumerate.h:48
std::vector< XrViewConfigurationView > EnumerateViewConfigurationViews(XrInstance instance, XrSystemId systemId, XrViewConfigurationType viewConfigurationType)
Definition XrEnumerate.h:35
bool IsRecommendedSwapchainSizeChanged(const std::vector< XrViewConfigurationView > &oldConfigs, const std::vector< XrViewConfigurationView > &newConfigs)
XrEnvironmentBlendMode PickEnvironmentBlendMode(const std::vector< XrEnvironmentBlendMode > &systemSupportedBlendModes, const std::vector< XrEnvironmentBlendMode > &appSupportedBlendModes)
Definition XrEnumerate.h:62
ViewProperties CreateViewProperties(XrInstance instance, XrSystemId systemId, XrViewConfigurationType viewConfigurationType, const std::vector< XrEnvironmentBlendMode > &appSupportedEnvironmentBlendModes)
ViewConfigurationState CreateViewConfigurationState(XrViewConfigurationType viewConfigurationType, XrInstance instance, XrSystemId systemId)
constexpr bool IsPrimaryViewConfigurationType(XrViewConfigurationType type)
std::vector< XrView > Views
std::vector< XrViewConfigurationView > ViewConfigViews
XrViewConfigurationType Type
std::vector< XrEnvironmentBlendMode > SupportedBlendModes
XrViewConfigurationType Type
XrEnvironmentBlendMode BlendMode