Add support for alpha environment blend passthrough

This commit is contained in:
Patrick Nicolas
2024-04-12 14:53:22 +02:00
parent f8207631bb
commit 5d91bf0763
3 changed files with 36 additions and 6 deletions
+25 -5
View File
@@ -536,6 +536,17 @@ static std::vector<XrCompositionLayerProjectionView> render_layer(std::vector<Xr
return layer_views;
}
namespace
{
template <class... Ts>
struct overloaded : Ts...
{
using Ts::operator()...;
};
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;
} // namespace
void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
{
if (async_session.valid() && async_session.poll() == utils::future_status::ready)
@@ -653,14 +664,19 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
.views = controllers_layer_views.data(),
};
XrEnvironmentBlendMode blend_mode = XR_ENVIRONMENT_BLEND_MODE_OPAQUE;
std::vector<XrCompositionLayerBaseHeader *> layers_base;
if (passthrough_enabled)
{
std::visit(
[&](auto & p) {
layers_base.push_back(p.layer());
},
overloaded{
[&](xr::passthrough_alpha_blend & p) {
blend_mode = XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND;
},
[&](auto & p) {
layers_base.push_back(p.layer());
}},
passthrough);
}
else
@@ -670,7 +686,7 @@ void scenes::lobby::render(XrTime predicted_display_time, bool should_render)
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&imgui_layer));
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&controllers_layer));
session.end_frame(predicted_display_time, layers_base);
session.end_frame(predicted_display_time, layers_base, blend_mode);
}
void scenes::lobby::on_focused()
@@ -749,7 +765,11 @@ void scenes::lobby::on_focused()
if (passthrough_supported != xr::system::passthrough_type::no_passthrough)
{
if (utils::contains(application::get_xr_extensions(), XR_FB_PASSTHROUGH_EXTENSION_NAME))
if (utils::contains(system.environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND))
{
passthrough.emplace<xr::passthrough_alpha_blend>();
}
else if (utils::contains(application::get_xr_extensions(), XR_FB_PASSTHROUGH_EXTENSION_NAME))
{
passthrough.emplace<xr::passthrough_fb>(instance, session);
}
+8 -1
View File
@@ -91,6 +91,13 @@ public:
}
};
using passthrough = std::variant<passthrough_fb, passthrough_htc>;
class passthrough_alpha_blend
{
public:
void start() {}
void pause() {}
};
using passthrough = std::variant<passthrough_fb, passthrough_htc, passthrough_alpha_blend>;
} // namespace xr
+3
View File
@@ -89,6 +89,9 @@ XrSystemHandTrackingPropertiesEXT xr::system::hand_tracking_properties() const
xr::system::passthrough_type xr::system::passthrough_supported() const
{
if (utils::contains(environment_blend_modes(XR_VIEW_CONFIGURATION_TYPE_PRIMARY_STEREO), XR_ENVIRONMENT_BLEND_MODE_ALPHA_BLEND))
return passthrough_type::color;
const std::vector<std::string> & xr_extensions = application::get_xr_extensions();
if (utils::contains(xr_extensions, XR_HTC_PASSTHROUGH_EXTENSION_NAME))
return passthrough_type::color;