From d6155b3abfe70b1cf06d570f2ce7d55df3140368 Mon Sep 17 00:00:00 2001 From: SimoneN64 Date: Wed, 18 Sep 2024 21:03:36 +0200 Subject: [PATCH] It works! --- external/imgui/CMakeLists.txt | 3 +- external/imgui/backends/imgui_impl_sdl3.cpp | 4 +-- external/parallel-rdp/ParallelRDPWrapper.cpp | 36 +++++++++++++++++--- src/frontend/CMakeLists.txt | 2 +- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/external/imgui/CMakeLists.txt b/external/imgui/CMakeLists.txt index c837818b..2107e979 100644 --- a/external/imgui/CMakeLists.txt +++ b/external/imgui/CMakeLists.txt @@ -6,4 +6,5 @@ file(GLOB HEADERS *.h) list(APPEND SOURCES backends/imgui_impl_sdl3.cpp backends/imgui_impl_vulkan.cpp) add_library(imgui ${SOURCES} ${HEADERS}) -target_include_directories(imgui PRIVATE . backends ../SDL/include) \ No newline at end of file +target_include_directories(imgui PRIVATE . backends ../SDL/include) +target_compile_definitions(imgui PRIVATE IMGUI_IMPL_VULKAN_USE_VOLK) \ No newline at end of file diff --git a/external/imgui/backends/imgui_impl_sdl3.cpp b/external/imgui/backends/imgui_impl_sdl3.cpp index 5135b75a..1bc810ff 100644 --- a/external/imgui/backends/imgui_impl_sdl3.cpp +++ b/external/imgui/backends/imgui_impl_sdl3.cpp @@ -626,7 +626,7 @@ static void ImGui_ImplSDL3_UpdateMouseData() // We forward mouse input when hovered or captured (via SDL_EVENT_MOUSE_MOTION) or when focused (below) #if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE // SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger other operations outside - SDL_CaptureMouse((bd->MouseButtonsDown != 0) ? SDL_TRUE : SDL_FALSE); + SDL_CaptureMouse(bd->MouseButtonsDown != 0); SDL_Window* focused_window = SDL_GetKeyboardFocus(); const bool is_app_focused = (focused_window && (bd->Window == focused_window || ImGui_ImplSDL3_GetViewportForWindowID(SDL_GetWindowID(focused_window)) != NULL)); #else @@ -1101,7 +1101,7 @@ static int ImGui_ImplSDL3_CreateVkSurface(ImGuiViewport* viewport, ImU64 vk_inst { ImGui_ImplSDL3_ViewportData* vd = (ImGui_ImplSDL3_ViewportData*)viewport->PlatformUserData; (void)vk_allocator; - SDL_bool ret = SDL_Vulkan_CreateSurface(vd->Window, (VkInstance)vk_instance, (VkAllocationCallbacks*)vk_allocator, (VkSurfaceKHR*)out_vk_surface); + bool ret = SDL_Vulkan_CreateSurface(vd->Window, (VkInstance)vk_instance, (VkAllocationCallbacks*)vk_allocator, (VkSurfaceKHR*)out_vk_surface); return ret ? 0 : 1; // ret ? VK_SUCCESS : VK_NOT_READY } diff --git a/external/parallel-rdp/ParallelRDPWrapper.cpp b/external/parallel-rdp/ParallelRDPWrapper.cpp index 6244ed27..71cb9131 100644 --- a/external/parallel-rdp/ParallelRDPWrapper.cpp +++ b/external/parallel-rdp/ParallelRDPWrapper.cpp @@ -56,6 +56,11 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr &instan #endif SDLWindow = SDL_CreateWindowWithProperties(props); + auto instance = wsi->get_context().get_instance(); + + volkInitialize(); + volkLoadInstance(instance); + IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImGuiIO &io = ImGui::GetIO(); @@ -64,10 +69,17 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr &instan io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; ImGui::StyleColorsDark(); + + ImGui_ImplVulkan_LoadFunctions( + [](const char *function_name, void *instance) { + return vkGetInstanceProcAddr(static_cast(instance), function_name); + }, + instance); + ImGui_ImplSDL3_InitForVulkan(SDLWindow); ImGui_ImplVulkan_InitInfo init_info = {}; - init_info.Instance = wsi->get_context().get_instance(); + init_info.Instance = instance; init_info.PhysicalDevice = wsi->get_device().get_physical_device(); init_info.Device = wsi->get_device().get_device(); init_info.QueueFamily = wsi->get_context().get_queue_info().family_indices[QUEUE_INDEX_GRAPHICS]; @@ -101,8 +113,7 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr &instan ImGui_ImplVulkan_Init(&init_info); } -void ParallelRDP::Init(const std::shared_ptr &factory, - const std::shared_ptr &wsiPlatform, +void ParallelRDP::Init(const std::shared_ptr &factory, const std::shared_ptr &wsiPlatform, const std::shared_ptr &newWindowInfo, const u8 *rdram, void *winPtr) { LoadWSIPlatform(factory, wsiPlatform, newWindowInfo, winPtr); @@ -151,7 +162,7 @@ void ParallelRDP::Init(const std::shared_ptr &factory, void ParallelRDP::DrawFullscreenTexturedQuad(Util::IntrusivePtr image, Util::IntrusivePtr cmd) const { - cmd->set_texture(0, 0, image->get_view(), Vulkan::StockSampler::LinearClamp); + cmd->set_texture(0, 0, image->get_view(), StockSampler::LinearClamp); cmd->set_program(fullscreen_quad_program); cmd->set_quad_state(); auto data = static_cast(cmd->allocate_vertex_data(0, 6 * sizeof(float), 2 * sizeof(float))); @@ -188,7 +199,7 @@ void ParallelRDP::UpdateScreen(Util::IntrusivePtr image) const { wsi->begin_frame(); if (!image) { - auto info = Vulkan::ImageCreateInfo::immutable_2d_image(800, 600, VK_FORMAT_R8G8B8A8_UNORM); + auto info = ImageCreateInfo::immutable_2d_image(800, 600, VK_FORMAT_R8G8B8A8_UNORM); info.usage = VK_IMAGE_USAGE_SAMPLED_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT; info.misc = IMAGE_MISC_MUTABLE_SRGB_BIT; info.initial_layout = VK_IMAGE_LAYOUT_UNDEFINED; @@ -210,9 +221,24 @@ void ParallelRDP::UpdateScreen(Util::IntrusivePtr image) const { cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly)); DrawFullscreenTexturedQuad(image, cmd); + + SDL_Event event; + while (SDL_PollEvent(&event)) { + ImGui_ImplSDL3_ProcessEvent(&event); + } + + ImGui_ImplVulkan_NewFrame(); + ImGui_ImplSDL3_NewFrame(); + ImGui::NewFrame(); + + ImGui::ShowDemoWindow(); + ImGui::Render(); ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->get_command_buffer()); + ImGui::UpdatePlatformWindows(); + ImGui::RenderPlatformWindowsDefault(); + cmd->end_render_pass(); wsi->get_device().submit(cmd); wsi->end_frame(); diff --git a/src/frontend/CMakeLists.txt b/src/frontend/CMakeLists.txt index b0c35688..58a3bb67 100644 --- a/src/frontend/CMakeLists.txt +++ b/src/frontend/CMakeLists.txt @@ -96,7 +96,7 @@ if (${CMAKE_BUILD_TYPE} MATCHES Debug) #target_link_options(kaizen-qt PUBLIC -fsanitize=address -fsanitize=undefined) endif () -target_link_libraries(kaizen-qt PUBLIC SDL3::SDL3 SDL3::SDL3-static Qt6::Core Qt6::Gui Qt6::Widgets discord-rpc fmt mio nlohmann_json imgui parallel-rdp backend) +target_link_libraries(kaizen-qt PUBLIC SDL3::SDL3 SDL3::SDL3-static Qt6::Core Qt6::Gui Qt6::Widgets discord-rpc fmt mio nlohmann_json parallel-rdp imgui backend) target_compile_definitions(kaizen-qt PUBLIC SDL_MAIN_HANDLED) file(COPY ../../resources/ DESTINATION ${PROJECT_BINARY_DIR}/resources/)