GUI: changed the main window
This commit is contained in:
Binary file not shown.
Binary file not shown.
+41
-9
@@ -20,14 +20,14 @@
|
||||
"count": 6,
|
||||
"type": "VEC3",
|
||||
"max": [
|
||||
100,
|
||||
10,
|
||||
0,
|
||||
100
|
||||
10
|
||||
],
|
||||
"min": [
|
||||
-100,
|
||||
-10,
|
||||
0,
|
||||
-100
|
||||
-10
|
||||
],
|
||||
"name": "POSITION"
|
||||
},
|
||||
@@ -38,12 +38,12 @@
|
||||
"count": 6,
|
||||
"type": "VEC2",
|
||||
"max": [
|
||||
100,
|
||||
5,
|
||||
1
|
||||
],
|
||||
"min": [
|
||||
0,
|
||||
-99
|
||||
-4
|
||||
],
|
||||
"name": "TEXCOORD_0"
|
||||
},
|
||||
@@ -67,7 +67,7 @@
|
||||
}
|
||||
],
|
||||
"asset": {
|
||||
"generator": "Aspose.3D 23.12.0",
|
||||
"generator": "Aspose.3D 24.1.0",
|
||||
"version": "2.0"
|
||||
},
|
||||
"extensionsUsed": [
|
||||
@@ -75,7 +75,7 @@
|
||||
],
|
||||
"buffers": [
|
||||
{
|
||||
"uri": "data:application/octet-stream;base64,AAABAAIAAwAEAAUAAAAAAAAAyMIAAAAAAADIwgAAAAAAAIA/AAAAACUAgD8AAAAAAADIwgAAAAAAAMhCAADIQgAAgD8AAAAAJQCAPwAAAAAAAMhCAAAAAAAAyMIAAAAAAADGwgAAAAAlAIA/AAAAAAAAyEIAAAAAAADIQgAAyEIAAMbCAAAAACUAgD8AAAAAAADIQgAAAAAAAMjCAAAAAAAAxsIAAAAAJQCAPwAAAAAAAMjCAAAAAAAAyEIAAMhCAACAPwAAAAAlAIA/AAAAAAAAAAA=",
|
||||
"uri": "data:application/octet-stream;base64,AAABAAIAAwAEAAUAAAAAAAAAIMEAAAAAAAAgwQAAAAAAAIA/AAAAACUAgD8AAAAAAAAgwQAAAAAAACBBAACgQAAAgD8AAAAAJQCAPwAAAAAAACBBAAAAAAAAIMEAAAAAAACAwAAAAAAlAIA/AAAAAAAAIEEAAAAAAAAgQQAAoEAAAIDAAAAAACUAgD8AAAAAAAAgQQAAAAAAACDBAAAAAAAAgMAAAAAAJQCAPwAAAAAAACDBAAAAAAAAIEEAAKBAAACAPwAAAAAlAIA/AAAAAAAAAAA=",
|
||||
"byteLength": 212
|
||||
}
|
||||
],
|
||||
@@ -151,13 +151,45 @@
|
||||
{
|
||||
"mesh": 0,
|
||||
"name": "ground"
|
||||
},
|
||||
{
|
||||
"mesh": 0,
|
||||
"translation": [-20,0,0]
|
||||
},
|
||||
{
|
||||
"mesh": 0,
|
||||
"translation": [20,0,0]
|
||||
},
|
||||
{
|
||||
"mesh": 0,
|
||||
"translation": [0,0,-20]
|
||||
},
|
||||
{
|
||||
"mesh": 0,
|
||||
"translation": [-20,0,-20]
|
||||
},
|
||||
{
|
||||
"mesh": 0,
|
||||
"translation": [20,0,-20]
|
||||
},
|
||||
{
|
||||
"mesh": 0,
|
||||
"translation": [0,0,20]
|
||||
},
|
||||
{
|
||||
"mesh": 0,
|
||||
"translation": [-20,0,20]
|
||||
},
|
||||
{
|
||||
"mesh": 0,
|
||||
"translation": [20,0,20]
|
||||
}
|
||||
],
|
||||
"scene": 0,
|
||||
"scenes": [
|
||||
{
|
||||
"nodes": [
|
||||
0
|
||||
0,1,2,3,4,5,6,7,8
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -92,6 +92,8 @@ vk::Format get_format_srgb(int num_components)
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
int bytes_per_pixel(vk::Format format)
|
||||
@@ -125,6 +127,8 @@ int bytes_per_pixel(vk::Format format)
|
||||
default:
|
||||
assert(false);
|
||||
}
|
||||
|
||||
__builtin_unreachable();
|
||||
}
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
#include <backends/imgui_impl_vulkan.h>
|
||||
#include <glm/gtc/matrix_access.hpp>
|
||||
|
||||
#include "../external/IconsFontAwesome6.h"
|
||||
|
||||
/* Do not use:
|
||||
*
|
||||
* ImGui_ImplVulkanH_SelectSurfaceFormat
|
||||
@@ -123,7 +125,7 @@ std::optional<ImVec2> imgui_context::ray_plane_intersection(const imgui_context:
|
||||
coord.y = ray_start.y + lambda * ray_dir.y;
|
||||
|
||||
// Convert from mesh coordinates to imgui coordinates
|
||||
coord = coord / scale;
|
||||
coord = coord / scale_;
|
||||
|
||||
if (fabs(coord.x) <= 0.5 && fabs(coord.y) <= 0.5)
|
||||
return ImVec2(
|
||||
@@ -182,7 +184,7 @@ static const std::array pool_sizes =
|
||||
}
|
||||
};
|
||||
|
||||
imgui_context::imgui_context(vk::raii::Device& device, uint32_t queue_family_index, vk::raii::Queue& queue, XrSpace world, std::span<controller> controllers_, vk::Extent2D size, float resolution, vk::Format format, int frames_in_flight) :
|
||||
imgui_context::imgui_context(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) :
|
||||
device(device),
|
||||
queue_family_index(queue_family_index),
|
||||
queue(queue),
|
||||
@@ -193,17 +195,18 @@ imgui_context::imgui_context(vk::raii::Device& device, uint32_t queue_family_ind
|
||||
.poolSizeCount = pool_sizes.size(),
|
||||
.pPoolSizes = pool_sizes.data(),
|
||||
}),
|
||||
renderpass(create_renderpass(device, format, true)),
|
||||
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(frames_in_flight),
|
||||
size(size),
|
||||
format(format),
|
||||
scale(size.width / resolution, size.height / resolution),
|
||||
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()),
|
||||
io(ImGui::GetIO()),
|
||||
io((ImGui::SetCurrentContext(context), ImGui::GetIO())),
|
||||
world(world)
|
||||
{
|
||||
controllers.reserve(controllers_.size());
|
||||
@@ -232,21 +235,37 @@ imgui_context::imgui_context(vk::raii::Device& device, uint32_t queue_family_ind
|
||||
.DescriptorPool = *descriptor_pool,
|
||||
.Subpass = 0,
|
||||
.MinImageCount = 2,
|
||||
.ImageCount = (uint32_t)frames_in_flight, // used to cycle between VkBuffers in ImGui_ImplVulkan_RenderDrawData
|
||||
.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);
|
||||
ImGui_ImplVulkan_Init(&init_info, *renderpass);
|
||||
|
||||
// Load Fonts
|
||||
ImFontConfig config;
|
||||
asset roboto("Roboto-Regular.ttf");
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte*>(roboto.data()), roboto.size(), 45, &config);
|
||||
asset font_awesome_regular("Font Awesome 6 Free-Regular-400.otf");
|
||||
asset font_awesome_solid("Font Awesome 6 Free-Solid-900.otf");
|
||||
{
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte*>(roboto.data()), roboto.size(), 30, &config);
|
||||
|
||||
large_font = io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte*>(roboto.data()), roboto.size(), 90, &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);
|
||||
}
|
||||
|
||||
{
|
||||
ImFontConfig config;
|
||||
config.FontDataOwnedByAtlas = false;
|
||||
large_font = io.Fonts->AddFontFromMemoryTTF(const_cast<std::byte*>(roboto.data()), roboto.size(), 45, &config);
|
||||
|
||||
}
|
||||
|
||||
|
||||
// Setup Dear ImGui style
|
||||
@@ -256,23 +275,13 @@ imgui_context::imgui_context(vk::raii::Device& device, uint32_t queue_family_ind
|
||||
|
||||
ImGuiStyle& style = ImGui::GetStyle();
|
||||
|
||||
style.ScaleAllSizes(2.5f);
|
||||
|
||||
style.WindowPadding = { 50, 50 };
|
||||
style.WindowBorderSize = 10; // Not scaled by ScaleAllSizes
|
||||
style.WindowRounding = 25;
|
||||
style.ItemSpacing = {50, 50};
|
||||
|
||||
style.FrameRounding = 10;
|
||||
style.FramePadding = ImVec2(15, 10);
|
||||
|
||||
style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0,0,0,0.8);
|
||||
|
||||
// TODO: scroll to drag https://github.com/ocornut/imgui/issues/3379
|
||||
style.WindowBorderSize = 0;
|
||||
}
|
||||
|
||||
void imgui_context::new_frame(XrTime display_time)
|
||||
{
|
||||
ImGui::SetCurrentContext(context);
|
||||
|
||||
if (last_display_time)
|
||||
io.DeltaTime = std::min((display_time - last_display_time) * 1e-9f, 0.1f);
|
||||
last_display_time = display_time;
|
||||
@@ -350,22 +359,19 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
}
|
||||
|
||||
std::optional<ImVec2> position;
|
||||
float trigger;
|
||||
|
||||
if (new_focused_controller != (size_t)-1)
|
||||
{
|
||||
position = ray_plane_intersection(new_states[new_focused_controller]);
|
||||
trigger = new_states[new_focused_controller].trigger_value;
|
||||
auto scroll = new_states[new_focused_controller].scroll_value;
|
||||
|
||||
bool last_trigger = controllers[new_focused_controller].second.trigger_clicked;
|
||||
button_pressed = new_states[new_focused_controller].trigger_clicked;
|
||||
|
||||
if (position)
|
||||
{
|
||||
io.AddMousePosEvent(position->x, position->y);
|
||||
|
||||
button_pressed = new_states[new_focused_controller].trigger_clicked;
|
||||
|
||||
if (focused_change || last_trigger != button_pressed)
|
||||
{
|
||||
io.AddMouseButtonEvent(0, button_pressed);
|
||||
@@ -385,7 +391,6 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
else
|
||||
{
|
||||
position = {};
|
||||
trigger = 0;
|
||||
}
|
||||
|
||||
focused_controller = new_focused_controller;
|
||||
@@ -395,7 +400,6 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
}
|
||||
|
||||
// Start the Dear ImGui frame
|
||||
ImGui::SetCurrentContext(context);
|
||||
ImGui_ImplVulkan_NewFrame();
|
||||
|
||||
io.DisplaySize = ImVec2(size.width, size.height);
|
||||
@@ -407,18 +411,30 @@ void imgui_context::new_frame(XrTime display_time)
|
||||
|
||||
ImDrawList* draw_list = ImGui::GetForegroundDrawList();
|
||||
|
||||
if (position && io.WantCaptureMouse)
|
||||
if (position)
|
||||
{
|
||||
ImU32 color_pressed = ImGui::GetColorU32(ImVec4(0, 0.2, 1, 0.8));
|
||||
ImU32 color_unpressed = ImGui::GetColorU32(ImVec4(1, 1, 1, 0.8));
|
||||
float distance_to_border = std::min({
|
||||
position->x,
|
||||
size.width - position->x,
|
||||
position->y,
|
||||
size.height - position->y
|
||||
});
|
||||
|
||||
draw_list->AddCircleFilled(*position, 10, button_pressed ? color_pressed : color_unpressed);
|
||||
draw_list->AddCircle(*position, 12, ImGui::GetColorU32(ImVec4(0,0,0,0.8)), 0, 4);
|
||||
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));
|
||||
ImU32 color_unpressed = ImGui::GetColorU32(ImVec4(1, 1, 1, alpha));
|
||||
|
||||
draw_list->AddCircleFilled(*position, radius, button_pressed ? color_pressed : color_unpressed);
|
||||
draw_list->AddCircle(*position, radius*1.2, ImGui::GetColorU32(ImVec4(0, 0, 0, alpha)), 0, radius * 0.4);
|
||||
}
|
||||
}
|
||||
|
||||
void imgui_context::render(vk::Image destination)
|
||||
{
|
||||
ImGui::SetCurrentContext(context);
|
||||
|
||||
ImGui::Render();
|
||||
ImDrawData* draw_data = ImGui::GetDrawData();
|
||||
const bool is_minimized = (draw_data->DisplaySize.x <= 0.0f || draw_data->DisplaySize.y <= 0.0f);
|
||||
@@ -466,6 +482,8 @@ void imgui_context::render(vk::Image destination)
|
||||
|
||||
imgui_context::~imgui_context()
|
||||
{
|
||||
ImGui::SetCurrentContext(context);
|
||||
|
||||
std::vector<vk::Fence> fences;
|
||||
|
||||
// Release the command buffers without freing them, they will be destroyed with the command pool
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "xr/swapchain.h"
|
||||
#include <imgui.h>
|
||||
#include <vulkan/vulkan_raii.hpp>
|
||||
#include <glm/glm.hpp>
|
||||
@@ -95,7 +96,9 @@ private:
|
||||
|
||||
glm::vec3 position_ = {0, 1, -1.5};
|
||||
glm::quat orientation_ = {1, 0, 0, 0};
|
||||
glm::vec2 scale = {1, 1};
|
||||
glm::vec2 scale_;
|
||||
|
||||
xr::swapchain& swapchain;
|
||||
|
||||
ImGuiContext * context;
|
||||
ImGuiIO& io;
|
||||
@@ -110,7 +113,7 @@ private:
|
||||
std::optional<ImVec2> ray_plane_intersection(const imgui_context::controller_state& in);
|
||||
|
||||
public:
|
||||
imgui_context(vk::raii::Device& device, uint32_t queue_family_index, vk::raii::Queue& queue, XrSpace world, std::span<controller> controllers, vk::Extent2D size, float resolution, vk::Format format, int frames_in_flight = 3);
|
||||
imgui_context(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);
|
||||
~imgui_context();
|
||||
|
||||
void set_position(glm::vec3 position, glm::quat orientation)
|
||||
@@ -119,7 +122,25 @@ public:
|
||||
orientation_ = orientation;
|
||||
}
|
||||
|
||||
XrPosef pose()
|
||||
XrCompositionLayerQuad composition_layer(XrSwapchain swapchain) const
|
||||
{
|
||||
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(),
|
||||
};
|
||||
}
|
||||
|
||||
XrPosef pose() const
|
||||
{
|
||||
return XrPosef{
|
||||
.orientation = {
|
||||
@@ -156,6 +177,11 @@ public:
|
||||
return orientation_;
|
||||
}
|
||||
|
||||
XrExtent2Df scale() const
|
||||
{
|
||||
return { scale_.x, scale_.y };
|
||||
}
|
||||
|
||||
void new_frame(XrTime display_time);
|
||||
|
||||
void render(vk::Image destination);
|
||||
|
||||
+4
-25
@@ -536,8 +536,7 @@ void scenes::lobby::render()
|
||||
|
||||
input->apply(world_space, framestate.predictedDisplayTime);
|
||||
|
||||
draw_gui(framestate.predictedDisplayTime);
|
||||
|
||||
XrCompositionLayerQuad imgui_layer = draw_gui(framestate.predictedDisplayTime);
|
||||
|
||||
assert(renderer);
|
||||
renderer->start_frame();
|
||||
@@ -545,16 +544,13 @@ void scenes::lobby::render()
|
||||
auto controllers_layer_views = render_layer(views, swapchains_controllers, *renderer, *controllers_scene, {0, 0, 0, 0});
|
||||
renderer->end_frame();
|
||||
|
||||
|
||||
|
||||
// After end_frame because the command buffers are submitted in end_frame
|
||||
for (auto & swapchain: swapchains_lobby)
|
||||
swapchain.release();
|
||||
|
||||
for (auto & swapchain: swapchains_controllers)
|
||||
swapchain.release();
|
||||
|
||||
swapchain_imgui.release();
|
||||
|
||||
XrCompositionLayerProjection lobby_layer{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
|
||||
.layerFlags = 0,
|
||||
@@ -563,21 +559,6 @@ void scenes::lobby::render()
|
||||
.views = lobby_layer_views.data(),
|
||||
};
|
||||
|
||||
XrCompositionLayerQuad imgui_layer{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_QUAD,
|
||||
.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
.space = world_space,
|
||||
.eyeVisibility = XrEyeVisibility::XR_EYE_VISIBILITY_BOTH,
|
||||
.subImage = {
|
||||
.swapchain = swapchain_imgui,
|
||||
.imageRect = {
|
||||
.offset = {0, 0},
|
||||
.extent = swapchain_imgui.extent()},
|
||||
},
|
||||
.pose = imgui_ctx->pose(),
|
||||
.size = {0.75, 0.5}, // TODO
|
||||
};
|
||||
|
||||
XrCompositionLayerProjection controllers_layer{
|
||||
.type = XR_TYPE_COMPOSITION_LAYER_PROJECTION,
|
||||
.layerFlags = XR_COMPOSITION_LAYER_BLEND_TEXTURE_SOURCE_ALPHA_BIT,
|
||||
@@ -619,7 +600,6 @@ void scenes::lobby::on_focused()
|
||||
vk::Extent2D output_size{width, height};
|
||||
|
||||
std::array depth_formats{
|
||||
vk::Format::eD16Unorm,
|
||||
vk::Format::eX8D24UnormPack32,
|
||||
vk::Format::eD32Sfloat,
|
||||
};
|
||||
@@ -650,9 +630,8 @@ void scenes::lobby::on_focused()
|
||||
},
|
||||
};
|
||||
|
||||
vk::Extent2D gui_size(1500, 1000);
|
||||
swapchain_imgui = xr::swapchain(session, device, swapchain_format, gui_size.width, gui_size.height);
|
||||
imgui_ctx.emplace(device, queue_family_index, queue, world_space, imgui_inputs, gui_size, 2000, swapchain_format, swapchain_imgui.images().size());
|
||||
swapchain_imgui = xr::swapchain(session, device, swapchain_format, 1500, 1000);
|
||||
imgui_ctx.emplace(device, queue_family_index, queue, world_space, imgui_inputs, swapchain_imgui, glm::vec2{1.0, 0.6666});
|
||||
}
|
||||
|
||||
void scenes::lobby::on_unfocused()
|
||||
|
||||
+15
-2
@@ -92,15 +92,28 @@ class lobby : public scene_impl<lobby>
|
||||
|
||||
void update_server_list();
|
||||
|
||||
void draw_gui(XrTime predicted_display_time);
|
||||
XrCompositionLayerQuad draw_gui(XrTime predicted_display_time);
|
||||
|
||||
bool move_gui_first_time = true;
|
||||
|
||||
void move_gui(glm::vec3 position, glm::quat orientation, XrTime predicted_display_time);
|
||||
|
||||
enum class tab
|
||||
{
|
||||
server_list,
|
||||
new_server,
|
||||
settings,
|
||||
about,
|
||||
exit
|
||||
};
|
||||
|
||||
tab current_tab = tab::server_list;
|
||||
tab last_current_tab = tab::server_list;
|
||||
|
||||
void gui_connecting();
|
||||
void gui_server_list();
|
||||
void gui_add_server();
|
||||
void gui_settings();
|
||||
void gui_about();
|
||||
void gui_keyboard(ImVec2 size);
|
||||
|
||||
void connect(server_data& data);
|
||||
|
||||
+265
-164
@@ -17,11 +17,14 @@
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "imgui.h"
|
||||
#include "imgui_internal.h"
|
||||
#include "lobby.h"
|
||||
#include "wivrn_packets.h"
|
||||
#include "../common/version.h"
|
||||
#include <utils/strings.h>
|
||||
|
||||
#include "../external/IconsFontAwesome6.h"
|
||||
|
||||
static void CenterTextH(const std::string& text)
|
||||
{
|
||||
@@ -99,13 +102,11 @@ void scenes::lobby::gui_connecting()
|
||||
|
||||
void scenes::lobby::gui_add_server()
|
||||
{
|
||||
|
||||
const ImVec2 button_size(220, 80);
|
||||
|
||||
// CenterNextWindow({1200, 900});
|
||||
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
CenterTextH("Add server");
|
||||
ImGui::PopFont();
|
||||
|
||||
// TODO column widths
|
||||
ImGui::BeginTable("table", 2);
|
||||
@@ -154,7 +155,7 @@ void scenes::lobby::gui_add_server()
|
||||
|
||||
ImGui::SetCursorPosX(top_left.x);
|
||||
if (ImGui::Button("Cancel", button_size))
|
||||
ImGui::CloseCurrentPopup();
|
||||
current_tab = tab::server_list;
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "cancel";
|
||||
|
||||
@@ -162,8 +163,7 @@ void scenes::lobby::gui_add_server()
|
||||
|
||||
if (ImGui::Button("Save", button_size))
|
||||
{
|
||||
ImGui::CloseCurrentPopup();
|
||||
|
||||
current_tab = tab::server_list;
|
||||
server_data data
|
||||
{
|
||||
.manual = true,
|
||||
@@ -195,185 +195,199 @@ void scenes::lobby::gui_server_list()
|
||||
const float list_item_height = 100;
|
||||
auto& style = ImGui::GetStyle();
|
||||
|
||||
ImGui::SetNextWindowPos({0, 0});
|
||||
ImGui::SetNextWindowSize(ImGui::GetMainViewport()->Size);
|
||||
ImGui::Begin("WiVRn", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoMove);
|
||||
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
CenterTextH(std::string("WiVRn ") + xrt::drivers::wivrn::git_version);
|
||||
ImGui::PopFont();
|
||||
|
||||
std::string cookie_to_remove;
|
||||
|
||||
float list_box_height = ImGui::GetWindowContentRegionMax().y - button_size.y - style.WindowPadding.y - ImGui::GetCursorPosY();
|
||||
|
||||
if (ImGui::BeginListBox("##detected servers", ImVec2(-FLT_MIN, list_box_height)))
|
||||
if (sorted_cookies.empty())
|
||||
{
|
||||
if (sorted_cookies.empty())
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.5));
|
||||
CenterTextHV("Start a WiVRn server on your\nlocal network");
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
auto pos = ImGui::GetCursorPos();
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Header, 0);
|
||||
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, 0);
|
||||
ImGui::PushStyleColor(ImGuiCol_HeaderActive, 0);
|
||||
for(const auto& [name, cookie]: sorted_cookies)
|
||||
{
|
||||
server_data& data = servers.at(cookie);
|
||||
bool is_selected = (cookie == selected_item);
|
||||
|
||||
ImGui::SetCursorPos(pos);
|
||||
|
||||
ImGui::SetNextItemAllowOverlap();
|
||||
|
||||
// TODO custom widget
|
||||
if (ImGui::Selectable(("##" + cookie).c_str(), is_selected, ImGuiSelectableFlags_None, ImVec2(0, list_item_height)))
|
||||
selected_item = cookie;
|
||||
|
||||
ImGui::SetCursorPos(ImVec2(pos.x, pos.y));
|
||||
ImGui::Text("%s", name.c_str());
|
||||
|
||||
if (!data.manual)
|
||||
{
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 0.5));
|
||||
CenterTextHV("Start a WiVRn server on your\nlocal network");
|
||||
ImGui::SetCursorPos(ImVec2(pos.x, pos.y + 50));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0,1,0,1));
|
||||
if (ImGui::Checkbox(("Autoconnect##" + cookie).c_str(), &data.autoconnect))
|
||||
save_config();
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "autoconnect " + cookie;
|
||||
ImGui::PopStyleColor();
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
auto pos = ImGui::GetCursorPos();
|
||||
// TODO
|
||||
// if (ImGui::IsItemHovered())
|
||||
// {
|
||||
// ImGui::SetTooltip("Tooltip");
|
||||
// }
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_Header, 0);
|
||||
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, 0);
|
||||
ImGui::PushStyleColor(ImGuiCol_HeaderActive, 0);
|
||||
for(const auto& [name, cookie]: sorted_cookies)
|
||||
ImVec2 button_position(ImGui::GetWindowContentRegionMax().x + style.FramePadding.x, pos.y + (list_item_height - button_size.y) / 2);
|
||||
|
||||
button_position.x -= button_size.x + style.WindowPadding.x;
|
||||
ImGui::SetCursorPos(button_position);
|
||||
|
||||
bool enable_connect_button = data.visible || data.manual;
|
||||
ImGui::BeginDisabled(!enable_connect_button);
|
||||
if (enable_connect_button)
|
||||
{
|
||||
server_data& data = servers.at(cookie);
|
||||
bool is_selected = (cookie == selected_item);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.8f, 0.3f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.8f, 0.3f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 1.0f, 0.2f, 1.00f));
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.4f, 0.3f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.4f, 0.3f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.5f, 0.2f, 1.00f));
|
||||
}
|
||||
if (ImGui::Button(("Connect##" + cookie).c_str(), button_size))
|
||||
{
|
||||
connect(data);
|
||||
ImGui::OpenPopup("connecting");
|
||||
}
|
||||
|
||||
ImGui::SetCursorPos(pos);
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "connect " + cookie;
|
||||
|
||||
ImGui::SetNextItemAllowOverlap();
|
||||
ImGui::PopStyleColor(3);
|
||||
ImGui::EndDisabled();
|
||||
|
||||
// TODO custom widget
|
||||
if (ImGui::Selectable(("##" + cookie).c_str(), is_selected, ImGuiSelectableFlags_None, ImVec2(0, list_item_height)))
|
||||
selected_item = cookie;
|
||||
|
||||
ImGui::SetCursorPos(ImVec2(pos.x, pos.y));
|
||||
ImGui::Text("%s", name.c_str());
|
||||
|
||||
if (!data.manual)
|
||||
{
|
||||
ImGui::SetCursorPos(ImVec2(pos.x, pos.y + 50));
|
||||
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0,1,0,1));
|
||||
if (ImGui::Checkbox(("Autoconnect##" + cookie).c_str(), &data.autoconnect))
|
||||
save_config();
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "autoconnect " + cookie;
|
||||
ImGui::PopStyleColor();
|
||||
}
|
||||
|
||||
// TODO
|
||||
// if (ImGui::IsItemHovered())
|
||||
// {
|
||||
// ImGui::SetTooltip("Tooltip");
|
||||
// }
|
||||
|
||||
ImVec2 button_position(ImGui::GetWindowContentRegionMax().x + style.FramePadding.x, pos.y + (list_item_height - button_size.y) / 2);
|
||||
|
||||
button_position.x -= button_size.x + style.WindowPadding.x;
|
||||
button_position.x -= button_size.x + style.WindowPadding.x;
|
||||
if (data.manual)
|
||||
{
|
||||
ImGui::SetCursorPos(button_position);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
|
||||
bool enable_connect_button = data.visible || data.manual;
|
||||
ImGui::BeginDisabled(!enable_connect_button);
|
||||
if (enable_connect_button)
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.8f, 0.3f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.8f, 0.3f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 1.0f, 0.2f, 1.00f));
|
||||
}
|
||||
else
|
||||
{
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.4f, 0.3f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.4f, 0.3f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.5f, 0.2f, 1.00f));
|
||||
}
|
||||
if (ImGui::Button(("Connect##" + cookie).c_str(), button_size))
|
||||
{
|
||||
connect(data);
|
||||
ImGui::OpenPopup("connecting");
|
||||
}
|
||||
if (ImGui::Button(("Remove##" + cookie).c_str(), button_size))
|
||||
cookie_to_remove = cookie;
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "connect " + cookie;
|
||||
hovered_item = "remove " + cookie;
|
||||
|
||||
ImGui::PopStyleColor(3);
|
||||
ImGui::EndDisabled();
|
||||
|
||||
button_position.x -= button_size.x + style.WindowPadding.x;
|
||||
if (data.manual)
|
||||
{
|
||||
ImGui::SetCursorPos(button_position);
|
||||
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.2f, 0.2f, 0.40f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.8f, 0.2f, 0.2f, 1.00f));
|
||||
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 0.1f, 0.1f, 1.00f));
|
||||
|
||||
if (ImGui::Button(("Remove##" + cookie).c_str(), button_size))
|
||||
cookie_to_remove = cookie;
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "remove " + cookie;
|
||||
|
||||
ImGui::PopStyleColor(3);
|
||||
}
|
||||
|
||||
pos.y += 120;
|
||||
}
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
if (cookie_to_remove != "")
|
||||
{
|
||||
servers.erase(cookie_to_remove);
|
||||
save_config();
|
||||
}
|
||||
|
||||
ImGui::EndListBox();
|
||||
pos.y += 120;
|
||||
}
|
||||
ImGui::PopStyleColor(3);
|
||||
|
||||
auto top_left = ImGui::GetWindowContentRegionMin();
|
||||
auto bottom_right = ImGui::GetWindowContentRegionMax();
|
||||
|
||||
#ifndef NDEBUG
|
||||
ImGui::SetCursorPos(ImVec2(top_left.x, bottom_right.y - button_size.y));
|
||||
if (ImGui::Button("Add server", button_size))
|
||||
if (cookie_to_remove != "")
|
||||
{
|
||||
ImGui::OpenPopup("add_server");
|
||||
strcpy(add_server_window_prettyname, "");
|
||||
strcpy(add_server_window_hostname, "");
|
||||
add_server_window_port = xrt::drivers::wivrn::default_port;
|
||||
servers.erase(cookie_to_remove);
|
||||
save_config();
|
||||
}
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
{
|
||||
hovered_item = "add";
|
||||
ImGui::SetTooltip("TODO");
|
||||
}
|
||||
#endif
|
||||
|
||||
ImGui::SetCursorPos(ImVec2(bottom_right.x - button_size.x, bottom_right.y - button_size.y));
|
||||
if (ImGui::Button("Exit", button_size))
|
||||
application::pop_scene();
|
||||
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "exit";
|
||||
|
||||
if (ImGui::BeginPopupModal("add_server", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoMove))
|
||||
{
|
||||
gui_add_server();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
// Check if an automatic connection has started
|
||||
if ((async_session.valid() || next_scene) && !ImGui::IsPopupOpen("connecting"))
|
||||
ImGui::OpenPopup("connecting");
|
||||
|
||||
if (ImGui::BeginPopupModal("connecting", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoMove))
|
||||
{
|
||||
gui_connecting();
|
||||
ImGui::EndPopup();
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void scenes::lobby::draw_gui(XrTime predicted_display_time)
|
||||
void scenes::lobby::gui_about()
|
||||
{
|
||||
ImGui::PushFont(imgui_ctx->large_font);
|
||||
ImGui::TextWrapped("WiVRn %s", xrt::drivers::wivrn::git_version);
|
||||
ImGui::PopFont();
|
||||
}
|
||||
|
||||
static bool RadioButtonWithoutCheckBox(const char * label, bool active, ImVec2 size_arg)
|
||||
{
|
||||
ImGuiWindow * window = ImGui::GetCurrentWindow();
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
ImGuiContext & g = *GImGui;
|
||||
const ImGuiStyle & style = g.Style;
|
||||
const ImGuiID id = window->GetID(label);
|
||||
const ImVec2 label_size = ImGui::CalcTextSize(label, NULL, true);
|
||||
|
||||
const ImVec2 pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 size = ImGui::CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
|
||||
|
||||
const ImRect bb(pos, pos + size);
|
||||
ImGui::ItemSize(bb, style.FramePadding.y);
|
||||
if (!ImGui::ItemAdd(bb, id))
|
||||
return false;
|
||||
|
||||
bool hovered, held;
|
||||
bool pressed = ImGui::ButtonBehavior(bb, id, &hovered, &held);
|
||||
|
||||
ImGuiCol_ col;
|
||||
if ((held && hovered) || active)
|
||||
col = ImGuiCol_ButtonActive;
|
||||
else if (hovered)
|
||||
col = ImGuiCol_ButtonHovered;
|
||||
else
|
||||
col = ImGuiCol_Button;
|
||||
|
||||
ImGui::RenderNavHighlight(bb, id);
|
||||
ImGui::RenderFrame(bb.Min, bb.Max, ImGui::GetColorU32(col), true, style.FrameRounding);
|
||||
|
||||
ImVec2 TextAlign{0, 0.5f};
|
||||
ImGui::RenderTextClipped(bb.Min + style.FramePadding, bb.Max - style.FramePadding, label, NULL, &label_size, TextAlign, &bb);
|
||||
|
||||
IMGUI_TEST_ENGINE_ITEM_INFO(id, label, g.LastItemData.StatusFlags);
|
||||
return pressed;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static bool RadioButtonWithoutCheckBox(const char * label, T * v, T v_button, ImVec2 size_arg)
|
||||
{
|
||||
const bool pressed = RadioButtonWithoutCheckBox(label, *v == v_button, size_arg);
|
||||
if (pressed)
|
||||
*v = v_button;
|
||||
return pressed;
|
||||
}
|
||||
|
||||
static void ScrollWhenDraggingOnVoid(ImVec2 delta)
|
||||
{
|
||||
// https://github.com/ocornut/imgui/issues/3379#issuecomment-1678718752
|
||||
ImGuiContext& g = *ImGui::GetCurrentContext();
|
||||
ImGuiWindow* window = g.CurrentWindow;
|
||||
bool hovered = false;
|
||||
bool held = false;
|
||||
ImGuiID id = window->GetID("##scrolldraggingoverlay");
|
||||
ImGui::KeepAliveID(id);
|
||||
if (g.HoveredId == 0) // If nothing hovered so far in the frame (not same as IsAnyItemHovered()!)
|
||||
ImGui::ButtonBehavior(window->Rect(), id, &hovered, &held, ImGuiButtonFlags_MouseButtonLeft);
|
||||
if (held && delta.x != 0.0f)
|
||||
ImGui::SetScrollX(window, window->Scroll.x + delta.x);
|
||||
if (held && delta.y != 0.0f)
|
||||
ImGui::SetScrollY(window, window->Scroll.y + delta.y);
|
||||
}
|
||||
|
||||
XrCompositionLayerQuad scenes::lobby::draw_gui(XrTime predicted_display_time)
|
||||
{
|
||||
imgui_ctx->new_frame(predicted_display_time);
|
||||
ImGuiIO & io = ImGui::GetIO();
|
||||
ImGuiStyle & style = ImGui::GetStyle();
|
||||
|
||||
// const float MinTabWidth = 60;
|
||||
const float MinTabWidth = 300;
|
||||
const float MaxTabWidth = 300;
|
||||
|
||||
int image_index = swapchain_imgui.acquire();
|
||||
swapchain_imgui.wait();
|
||||
|
||||
@@ -384,13 +398,100 @@ void scenes::lobby::draw_gui(XrTime predicted_display_time)
|
||||
move_gui(head_position->first, head_position->second, predicted_display_time);
|
||||
}
|
||||
|
||||
imgui_ctx->new_frame(predicted_display_time);
|
||||
// ImGui::ShowDemoWindow();
|
||||
|
||||
auto last_hovered = hovered_item;
|
||||
hovered_item = "";
|
||||
|
||||
gui_server_list();
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, {0, 0});
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 30);
|
||||
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::Begin("WiVRn", nullptr,
|
||||
ImGuiWindowFlags_NoTitleBar |
|
||||
ImGuiWindowFlags_NoResize |
|
||||
ImGuiWindowFlags_NoMove);
|
||||
|
||||
ImGui::SetCursorPos({MinTabWidth + 20, 0});
|
||||
|
||||
{
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 10);
|
||||
ImGui::BeginChild("Main", ImVec2(ImGui::GetWindowSize().x - ImGui::GetCursorPosX(), 0));
|
||||
ImGui::SetCursorPosY(20);
|
||||
|
||||
switch(current_tab)
|
||||
{
|
||||
case tab::server_list:
|
||||
gui_server_list();
|
||||
break;
|
||||
|
||||
case tab::new_server:
|
||||
break;
|
||||
|
||||
case tab::settings:
|
||||
break;
|
||||
|
||||
case tab::about:
|
||||
gui_about();
|
||||
break;
|
||||
|
||||
case tab::exit:
|
||||
application::pop_scene();
|
||||
break;
|
||||
}
|
||||
|
||||
if (current_tab != last_current_tab)
|
||||
{
|
||||
last_current_tab = current_tab;
|
||||
ImGui::SetScrollY(0);
|
||||
}
|
||||
|
||||
ImGui::Dummy(ImVec2(0,20));
|
||||
|
||||
ImVec2 mouse_delta = ImGui::GetIO().MouseDelta;
|
||||
ScrollWhenDraggingOnVoid(ImVec2(0.0f, -mouse_delta.y));
|
||||
ImGui::EndChild();
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_FrameRounding
|
||||
}
|
||||
|
||||
ImGui::PushStyleColor(ImGuiCol_ChildBg, IM_COL32(0, 0, 0, 255));
|
||||
ImGui::SetCursorPos(style.WindowPadding);
|
||||
|
||||
{
|
||||
static float TabWidth = MinTabWidth;
|
||||
ImGui::BeginChild("Tabs", {TabWidth, ImGui::GetContentRegionMax().y - ImGui::GetWindowContentRegionMin().y});
|
||||
|
||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10,10));
|
||||
RadioButtonWithoutCheckBox(ICON_FA_COMPUTER " Server list", ¤t_tab, tab::server_list, {TabWidth, 0});
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "Server list";
|
||||
|
||||
ImGui::SetCursorPosY(ImGui::GetContentRegionMax().y - 2*ImGui::GetCurrentContext()->FontSize - 4*style.FramePadding.y - style.ItemSpacing.y - style.WindowPadding.y);
|
||||
RadioButtonWithoutCheckBox(ICON_FA_CIRCLE_INFO " About", ¤t_tab, tab::about, {TabWidth, 0});
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "about";
|
||||
RadioButtonWithoutCheckBox(ICON_FA_DOOR_OPEN " Exit", ¤t_tab, tab::exit, {TabWidth, 0});
|
||||
if (ImGui::IsItemHovered())
|
||||
hovered_item = "exit";
|
||||
|
||||
if (!ImGui::IsMouseDown(ImGuiMouseButton_Left))
|
||||
{
|
||||
if (ImGui::IsWindowHovered(ImGuiHoveredFlags_ChildWindows))
|
||||
TabWidth = std::min<float>(TabWidth + 600 * io.DeltaTime, MaxTabWidth);
|
||||
else
|
||||
TabWidth = std::max<float>(TabWidth - 600 * io.DeltaTime, MinTabWidth);
|
||||
}
|
||||
|
||||
ImGui::PopStyleVar(); // ImGuiStyleVar_FramePadding
|
||||
ImGui::EndChild();
|
||||
}
|
||||
ImGui::PopStyleColor(); // ImGuiCol_ChildBg
|
||||
ImGui::End();
|
||||
ImGui::PopStyleColor(); // ImGuiCol_WindowBg
|
||||
ImGui::PopStyleVar(2); // ImGuiStyleVar_WindowPadding, ImGuiStyleVar_ScrollbarSize
|
||||
|
||||
if (hovered_item != last_hovered && hovered_item != "")
|
||||
{
|
||||
@@ -399,9 +500,9 @@ void scenes::lobby::draw_gui(XrTime predicted_display_time)
|
||||
application::haptic_start(haptic_output[controller], XR_NULL_PATH, 10'000'000, 1000, 1);
|
||||
}
|
||||
|
||||
// Render the GUI to the imgui material
|
||||
// imgui_material->base_color_texture->image_view = imgui_ctx->render();
|
||||
// imgui_material->ds_dirty = true;
|
||||
|
||||
imgui_ctx->render(swapchain_imgui.images()[image_index].image);
|
||||
swapchain_imgui.release();
|
||||
|
||||
return imgui_ctx->composition_layer(swapchain_imgui);
|
||||
}
|
||||
|
||||
+49
-27
@@ -19,9 +19,15 @@
|
||||
|
||||
#version 450
|
||||
|
||||
#define NB_TEXCOORDS 2
|
||||
layout (constant_id = 0) const int nb_texcoords = 2;
|
||||
layout (constant_id = 1) const int nb_joints = 1;
|
||||
layout (constant_id = 2) const int nb_clipping = 1;
|
||||
layout (constant_id = 3) const bool dithering = true;
|
||||
layout (constant_id = 4) const bool alpha_cutout = false;
|
||||
|
||||
#define DITHERING
|
||||
const float fog_min_dist = 20.0;
|
||||
const float fog_max_dist = 35.0;
|
||||
const vec4 fog_color = vec4(0.0, 0.25, 0.5, 1.0);
|
||||
|
||||
layout(set = 0, binding = 0) uniform scene_ubo
|
||||
{
|
||||
@@ -30,6 +36,7 @@ layout(set = 0, binding = 0) uniform scene_ubo
|
||||
vec4 light_position;
|
||||
vec4 ambient_color;
|
||||
vec4 light_color;
|
||||
// vec4 clipping_plane[8];
|
||||
} scene;
|
||||
|
||||
layout(set = 0, binding = 1) uniform mesh_ubo
|
||||
@@ -67,10 +74,10 @@ layout(set = 1, binding = 5) uniform material_ubo
|
||||
layout(location = 0) in vec3 in_position;
|
||||
layout(location = 1) in vec3 in_normal;
|
||||
layout(location = 2) in vec3 in_tangent;
|
||||
layout(location = 3) in vec2 in_texcoord[NB_TEXCOORDS];
|
||||
layout(location = 3+NB_TEXCOORDS) in vec4 in_color;
|
||||
layout(location = 4+NB_TEXCOORDS) in vec4 in_joints;
|
||||
layout(location = 5+NB_TEXCOORDS) in vec4 in_weights;
|
||||
layout(location = 3) in vec2 in_texcoord[2];
|
||||
layout(location = 5) in vec4 in_color;
|
||||
layout(location = 6) in vec4 in_joints[nb_joints];
|
||||
layout(location = 7) in vec4 in_weights[nb_joints];
|
||||
#endif
|
||||
|
||||
// Vertex-to-fragment
|
||||
@@ -81,9 +88,9 @@ layout(location = 5+NB_TEXCOORDS) in vec4 in_weights;
|
||||
#endif
|
||||
|
||||
layout(location = 0) VERT_TO_FRAG vec3 normal;
|
||||
layout(location = 1) VERT_TO_FRAG vec2 texcoord[NB_TEXCOORDS];
|
||||
layout(location = 1+NB_TEXCOORDS) VERT_TO_FRAG vec3 frag_pos;
|
||||
layout(location = 2+NB_TEXCOORDS) VERT_TO_FRAG vec4 light_pos;
|
||||
layout(location = 1) VERT_TO_FRAG vec4 frag_pos;
|
||||
layout(location = 2) VERT_TO_FRAG vec4 light_pos;
|
||||
layout(location = 3) VERT_TO_FRAG vec2 texcoord[nb_texcoords];
|
||||
|
||||
// Fragment output
|
||||
#ifdef FRAG_SHADER
|
||||
@@ -92,35 +99,43 @@ layout(location = 0) out vec4 out_color;
|
||||
|
||||
// Shader code
|
||||
#ifdef VERT_SHADER
|
||||
|
||||
// out float gl_ClipDistance[8];
|
||||
// out float gl_CullDistance[8];
|
||||
|
||||
void main()
|
||||
{
|
||||
normal = vec3(mesh.modelview * vec4(in_normal, 0.0));
|
||||
|
||||
for(int i = 0; i < NB_TEXCOORDS; i++)
|
||||
for(int i = 0; i < nb_texcoords; i++)
|
||||
texcoord[i] = in_texcoord[i];
|
||||
|
||||
gl_Position = mesh.modelviewproj * vec4(in_position, 1.0);
|
||||
frag_pos = vec3(mesh.modelview * vec4(in_position, 1.0));
|
||||
frag_pos = mesh.modelview * vec4(in_position, 1.0);
|
||||
light_pos = scene.view * scene.light_position;
|
||||
|
||||
// for(int i = 0; i < nb_clipping; i++)
|
||||
// {
|
||||
// gl_ClipDistance[i] = dot(scene.clipping_plane[i], frag_pos);
|
||||
// gl_CullDistance[i] = dot(scene.clipping_plane[i], frag_pos);
|
||||
// }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef FRAG_SHADER
|
||||
|
||||
#ifdef DITHERING
|
||||
const float dither_pattern[4][4] = {
|
||||
{ 0.0f, 0.5f, 0.125f, 0.625f},
|
||||
{ 0.75f, 0.22f, 0.875f, 0.375f},
|
||||
{ 0.1875f, 0.6875f, 0.0625f, 0.5625},
|
||||
{ 0.9375f, 0.4375f, 0.8125f, 0.3125}
|
||||
};
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
vec3 light_dir = normalize(light_pos.xyz - frag_pos * light_pos.w);
|
||||
vec3 view_dir = normalize(frag_pos);
|
||||
vec3 light_dir = normalize(light_pos.xyz - frag_pos.xyz * light_pos.w);
|
||||
vec3 view_dir = normalize(frag_pos.xyz);
|
||||
vec3 normal_unit = normalize(normal);
|
||||
vec3 reflect_dir = reflect(-light_dir, normal_unit);
|
||||
|
||||
@@ -137,21 +152,28 @@ void main()
|
||||
|
||||
vec3 light = ambient + diffuse /*+ specular*/;
|
||||
|
||||
vec4 c = texture(base_color, texcoord[0]);
|
||||
vec4 c = texture(base_color, fract(texcoord[0])) * vec4(light, 1.0);
|
||||
|
||||
if (c.a <= 0.5)
|
||||
discard;
|
||||
float fog = clamp((length(frag_pos) - fog_min_dist) / (fog_max_dist - fog_min_dist), 0.0, 1.0);
|
||||
|
||||
#ifdef DITHERING
|
||||
ivec2 tmp = ivec2(gl_FragCoord.xy) % 4;
|
||||
float dither_thd = dither_pattern[tmp.x][tmp.y];
|
||||
c = mix(c, fog_color, fog);
|
||||
|
||||
vec4 color = c * vec4(light, 1.0) * 255.0f;
|
||||
// vec4 c = vec4(1,1,1,1);
|
||||
|
||||
bvec4 tmp2 = greaterThan(fract(color), vec4(dither_thd, dither_thd, dither_thd, dither_thd));
|
||||
out_color = (ceil(color) + vec4(tmp2)) / 255.0;
|
||||
#else
|
||||
out_color = c * vec4(light, 1.0);
|
||||
#endif
|
||||
// if (alpha_cutout && c.a <= 0.5)
|
||||
// discard;
|
||||
|
||||
if (dithering)
|
||||
{
|
||||
ivec2 tmp = ivec2(gl_FragCoord.xy) % 4;
|
||||
float dither_thd = dither_pattern[tmp.x][tmp.y];
|
||||
|
||||
vec4 color = c * 255.0f;
|
||||
|
||||
bvec4 tmp2 = greaterThan(fract(color), vec4(dither_thd, dither_thd, dither_thd, dither_thd));
|
||||
out_color = (ceil(color) + vec4(tmp2)) / 255.0;
|
||||
}
|
||||
else
|
||||
out_color = c;
|
||||
}
|
||||
#endif
|
||||
|
||||
Vendored
+1401
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user