Update imgui to 1.91.3

Rework touch handling in lobby GUI

Add imgui patches

Support splitting the imgui viewport/swapchain in different composition layers
This commit is contained in:
Guillaume Meunier
2024-11-01 11:40:33 +01:00
parent 4baff267f6
commit 252b2fd81e
10 changed files with 388 additions and 184 deletions
+51 -11
View File
@@ -103,12 +103,25 @@ static const std::array supported_depth_formats{
void scenes::lobby::move_gui(glm::vec3 head_position, glm::vec3 new_gui_position)
{
const float gui_pitch = -0.2;
const float keyboard_pitch = -0.6;
glm::vec3 gui_direction = new_gui_position - head_position;
float gui_yaw = atan2(gui_direction.x, gui_direction.z) + M_PI;
imgui_ctx->position() = new_gui_position;
imgui_ctx->orientation() = glm::quat(cos(gui_yaw / 2), 0, sin(gui_yaw / 2), 0) * glm::quat(cos(gui_pitch / 2), sin(gui_pitch / 2), 0, 0);
auto q = glm::quat(cos(gui_yaw / 2), 0, sin(gui_yaw / 2), 0) * glm::quat(cos(gui_pitch / 2), sin(gui_pitch / 2), 0, 0);
auto M = glm::mat3_cast(q); // plane-to-world transform
// Main window
imgui_ctx->layers()[0].position = new_gui_position;
imgui_ctx->layers()[0].orientation = q;
// Popup
imgui_ctx->layers()[1].position = new_gui_position + M * glm::vec3(0, 0, 0.05);
imgui_ctx->layers()[1].orientation = q;
// Keyboard
imgui_ctx->layers()[2].position = new_gui_position + M * glm::vec3(0, -0.3, 0.1);
imgui_ctx->layers()[2].orientation = q * glm::quat(cos(keyboard_pitch / 2), sin(keyboard_pitch / 2), 0, 0);
}
scenes::lobby::lobby()
@@ -422,10 +435,11 @@ std::optional<glm::vec3> scenes::lobby::check_recenter_action(XrTime predicted_d
.aim_position = aim->first,
.aim_orientation = aim->second,
});
if (intersection)
if (not intersection.empty())
{
gui_recenter_distance = std::clamp(intersection->second, 0.05f, 1.f);
spdlog::info("recentering at {}m", intersection->second);
gui_recenter_distance = std::clamp(intersection.front().second, 0.05f, 1.f);
spdlog::info("recentering at {}m", intersection.front().second);
}
else
{
@@ -660,7 +674,7 @@ void scenes::lobby::render(const XrFrameState & frame_state)
move_gui(head_position->first, *new_gui_position);
}
XrCompositionLayerQuad imgui_layer = draw_gui(frame_state.predictedDisplayTime);
std::vector<XrCompositionLayerQuad> imgui_layers = draw_gui(frame_state.predictedDisplayTime);
assert(renderer);
renderer->start_frame();
@@ -754,7 +768,9 @@ void scenes::lobby::render(const XrFrameState & frame_state)
if (composition_layer_depth_test_supported)
{
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&lobby_layer));
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&imgui_layer));
for (auto & layer: imgui_layers)
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
// Add XrCompositionLayerDepthTestFB to lobby_layer and imgui_layer
// The sky in the lobby layer and the passthrough layer have the same depth, so the operation must be:
@@ -767,7 +783,8 @@ void scenes::lobby::render(const XrFrameState & frame_state)
.compareOp = application::get_config().passthrough_enabled ? XR_COMPARE_OP_LESS_FB : XR_COMPARE_OP_LESS_OR_EQUAL_FB};
lobby_layer.next = &layer_depth_test;
imgui_layer.next = &layer_depth_test;
for (auto & layer: imgui_layers)
layer.next = &layer_depth_test;
session.end_frame(frame_state.predictedDisplayTime, layers_base, blend_mode);
}
@@ -776,7 +793,8 @@ void scenes::lobby::render(const XrFrameState & frame_state)
if (not application::get_config().passthrough_enabled)
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&lobby_layer));
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&imgui_layer));
for (auto & layer: imgui_layers)
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
if (not composition_layer_depth_test_supported)
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&controllers_layer));
@@ -870,8 +888,30 @@ void scenes::lobby::on_focused()
});
}
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 1500, 1000);
imgui_ctx.emplace(physical_device, device, queue_family_index, queue, application::space(xr::spaces::world), imgui_inputs, swapchain_imgui, glm::vec2{0.6, 0.4});
std::vector<imgui_context::viewport> vps{
{
// Main window
.size = {0.6, 0.4},
.vp_origin = {0, 0},
.vp_size = {1500, 1000},
},
{
// Pop up window
.size = {0.6, 0.2},
.vp_origin = {1500, 0},
.vp_size = {1500, 500},
},
{
// Virtual keyboard
.size = {0.6, 0.2},
.vp_origin = {1500, 500},
.vp_size = {1500, 500},
},
};
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 3000, 1000);
imgui_ctx.emplace(physical_device, device, queue_family_index, queue, imgui_inputs, swapchain_imgui, vps);
try
{
+1 -1
View File
@@ -87,7 +87,7 @@ class lobby : public scene_impl<lobby>
void update_server_list();
XrCompositionLayerQuad draw_gui(XrTime predicted_display_time);
std::vector<XrCompositionLayerQuad> draw_gui(XrTime predicted_display_time);
XrAction recenter_left_action = XR_NULL_HANDLE;
XrAction recenter_right_action = XR_NULL_HANDLE;
+8 -7
View File
@@ -319,6 +319,9 @@ void scenes::lobby::gui_server_list()
if ((async_session.valid() || next_scene) && !ImGui::IsPopupOpen("connecting"))
ImGui::OpenPopup("connecting");
const auto & popup_layer = imgui_ctx->layers()[1];
const glm::vec2 popup_layer_center = popup_layer.vp_origin + popup_layer.vp_size / 2;
ImGui::SetNextWindowPos({popup_layer_center.x, popup_layer_center.y}, ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 10);
ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 2);
@@ -347,7 +350,7 @@ void scenes::lobby::gui_settings()
{
for (float rate: refresh_rates)
{
if (ImGui::Selectable(fmt::format("{}", rate).c_str(), rate == current) and rate != current)
if (ImGui::Selectable(fmt::format("{}", rate).c_str(), rate == current, ImGuiSelectableFlags_SelectOnRelease) and rate != current)
{
session.set_refresh_rate(rate);
config.preferred_refresh_rate = rate;
@@ -369,7 +372,7 @@ void scenes::lobby::gui_settings()
{
for (float scale: available_scales)
{
if (ImGui::Selectable(fmt::format(_F("{} - {}x{} per eye"), scale, (int)(width * scale), (int)(height * scale)).c_str(), scale == current) and scale != current)
if (ImGui::Selectable(fmt::format(_F("{} - {}x{} per eye"), scale, (int)(width * scale), (int)(height * scale)).c_str(), scale == current, ImGuiSelectableFlags_SelectOnRelease) and scale != current)
{
config.resolution_scale = scale;
config.save();
@@ -535,7 +538,7 @@ void scenes::lobby::gui_licenses()
try
{
auto current = std::make_unique<asset>(std::filesystem::path("licenses") / component);
if (ImGui::Selectable(component, component == selected_item))
if (ImGui::Selectable(component, component == selected_item, ImGuiSelectableFlags_SelectOnRelease))
{
selected_item = component;
license = std::move(current);
@@ -909,7 +912,7 @@ void scenes::lobby::draw_features_status(XrTime predicted_display_time)
}
}
XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
std::vector<XrCompositionLayerQuad> scenes::lobby::draw_gui(XrTime predicted_display_time)
{
for (const auto & [key, server]: application::get_config().servers)
{
@@ -929,9 +932,7 @@ XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
ImGui::PushStyleColor(ImGuiCol_WindowBg, IM_COL32(8, 8, 8, 224));
ImGui::SetNextWindowPos({50, 50});
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size - ImVec2(100, 100));
// ImGui::SetNextWindowPos({0, 0});
// ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size);
ImGui::SetNextWindowSize({1400, 900});
ImGui::Begin("WiVRn", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove);
+16 -6
View File
@@ -206,16 +206,23 @@ void scenes::stream::on_focused()
1500,
1000);
imgui_context::viewport vp{
.space = xr::spaces::view,
.position = {0, 0, -1},
.orientation = {1, 0, 0, 0},
.size = {1.0, 0.6666},
.vp_origin = {0, 0},
.vp_size = {1500, 1000},
};
imgui_ctx.emplace(physical_device,
device,
queue_family_index,
queue,
application::space(xr::spaces::view),
std::span<imgui_context::controller>{},
swapchain_imgui,
glm::vec2{1.0, 0.6666});
std::vector{vp});
imgui_ctx->set_position({0, 0, -1}, {1, 0, 0, 0});
plots_toggle_1 = get_action("plots_toggle_1").first;
plots_toggle_2 = get_action("plots_toggle_2").first;
}
@@ -740,17 +747,20 @@ void scenes::stream::render(const XrFrameState & frame_state)
.views = layer_view.data(),
};
XrCompositionLayerQuad imgui_layer;
std::vector<XrCompositionLayerQuad> imgui_layers;
if (imgui_ctx and plots_visible)
{
accumulate_metrics(frame_state.predictedDisplayTime, blit_handles, timestamps);
imgui_layer = plot_performance_metrics(frame_state.predictedDisplayTime);
imgui_layers = plot_performance_metrics(frame_state.predictedDisplayTime);
}
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
if (imgui_ctx and plots_visible)
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&imgui_layer));
{
for (auto & layer: imgui_layers)
layers_base.push_back(reinterpret_cast<XrCompositionLayerBaseHeader *>(&layer));
}
try
{
+1 -1
View File
@@ -232,7 +232,7 @@ private:
int metrics_offset = 0;
void accumulate_metrics(XrTime predicted_display_time, const std::vector<std::shared_ptr<wivrn::shard_accumulator::blit_handle>> & blit_handles, const gpu_timestamps & timestamps);
XrCompositionLayerQuad plot_performance_metrics(XrTime predicted_display_time);
std::vector<XrCompositionLayerQuad> plot_performance_metrics(XrTime predicted_display_time);
void on_reference_space_changed(XrReferenceSpaceType space, XrTime) override;
};
} // namespace scenes
+1 -1
View File
@@ -132,7 +132,7 @@ void scenes::stream::accumulate_metrics(XrTime predicted_display_time, const std
metrics_offset = (metrics_offset + 1) % global_metrics.size();
}
XrCompositionLayerQuad scenes::stream::plot_performance_metrics(XrTime predicted_display_time)
std::vector<XrCompositionLayerQuad> scenes::stream::plot_performance_metrics(XrTime predicted_display_time)
{
imgui_ctx->new_frame(predicted_display_time);
const ImGuiStyle & style = ImGui::GetStyle();