Skip to content

Commit 9f7b536

Browse files
Add basic run as overlay functionality
Add option to run as overlay, with no other changes.
1 parent 09cbbc9 commit 9f7b536

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

src/tests/hello_xr/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@ void ShowHelp() {
3535
// TODO: Improve/update when things are more settled.
3636
Log::Write(Log::Level::Info,
3737
"HelloXr --graphics|-g <Graphics API> [--formfactor|-ff <Form factor>] [--viewconfig|-vc <View config>] "
38-
"[--blendmode|-bm <Blend mode>] [--space|-s <Space>] [--verbose|-v]");
38+
"[--blendmode|-bm <Blend mode>] [--space|-s <Space>] [--overlay <Overlay placement>] [--verbose|-v]");
3939
Log::Write(Log::Level::Info, "Graphics APIs: D3D11, D3D12, OpenGLES, OpenGL, Vulkan2, Vulkan");
4040
Log::Write(Log::Level::Info, "Form factors: Hmd, Handheld");
4141
Log::Write(Log::Level::Info, "View configurations: Mono, Stereo");
4242
Log::Write(Log::Level::Info, "Environment blend modes: Opaque, Additive, AlphaBlend");
4343
Log::Write(Log::Level::Info, "Spaces: View, Local, Stage");
44+
Log::Write(Log::Level::Info, "Overlay: Integer value: [0, UINT32_MAX]");
4445
}
4546

4647
bool UpdateOptionsFromCommandLine(Options& options, int argc, char* argv[]) {
@@ -66,6 +67,8 @@ bool UpdateOptionsFromCommandLine(Options& options, int argc, char* argv[]) {
6667
options.EnvironmentBlendMode = getNextArg();
6768
} else if (EqualsIgnoreCase(arg, "--space") || EqualsIgnoreCase(arg, "-s")) {
6869
options.AppSpace = getNextArg();
70+
} else if (EqualsIgnoreCase(arg, "--overlay") || EqualsIgnoreCase(arg, "-o")) {
71+
options.OverlayPlacement = getNextArg();
6972
} else if (EqualsIgnoreCase(arg, "--verbose") || EqualsIgnoreCase(arg, "-v")) {
7073
Log::SetLevel(Log::Level::Verbose);
7174
} else if (EqualsIgnoreCase(arg, "--help") || EqualsIgnoreCase(arg, "-h")) {

src/tests/hello_xr/openxr_program.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ inline XrEnvironmentBlendMode GetXrEnvironmentBlendMode(const std::string& envir
6262
throw std::invalid_argument(Fmt("Unknown environment blend mode '%s'", environmentBlendModeStr.c_str()));
6363
}
6464

65+
inline uint32_t GetXrOverlayPlacement(const std::string& overlayPlacement) {
66+
try {
67+
unsigned long value = stoul(overlayPlacement);
68+
return static_cast<uint32_t>(value);
69+
} catch (...) {
70+
}
71+
throw std::invalid_argument(Fmt("Invalid overlay placement '%s'", overlayPlacement.c_str()));
72+
}
73+
6574
namespace Math {
6675
namespace Pose {
6776
XrPosef Identity() {
@@ -224,6 +233,10 @@ struct OpenXrProgram : IOpenXrProgram {
224233
std::transform(graphicsExtensions.begin(), graphicsExtensions.end(), std::back_inserter(extensions),
225234
[](const std::string& ext) { return ext.c_str(); });
226235

236+
if (m_overlayApp) {
237+
extensions.push_back(XR_EXTX_OVERLAY_EXTENSION_NAME);
238+
}
239+
227240
XrInstanceCreateInfo createInfo{XR_TYPE_INSTANCE_CREATE_INFO};
228241
createInfo.next = m_platformPlugin->GetInstanceCreateExtension();
229242
createInfo.enabledExtensionCount = (uint32_t)extensions.size();
@@ -325,6 +338,11 @@ struct OpenXrProgram : IOpenXrProgram {
325338
systemInfo.formFactor = m_formFactor;
326339
CHECK_XRCMD(xrGetSystem(m_instance, &systemInfo, &m_systemId));
327340

341+
if (!m_options->OverlayPlacement.empty()) {
342+
m_overlayApp = true;
343+
m_overlayPlacement = GetXrOverlayPlacement(m_options->OverlayPlacement);
344+
}
345+
328346
Log::Write(Log::Level::Verbose, Fmt("Using system %d for form factor %s", m_systemId, to_string(m_formFactor)));
329347
CHECK(m_instance != XR_NULL_HANDLE);
330348
CHECK(m_systemId != XR_NULL_SYSTEM_ID);
@@ -581,6 +599,14 @@ struct OpenXrProgram : IOpenXrProgram {
581599
XrSessionCreateInfo createInfo{XR_TYPE_SESSION_CREATE_INFO};
582600
createInfo.next = m_graphicsPlugin->GetGraphicsBinding();
583601
createInfo.systemId = m_systemId;
602+
603+
XrSessionCreateInfoOverlayEXTX overlayCreateInfo = {XR_TYPE_SESSION_CREATE_INFO_OVERLAY_EXTX, nullptr, 0U, 0U};
604+
if (m_overlayApp) {
605+
overlayCreateInfo.next = createInfo.next;
606+
createInfo.next = &overlayCreateInfo;
607+
overlayCreateInfo.sessionLayersPlacement = m_overlayPlacement;
608+
}
609+
584610
CHECK_XRCMD(xrCreateSession(m_instance, &createInfo, &m_session));
585611
}
586612

@@ -1020,6 +1046,8 @@ struct OpenXrProgram : IOpenXrProgram {
10201046
XrViewConfigurationType m_viewConfigType{XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO};
10211047
XrEnvironmentBlendMode m_environmentBlendMode{XR_ENVIRONMENT_BLEND_MODE_OPAQUE};
10221048
XrSystemId m_systemId{XR_NULL_SYSTEM_ID};
1049+
bool m_overlayApp = false;
1050+
uint32_t m_overlayPlacement = 0;
10231051

10241052
std::vector<XrViewConfigurationView> m_configViews;
10251053
std::vector<Swapchain> m_swapchains;

src/tests/hello_xr/options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ struct Options {
1414
std::string EnvironmentBlendMode{"Opaque"};
1515

1616
std::string AppSpace{"Local"};
17+
18+
std::string OverlayPlacement{""};
1719
};

0 commit comments

Comments
 (0)