clang-format
This commit is contained in:
+210
-212
@@ -21,21 +21,21 @@
|
||||
|
||||
#include "application.h"
|
||||
#include "asset.h"
|
||||
#include "image_loader.h"
|
||||
#include "openxr/openxr.h"
|
||||
#include "utils/ranges.h"
|
||||
#include "vulkan/vulkan_enums.hpp"
|
||||
#include "vulkan/vulkan_handles.hpp"
|
||||
#include "vulkan/vulkan_to_string.hpp"
|
||||
#include <spdlog/spdlog.h>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <backends/imgui_impl_vulkan.h>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <algorithm>
|
||||
#include <backends/imgui_impl_vulkan.h>
|
||||
#include <cmath>
|
||||
#include <cstddef>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <optional>
|
||||
#include "image_loader.h"
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include "IconsFontAwesome6.h"
|
||||
|
||||
@@ -51,47 +51,48 @@
|
||||
* struct ImGui_ImplVulkanH_Window
|
||||
*/
|
||||
|
||||
static vk::raii::RenderPass create_renderpass(vk::raii::Device& device, vk::Format format, bool clear)
|
||||
static vk::raii::RenderPass create_renderpass(vk::raii::Device & device, vk::Format format, bool clear)
|
||||
{
|
||||
vk::AttachmentDescription attachment{
|
||||
.format = format,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = clear ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.stencilLoadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.stencilStoreOp = vk::AttachmentStoreOp::eDontCare,
|
||||
.initialLayout = vk::ImageLayout::eUndefined,
|
||||
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
vk::AttachmentDescription attachment{
|
||||
.format = format,
|
||||
.samples = vk::SampleCountFlagBits::e1,
|
||||
.loadOp = clear ? vk::AttachmentLoadOp::eClear : vk::AttachmentLoadOp::eDontCare,
|
||||
.storeOp = vk::AttachmentStoreOp::eStore,
|
||||
.stencilLoadOp = vk::AttachmentLoadOp::eDontCare,
|
||||
.stencilStoreOp = vk::AttachmentStoreOp::eDontCare,
|
||||
.initialLayout = vk::ImageLayout::eUndefined,
|
||||
.finalLayout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::AttachmentReference color_attachment{
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
.attachment = 0,
|
||||
.layout = vk::ImageLayout::eColorAttachmentOptimal,
|
||||
};
|
||||
|
||||
vk::SubpassDescription subpass = {
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
.colorAttachmentCount = 1,
|
||||
.pColorAttachments = &color_attachment,
|
||||
.pipelineBindPoint = vk::PipelineBindPoint::eGraphics,
|
||||
.colorAttachmentCount = 1,
|
||||
.pColorAttachments = &color_attachment,
|
||||
};
|
||||
|
||||
vk::SubpassDependency dependency = {
|
||||
.srcSubpass = VK_SUBPASS_EXTERNAL,
|
||||
.dstSubpass = 0,
|
||||
.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
.dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
.srcAccessMask = {},
|
||||
.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
|
||||
.srcSubpass = VK_SUBPASS_EXTERNAL,
|
||||
.dstSubpass = 0,
|
||||
.srcStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
.dstStageMask = vk::PipelineStageFlagBits::eColorAttachmentOutput,
|
||||
.srcAccessMask = {},
|
||||
.dstAccessMask = vk::AccessFlagBits::eColorAttachmentWrite,
|
||||
};
|
||||
|
||||
return vk::raii::RenderPass(device, vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
.dependencyCount = 1,
|
||||
.pDependencies = &dependency,
|
||||
});
|
||||
return vk::raii::RenderPass(
|
||||
device, vk::RenderPassCreateInfo{
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &attachment,
|
||||
.subpassCount = 1,
|
||||
.pSubpasses = &subpass,
|
||||
.dependencyCount = 1,
|
||||
.pDependencies = &dependency,
|
||||
});
|
||||
}
|
||||
|
||||
static void check_vk_result(VkResult result)
|
||||
@@ -103,7 +104,7 @@ static void check_vk_result(VkResult result)
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state& in)
|
||||
std::optional<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(const imgui_context::controller_state & in)
|
||||
{
|
||||
if (!in.active)
|
||||
return {};
|
||||
@@ -131,133 +132,129 @@ std::optional<std::pair<ImVec2, float>> imgui_context::ray_plane_intersection(co
|
||||
coord = coord / scale_;
|
||||
|
||||
if (fabs(coord.x) <= 0.5 && fabs(coord.y) <= 0.5)
|
||||
return std::make_pair(ImVec2
|
||||
(
|
||||
(0.5 + coord.x) * size.width,
|
||||
(0.5 - coord.y) * size.height
|
||||
),
|
||||
-lambda);
|
||||
return std::make_pair(ImVec2(
|
||||
(0.5 + coord.x) * size.width,
|
||||
(0.5 - coord.y) * size.height),
|
||||
-lambda);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
imgui_context::imgui_frame& imgui_context::get_frame(vk::Image destination)
|
||||
imgui_context::imgui_frame & imgui_context::get_frame(vk::Image destination)
|
||||
{
|
||||
for(auto& i: frames)
|
||||
for (auto & i: frames)
|
||||
{
|
||||
if (i.destination == destination)
|
||||
return i;
|
||||
}
|
||||
|
||||
auto& frame = frames.emplace_back();
|
||||
auto & frame = frames.emplace_back();
|
||||
|
||||
frame.destination = destination;
|
||||
|
||||
// Only 1 mipmap level for the framebuffer view
|
||||
frame.image_view_framebuffer = vk::raii::ImageView(device, vk::ImageViewCreateInfo{
|
||||
.image = destination,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = format,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
}
|
||||
});
|
||||
|
||||
frame.framebuffer = vk::raii::Framebuffer(device, vk::FramebufferCreateInfo{
|
||||
.renderPass = *renderpass,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*frame.image_view_framebuffer,
|
||||
.width = size.width,
|
||||
.height = size.height,
|
||||
.layers = 1,
|
||||
});
|
||||
frame.image_view_framebuffer = vk::raii::ImageView(
|
||||
device,
|
||||
vk::ImageViewCreateInfo{
|
||||
.image = destination,
|
||||
.viewType = vk::ImageViewType::e2D,
|
||||
.format = format,
|
||||
.subresourceRange = {
|
||||
.aspectMask = vk::ImageAspectFlagBits::eColor,
|
||||
.baseMipLevel = 0,
|
||||
.levelCount = 1,
|
||||
.baseArrayLayer = 0,
|
||||
.layerCount = 1,
|
||||
},
|
||||
});
|
||||
|
||||
frame.framebuffer = vk::raii::Framebuffer(
|
||||
device,
|
||||
vk::FramebufferCreateInfo{
|
||||
.renderPass = *renderpass,
|
||||
.attachmentCount = 1,
|
||||
.pAttachments = &*frame.image_view_framebuffer,
|
||||
.width = size.width,
|
||||
.height = size.height,
|
||||
.layers = 1,
|
||||
});
|
||||
|
||||
return frame;
|
||||
}
|
||||
|
||||
static const std::array pool_sizes =
|
||||
{
|
||||
vk::DescriptorPoolSize{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 100,
|
||||
}
|
||||
};
|
||||
{
|
||||
vk::DescriptorPoolSize{
|
||||
.type = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 100,
|
||||
}};
|
||||
|
||||
static const vk::DescriptorSetLayoutBinding layout_bindings{
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment
|
||||
};
|
||||
.binding = 0,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.descriptorCount = 1,
|
||||
.stageFlags = vk::ShaderStageFlagBits::eFragment};
|
||||
|
||||
imgui_context::imgui_context(vk::raii::PhysicalDevice physical_device, vk::raii::Device& device, uint32_t queue_family_index, vk::raii::Queue& queue, XrSpace world, std::span<controller> controllers_, xr::swapchain& swapchain, glm::vec2 size) :
|
||||
physical_device(physical_device),
|
||||
device(device),
|
||||
queue_family_index(queue_family_index),
|
||||
queue(queue),
|
||||
descriptor_pool(device, vk::DescriptorPoolCreateInfo
|
||||
{
|
||||
.flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
|
||||
.maxSets = pool_sizes[0].descriptorCount,
|
||||
.poolSizeCount = pool_sizes.size(),
|
||||
.pPoolSizes = pool_sizes.data(),
|
||||
}),
|
||||
ds_layout(device, vk::DescriptorSetLayoutCreateInfo
|
||||
{
|
||||
.bindingCount = 1,
|
||||
.pBindings = &layout_bindings
|
||||
}),
|
||||
renderpass(create_renderpass(device, swapchain.format(), true)),
|
||||
command_pool(device, vk::CommandPoolCreateInfo{
|
||||
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer | vk::CommandPoolCreateFlagBits::eTransient,
|
||||
.queueFamilyIndex = queue_family_index,
|
||||
}),
|
||||
command_buffers(swapchain.images().size()),
|
||||
size(swapchain.extent().width, swapchain.extent().height),
|
||||
format(swapchain.format()),
|
||||
scale_(size.x, size.y),
|
||||
swapchain(swapchain),
|
||||
context(ImGui::CreateContext()),
|
||||
plot_context(ImPlot::CreateContext()),
|
||||
io((ImGui::SetCurrentContext(context), ImGui::GetIO())),
|
||||
world(world)
|
||||
imgui_context::imgui_context(vk::raii::PhysicalDevice physical_device, vk::raii::Device & device, uint32_t queue_family_index, vk::raii::Queue & queue, XrSpace world, std::span<controller> controllers_, xr::swapchain & swapchain, glm::vec2 size) :
|
||||
physical_device(physical_device),
|
||||
device(device),
|
||||
queue_family_index(queue_family_index),
|
||||
queue(queue),
|
||||
descriptor_pool(device,
|
||||
vk::DescriptorPoolCreateInfo{
|
||||
.flags = vk::DescriptorPoolCreateFlagBits::eFreeDescriptorSet,
|
||||
.maxSets = pool_sizes[0].descriptorCount,
|
||||
.poolSizeCount = pool_sizes.size(),
|
||||
.pPoolSizes = pool_sizes.data(),
|
||||
}),
|
||||
ds_layout(device, vk::DescriptorSetLayoutCreateInfo{.bindingCount = 1, .pBindings = &layout_bindings}),
|
||||
renderpass(create_renderpass(device, swapchain.format(), true)),
|
||||
command_pool(device,
|
||||
vk::CommandPoolCreateInfo{
|
||||
.flags = vk::CommandPoolCreateFlagBits::eResetCommandBuffer | vk::CommandPoolCreateFlagBits::eTransient,
|
||||
.queueFamilyIndex = queue_family_index,
|
||||
}),
|
||||
command_buffers(swapchain.images().size()),
|
||||
size(swapchain.extent().width, swapchain.extent().height),
|
||||
format(swapchain.format()),
|
||||
scale_(size.x, size.y),
|
||||
swapchain(swapchain),
|
||||
context(ImGui::CreateContext()),
|
||||
plot_context(ImPlot::CreateContext()),
|
||||
io((ImGui::SetCurrentContext(context), ImGui::GetIO())),
|
||||
world(world)
|
||||
{
|
||||
controllers.reserve(controllers_.size());
|
||||
for(const auto& i:controllers_)
|
||||
for (const auto & i: controllers_)
|
||||
controllers.emplace_back(i, controller_state{});
|
||||
|
||||
io.IniFilename = nullptr;
|
||||
|
||||
for(command_buffer& cb: command_buffers)
|
||||
for (command_buffer & cb: command_buffers)
|
||||
{
|
||||
cb.command_buffer = std::move(device.allocateCommandBuffers({
|
||||
.commandPool = *command_pool,
|
||||
.commandBufferCount = 1,
|
||||
.commandPool = *command_pool,
|
||||
.commandBufferCount = 1,
|
||||
})[0]);
|
||||
|
||||
cb.fence = device.createFence(vk::FenceCreateInfo{.flags = vk::FenceCreateFlagBits::eSignaled});
|
||||
}
|
||||
|
||||
ImGui_ImplVulkan_InitInfo init_info = {
|
||||
.Instance = *application::get_vulkan_instance(),
|
||||
.PhysicalDevice = *application::get_physical_device(),
|
||||
.Device = *application::get_device(),
|
||||
.QueueFamily = application::queue_family_index(),
|
||||
.Queue = *application::get_queue(),
|
||||
.PipelineCache = *application::get_pipeline_cache(),
|
||||
.DescriptorPool = *descriptor_pool,
|
||||
.Subpass = 0,
|
||||
.MinImageCount = 2,
|
||||
.ImageCount = (uint32_t)swapchain.images().size(), // used to cycle between VkBuffers in ImGui_ImplVulkan_RenderDrawData
|
||||
.MSAASamples = VK_SAMPLE_COUNT_1_BIT,
|
||||
.Allocator = nullptr,
|
||||
.CheckVkResultFn = check_vk_result,
|
||||
.Instance = *application::get_vulkan_instance(),
|
||||
.PhysicalDevice = *application::get_physical_device(),
|
||||
.Device = *application::get_device(),
|
||||
.QueueFamily = application::queue_family_index(),
|
||||
.Queue = *application::get_queue(),
|
||||
.PipelineCache = *application::get_pipeline_cache(),
|
||||
.DescriptorPool = *descriptor_pool,
|
||||
.Subpass = 0,
|
||||
.MinImageCount = 2,
|
||||
.ImageCount = (uint32_t)swapchain.images().size(), // used to cycle between VkBuffers in ImGui_ImplVulkan_RenderDrawData
|
||||
.MSAASamples = VK_SAMPLE_COUNT_1_BIT,
|
||||
.Allocator = nullptr,
|
||||
.CheckVkResultFn = check_vk_result,
|
||||
};
|
||||
|
||||
ImGui::SetCurrentContext(context);
|
||||
@@ -271,29 +268,27 @@ imgui_context::imgui_context(vk::raii::PhysicalDevice physical_device, vk::raii:
|
||||
{
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte*>(roboto.data()), roboto.size(), 30, &config);
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(roboto.data()), roboto.size(), 30, &config);
|
||||
|
||||
config.MergeMode = true;
|
||||
config.GlyphMinAdvanceX = 40; // Use if you want to make the icon monospaced
|
||||
static const ImWchar icon_ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 };
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte*>(font_awesome_regular.data()), font_awesome_regular.size(), 30, &config, icon_ranges);
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte*>(font_awesome_solid.data()), font_awesome_solid.size(), 30, &config, icon_ranges);
|
||||
static const ImWchar icon_ranges[] = {ICON_MIN_FA, ICON_MAX_FA, 0};
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(font_awesome_regular.data()), font_awesome_regular.size(), 30, &config, icon_ranges);
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(font_awesome_solid.data()), font_awesome_solid.size(), 30, &config, icon_ranges);
|
||||
}
|
||||
|
||||
{
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
large_font = io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte*>(roboto.data()), roboto.size(), 75, &config);
|
||||
|
||||
large_font = io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte *>(roboto.data()), roboto.size(), 75, &config);
|
||||
}
|
||||
|
||||
|
||||
// Setup Dear ImGui style
|
||||
ImGui::StyleColorsDark();
|
||||
// ImGui::StyleColorsClassic();
|
||||
//ImGui::StyleColorsLight();
|
||||
// ImGui::StyleColorsLight();
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
|
||||
style.WindowBorderSize = 0;
|
||||
}
|
||||
@@ -313,22 +308,21 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
|
||||
std::vector<controller_state> new_states;
|
||||
|
||||
for(auto&& [index, controller]: utils::enumerate(controllers))
|
||||
for (auto && [index, controller]: utils::enumerate(controllers))
|
||||
{
|
||||
auto& [ctrl, state] = controller;
|
||||
auto & [ctrl, state] = controller;
|
||||
|
||||
controller_state& new_state = new_states.emplace_back();
|
||||
controller_state & new_state = new_states.emplace_back();
|
||||
|
||||
if (auto joints = ctrl.hand.locate(world, display_time))
|
||||
{
|
||||
XrHandJointLocationEXT& index_tip = (*joints)[XR_HAND_JOINT_INDEX_TIP_EXT].first;
|
||||
XrHandJointLocationEXT & index_tip = (*joints)[XR_HAND_JOINT_INDEX_TIP_EXT].first;
|
||||
if (index_tip.locationFlags & XR_SPACE_LOCATION_POSITION_TRACKED_BIT)
|
||||
{
|
||||
new_state.aim_position = {
|
||||
index_tip.pose.position.x,
|
||||
index_tip.pose.position.y,
|
||||
index_tip.pose.position.z
|
||||
};
|
||||
index_tip.pose.position.x,
|
||||
index_tip.pose.position.y,
|
||||
index_tip.pose.position.z};
|
||||
|
||||
new_state.aim_orientation = orientation_;
|
||||
|
||||
@@ -340,7 +334,7 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
new_state.hover_distance = std::abs(position_distance->second);
|
||||
|
||||
if (std::abs(position_distance->second) < 0.1f)
|
||||
new_state.fingertip_hovered = true;
|
||||
new_state.fingertip_hovered = true;
|
||||
else
|
||||
new_state.active = false;
|
||||
|
||||
@@ -363,7 +357,7 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
|
||||
if (ctrl.squeeze)
|
||||
{
|
||||
auto squeeze = application::read_action_float(ctrl.squeeze).value_or(std::pair{0,0});
|
||||
auto squeeze = application::read_action_float(ctrl.squeeze).value_or(std::pair{0, 0});
|
||||
new_state.squeeze_value = squeeze.second;
|
||||
|
||||
// TODO tunable
|
||||
@@ -375,7 +369,7 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
|
||||
if (ctrl.trigger)
|
||||
{
|
||||
auto trigger = application::read_action_float(ctrl.trigger).value_or(std::pair{0,0});
|
||||
auto trigger = application::read_action_float(ctrl.trigger).value_or(std::pair{0, 0});
|
||||
new_state.trigger_value = trigger.second;
|
||||
|
||||
// TODO tunable
|
||||
@@ -388,20 +382,20 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
if (ctrl.scroll)
|
||||
{
|
||||
if (auto act = application::read_action_vec2(ctrl.scroll); act)
|
||||
new_state.scroll_value = { -act->second.x * scroll_scale, act->second.y * scroll_scale };
|
||||
new_state.scroll_value = {-act->second.x * scroll_scale, act->second.y * scroll_scale};
|
||||
else
|
||||
new_state.scroll_value = {0, 0};
|
||||
}
|
||||
}
|
||||
|
||||
for(auto [new_state, controller]: utils::zip(new_states, controllers))
|
||||
for (auto [new_state, controller]: utils::zip(new_states, controllers))
|
||||
{
|
||||
if (new_state.hover_distance < 0.02 && controller.second.hover_distance >= 0.02)
|
||||
new_state.fingertip_touched = true;
|
||||
}
|
||||
|
||||
float closest_hover_distance = 1e10;
|
||||
for(auto&& [index, new_state]: utils::enumerate(new_states))
|
||||
for (auto && [index, new_state]: utils::enumerate(new_states))
|
||||
{
|
||||
if (new_state.hover_distance < closest_hover_distance && new_state.fingertip_hovered)
|
||||
{
|
||||
@@ -434,7 +428,7 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
|
||||
bool last_trigger = controllers[new_focused_controller].second.trigger_clicked || controllers[new_focused_controller].second.fingertip_touched;
|
||||
button_pressed = new_states[new_focused_controller].trigger_clicked ||
|
||||
(new_states[new_focused_controller].fingertip_touched && !controllers[new_focused_controller].second.fingertip_touched);
|
||||
(new_states[new_focused_controller].fingertip_touched && !controllers[new_focused_controller].second.fingertip_touched);
|
||||
|
||||
if (position_distance)
|
||||
{
|
||||
@@ -462,7 +456,7 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
}
|
||||
|
||||
focused_controller = new_focused_controller;
|
||||
for(auto&& [controller, next_state]: utils::zip(controllers, new_states))
|
||||
for (auto && [controller, next_state]: utils::zip(controllers, new_states))
|
||||
{
|
||||
controller.second = next_state;
|
||||
}
|
||||
@@ -477,18 +471,16 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
|
||||
ImGui::NewFrame();
|
||||
|
||||
ImDrawList* draw_list = ImGui::GetForegroundDrawList();
|
||||
ImDrawList * draw_list = ImGui::GetForegroundDrawList();
|
||||
|
||||
if (position_distance)
|
||||
{
|
||||
float distance_to_border = std::min({
|
||||
position_distance->first.x,
|
||||
size.width - position_distance->first.x,
|
||||
position_distance->first.y,
|
||||
size.height - position_distance->first.y
|
||||
});
|
||||
float distance_to_border = std::min({position_distance->first.x,
|
||||
size.width - position_distance->first.x,
|
||||
position_distance->first.y,
|
||||
size.height - position_distance->first.y});
|
||||
|
||||
float radius = 10; //std::clamp<float>(distance_to_border / 4, 0, 10);
|
||||
float radius = 10; // std::clamp<float>(distance_to_border / 4, 0, 10);
|
||||
float alpha = std::clamp<float>((distance_to_border - 10) / 50, 0, 0.8);
|
||||
|
||||
ImU32 color_pressed = ImGui::GetColorU32(ImVec4(0, 0.2, 1, alpha));
|
||||
@@ -497,7 +489,7 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
bool pressed = button_pressed || new_states[new_focused_controller].fingertip_touched;
|
||||
|
||||
draw_list->AddCircleFilled(position_distance->first, radius, pressed ? color_pressed : color_unpressed);
|
||||
draw_list->AddCircle(position_distance->first, radius*1.2, ImGui::GetColorU32(ImVec4(0, 0, 0, alpha)), 0, radius * 0.4);
|
||||
draw_list->AddCircle(position_distance->first, radius * 1.2, ImGui::GetColorU32(ImVec4(0, 0, 0, alpha)), 0, radius * 0.4);
|
||||
}
|
||||
|
||||
image_index = swapchain.acquire();
|
||||
@@ -515,9 +507,9 @@ XrCompositionLayerQuad imgui_context::end_frame()
|
||||
|
||||
current_command_buffer = (current_command_buffer + 1) % command_buffers.size();
|
||||
|
||||
auto& f = get_frame(destination);
|
||||
auto& cb = get_command_buffer().command_buffer;
|
||||
auto& fence = get_command_buffer().fence;
|
||||
auto & f = get_frame(destination);
|
||||
auto & cb = get_command_buffer().command_buffer;
|
||||
auto & fence = get_command_buffer().fence;
|
||||
|
||||
if (auto result = device.waitForFences(*fence, true, 1'000'000'000); result != vk::Result::eSuccess)
|
||||
throw std::runtime_error("vkWaitForfences: " + vk::to_string(result));
|
||||
@@ -528,14 +520,14 @@ XrCompositionLayerQuad imgui_context::end_frame()
|
||||
vk::ClearValue clear{vk::ClearColorValue(0, 0, 0, 0)};
|
||||
|
||||
cb.beginRenderPass(vk::RenderPassBeginInfo{
|
||||
.renderPass = *renderpass,
|
||||
.framebuffer = *f.framebuffer,
|
||||
.renderArea = {
|
||||
.extent = size,
|
||||
},
|
||||
.clearValueCount = 1,
|
||||
.pClearValues = &clear
|
||||
}, vk::SubpassContents::eInline);
|
||||
.renderPass = *renderpass,
|
||||
.framebuffer = *f.framebuffer,
|
||||
.renderArea = {
|
||||
.extent = size,
|
||||
},
|
||||
.clearValueCount = 1,
|
||||
.pClearValues = &clear},
|
||||
vk::SubpassContents::eInline);
|
||||
|
||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), *cb);
|
||||
|
||||
@@ -544,25 +536,26 @@ XrCompositionLayerQuad imgui_context::end_frame()
|
||||
cb.end();
|
||||
|
||||
queue.submit(vk::SubmitInfo{
|
||||
.commandBufferCount = 1,
|
||||
.pCommandBuffers = &*cb,
|
||||
}, *fence);
|
||||
.commandBufferCount = 1,
|
||||
.pCommandBuffers = &*cb,
|
||||
},
|
||||
*fence);
|
||||
|
||||
swapchain.release();
|
||||
|
||||
return XrCompositionLayerQuad{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_QUAD,
|
||||
.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
.space = world,
|
||||
.eyeVisibility = XrEyeVisibility::XR_EYE_VISIBILITY_BOTH,
|
||||
.subImage = {
|
||||
.swapchain = swapchain,
|
||||
.imageRect = {
|
||||
.offset = {0, 0},
|
||||
.extent = {(int32_t)size.width, (int32_t)size.height}},
|
||||
},
|
||||
.pose = pose(),
|
||||
.size = scale(),
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_QUAD,
|
||||
.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
.space = world,
|
||||
.eyeVisibility = XrEyeVisibility::XR_EYE_VISIBILITY_BOTH,
|
||||
.subImage = {
|
||||
.swapchain = swapchain,
|
||||
.imageRect = {
|
||||
.offset = {0, 0},
|
||||
.extent = {(int32_t)size.width, (int32_t)size.height}},
|
||||
},
|
||||
.pose = pose(),
|
||||
.size = scale(),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -574,7 +567,7 @@ imgui_context::~imgui_context()
|
||||
std::vector<vk::Fence> fences;
|
||||
|
||||
// Release the command buffers without freing them, they will be destroyed with the command pool
|
||||
for(auto& f: command_buffers)
|
||||
for (auto & f: command_buffers)
|
||||
{
|
||||
f.command_buffer.release();
|
||||
fences.push_back(*f.fence);
|
||||
@@ -589,54 +582,59 @@ imgui_context::~imgui_context()
|
||||
ImGui::DestroyContext(context);
|
||||
}
|
||||
|
||||
|
||||
ImTextureID imgui_context::load_texture(const std::string& filename, vk::raii::Sampler&& sampler)
|
||||
ImTextureID imgui_context::load_texture(const std::string & filename, vk::raii::Sampler && sampler)
|
||||
{
|
||||
bool srgb = true;
|
||||
image_loader loader(physical_device, device, queue, command_pool);
|
||||
loader.load(asset{filename}, srgb);
|
||||
|
||||
vk::raii::DescriptorSet ds = std::move(device.allocateDescriptorSets({
|
||||
.descriptorPool = *descriptor_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*ds_layout
|
||||
.descriptorPool = *descriptor_pool,
|
||||
.descriptorSetCount = 1,
|
||||
.pSetLayouts = &*ds_layout,
|
||||
})[0]);
|
||||
|
||||
vk::DescriptorImageInfo image_info{
|
||||
.sampler = *sampler,
|
||||
.imageView = **loader.image_view,
|
||||
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
.sampler = *sampler,
|
||||
.imageView = **loader.image_view,
|
||||
.imageLayout = vk::ImageLayout::eShaderReadOnlyOptimal,
|
||||
};
|
||||
|
||||
vk::WriteDescriptorSet ds_write{
|
||||
.dstSet = *ds,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info
|
||||
};
|
||||
.dstSet = *ds,
|
||||
.descriptorCount = 1,
|
||||
.descriptorType = vk::DescriptorType::eCombinedImageSampler,
|
||||
.pImageInfo = &image_info};
|
||||
|
||||
device.updateDescriptorSets(ds_write, nullptr);
|
||||
|
||||
ImTextureID id = *ds;
|
||||
|
||||
textures.emplace(id, texture_data{
|
||||
.sampler = std::move(sampler),
|
||||
// .image = std::move(loader.image),
|
||||
.image_view = std::move(loader.image_view),
|
||||
.descriptor_set = std::move(ds),
|
||||
});
|
||||
textures.emplace(
|
||||
id,
|
||||
texture_data{
|
||||
.sampler = std::move(sampler),
|
||||
// .image = std::move(loader.image),
|
||||
.image_view = std::move(loader.image_view),
|
||||
.descriptor_set = std::move(ds),
|
||||
});
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
ImTextureID imgui_context::load_texture(const std::string& filename)
|
||||
ImTextureID imgui_context::load_texture(const std::string & filename)
|
||||
{
|
||||
return load_texture(filename, vk::raii::Sampler(device, vk::SamplerCreateInfo{
|
||||
.magFilter = vk::Filter::eLinear,
|
||||
.minFilter = vk::Filter::eLinear,
|
||||
.mipmapMode = vk::SamplerMipmapMode::eLinear,
|
||||
.borderColor = vk::BorderColor::eFloatTransparentBlack,
|
||||
}));
|
||||
return load_texture(
|
||||
filename,
|
||||
vk::raii::Sampler{
|
||||
device,
|
||||
vk::SamplerCreateInfo{
|
||||
.magFilter = vk::Filter::eLinear,
|
||||
.minFilter = vk::Filter::eLinear,
|
||||
.mipmapMode = vk::SamplerMipmapMode::eLinear,
|
||||
.borderColor = vk::BorderColor::eFloatTransparentBlack,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
void imgui_context::free_texture(ImTextureID texture)
|
||||
|
||||
Reference in New Issue
Block a user