diff --git a/external/parallel-rdp/ParallelRDPWrapper.cpp b/external/parallel-rdp/ParallelRDPWrapper.cpp index 13844a6a..3158779d 100644 --- a/external/parallel-rdp/ParallelRDPWrapper.cpp +++ b/external/parallel-rdp/ParallelRDPWrapper.cpp @@ -33,7 +33,7 @@ static void check_vk_result(VkResult err) { void ParallelRDP::LoadWSIPlatform(const std::shared_ptr &instanceFactory, const std::shared_ptr &wsi_platform, - const std::shared_ptr &newWindowInfo, void *winPtr) { + const std::shared_ptr &newWindowInfo) { wsi = std::make_shared(); wsi->set_backbuffer_srgb(false); wsi->set_platform(wsi_platform.get()); @@ -45,39 +45,17 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr &instan windowInfo = newWindowInfo; - auto props = SDL_CreateProperties(); -#ifdef SDL_PLATFORM_LINUX - SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER, winPtr); - SDL_SetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, static_castwinPtr); -#elif SDL_PLATFORM_WINDOWS - SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER, winPtr); -#else - SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_COCOA_WINDOW_POINTER, winPtr); -#endif - SDLWindow = SDL_CreateWindowWithProperties(props); - auto instance = wsi->get_context().get_instance(); volkInitialize(); volkLoadInstance(instance); - IMGUI_CHECKVERSION(); - ImGui::CreateContext(); - ImGuiIO &io = ImGui::GetIO(); - (void)io; - io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; - 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 = instance; init_info.PhysicalDevice = wsi->get_device().get_physical_device(); @@ -114,8 +92,8 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr &instan } 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); + const std::shared_ptr &newWindowInfo, const u8 *rdram) { + LoadWSIPlatform(factory, wsiPlatform, newWindowInfo); ResourceLayout vertLayout; ResourceLayout fragLayout; @@ -222,17 +200,10 @@ 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()); diff --git a/external/parallel-rdp/ParallelRDPWrapper.hpp b/external/parallel-rdp/ParallelRDPWrapper.hpp index c667b244..bed15a66 100644 --- a/external/parallel-rdp/ParallelRDPWrapper.hpp +++ b/external/parallel-rdp/ParallelRDPWrapper.hpp @@ -17,7 +17,7 @@ public: }; void Init(const std::shared_ptr &, const std::shared_ptr &, - const std::shared_ptr &, const u8 *, void *); + const std::shared_ptr &, const u8 *); ParallelRDP() = default; void UpdateScreen(const n64::VI &) const; @@ -28,12 +28,11 @@ public: private: void LoadWSIPlatform(const std::shared_ptr &, const std::shared_ptr &, - const std::shared_ptr &, void *); + const std::shared_ptr &); void DrawFullscreenTexturedQuad(Util::IntrusivePtr, Util::IntrusivePtr) const; void UpdateScreen(Util::IntrusivePtr) const; std::shared_ptr wsi; std::shared_ptr command_processor; std::shared_ptr windowInfo; - SDL_Window *SDLWindow; }; diff --git a/src/frontend/EmuThread.cpp b/src/frontend/EmuThread.cpp index 1524c5b3..7b0ee1fa 100644 --- a/src/frontend/EmuThread.cpp +++ b/src/frontend/EmuThread.cpp @@ -7,8 +7,7 @@ EmuThread::EmuThread(const std::shared_ptr &instance_, instance(instance_), wsiPlatform(wsiPlatform_), windowInfo(windowInfo_), core(parallel), settings(settings) {} [[noreturn]] void EmuThread::run() noexcept { - parallel.Init(instance, wsiPlatform, windowInfo, core.cpu->GetMem().GetRDRAMPtr(), - reinterpret_cast(wsiPlatform->get_native_window())); + parallel.Init(instance, wsiPlatform, windowInfo, core.cpu->GetMem().GetRDRAMPtr()); SDL_InitSubSystem(SDL_INIT_GAMEPAD); bool controllerConnected = false; diff --git a/src/frontend/RenderWidget.cpp b/src/frontend/RenderWidget.cpp index f6321236..8a129a7b 100644 --- a/src/frontend/RenderWidget.cpp +++ b/src/frontend/RenderWidget.cpp @@ -1,5 +1,8 @@ #include #include +#include +#include +#include RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) { setAttribute(Qt::WA_NativeWindow); @@ -24,4 +27,38 @@ RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) { wsiPlatform = std::make_unique(windowHandle()); windowInfo = std::make_unique(windowHandle()); + + auto winPtr = reinterpret_cast(winId()); + auto props = SDL_CreateProperties(); +#ifdef SDL_PLATFORM_LINUX + SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WAYLAND_WL_SURFACE_POINTER, winPtr); + SDL_SetNumberProperty(props, SDL_PROP_WINDOW_X11_WINDOW_NUMBER, static_cast winPtr); +#elif SDL_PLATFORM_WINDOWS + SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_WIN32_HWND_POINTER, winPtr); +#else + SDL_SetPointerProperty(props, SDL_PROP_WINDOW_CREATE_COCOA_WINDOW_POINTER, winPtr); +#endif + sdlWindow = SDL_CreateWindowWithProperties(props); + + IMGUI_CHECKVERSION(); + ImGui::CreateContext(); + ImGuiIO &io = ImGui::GetIO(); + (void)io; + io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; + io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; + + ImGui::StyleColorsDark(); + + ImGui_ImplSDL3_InitForVulkan(sdlWindow); + + connect(&timer, &QTimer::timeout, this, &RenderWidget::UpdateEvents); + timer.setInterval(16); + timer.start(); +} + +void RenderWidget::UpdateEvents() { + SDL_Event event; + while (SDL_PollEvent(&event)) { + ImGui_ImplSDL3_ProcessEvent(&event); + } } diff --git a/src/frontend/RenderWidget.hpp b/src/frontend/RenderWidget.hpp index f9fc4604..476c92eb 100644 --- a/src/frontend/RenderWidget.hpp +++ b/src/frontend/RenderWidget.hpp @@ -5,12 +5,9 @@ #include #include #include +#include -#include -#include -#include #include -#include struct QtInstanceFactory : Vulkan::InstanceFactory { VkInstance create_instance(const VkInstanceCreateInfo *info) override { @@ -84,6 +81,10 @@ public: }; class RenderWidget : public QWidget { + SDL_Window *sdlWindow; + QTimer timer; + void UpdateEvents(); + public: explicit RenderWidget(QWidget *parent); @@ -91,7 +92,7 @@ public: std::unique_ptr windowInfo; std::unique_ptr wsiPlatform; - std::unique_ptr instance; + std::unique_ptr instance; Q_SIGNALS: void Show() { show(); } void Hide() { hide(); }