Make SDL context part of the RenderWidget. Much cleaner
This commit is contained in:
35
external/parallel-rdp/ParallelRDPWrapper.cpp
vendored
35
external/parallel-rdp/ParallelRDPWrapper.cpp
vendored
@@ -33,7 +33,7 @@ static void check_vk_result(VkResult err) {
|
|||||||
|
|
||||||
void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<InstanceFactory> &instanceFactory,
|
void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<InstanceFactory> &instanceFactory,
|
||||||
const std::shared_ptr<WSIPlatform> &wsi_platform,
|
const std::shared_ptr<WSIPlatform> &wsi_platform,
|
||||||
const std::shared_ptr<WindowInfo> &newWindowInfo, void *winPtr) {
|
const std::shared_ptr<WindowInfo> &newWindowInfo) {
|
||||||
wsi = std::make_shared<WSI>();
|
wsi = std::make_shared<WSI>();
|
||||||
wsi->set_backbuffer_srgb(false);
|
wsi->set_backbuffer_srgb(false);
|
||||||
wsi->set_platform(wsi_platform.get());
|
wsi->set_platform(wsi_platform.get());
|
||||||
@@ -45,39 +45,17 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<InstanceFactory> &instan
|
|||||||
|
|
||||||
windowInfo = newWindowInfo;
|
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_cast<s64>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);
|
|
||||||
|
|
||||||
auto instance = wsi->get_context().get_instance();
|
auto instance = wsi->get_context().get_instance();
|
||||||
|
|
||||||
volkInitialize();
|
volkInitialize();
|
||||||
volkLoadInstance(instance);
|
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(
|
ImGui_ImplVulkan_LoadFunctions(
|
||||||
[](const char *function_name, void *instance) {
|
[](const char *function_name, void *instance) {
|
||||||
return vkGetInstanceProcAddr(static_cast<VkInstance>(instance), function_name);
|
return vkGetInstanceProcAddr(static_cast<VkInstance>(instance), function_name);
|
||||||
},
|
},
|
||||||
instance);
|
instance);
|
||||||
|
|
||||||
ImGui_ImplSDL3_InitForVulkan(SDLWindow);
|
|
||||||
|
|
||||||
ImGui_ImplVulkan_InitInfo init_info = {};
|
ImGui_ImplVulkan_InitInfo init_info = {};
|
||||||
init_info.Instance = instance;
|
init_info.Instance = instance;
|
||||||
init_info.PhysicalDevice = wsi->get_device().get_physical_device();
|
init_info.PhysicalDevice = wsi->get_device().get_physical_device();
|
||||||
@@ -114,8 +92,8 @@ void ParallelRDP::LoadWSIPlatform(const std::shared_ptr<InstanceFactory> &instan
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ParallelRDP::Init(const std::shared_ptr<InstanceFactory> &factory, const std::shared_ptr<WSIPlatform> &wsiPlatform,
|
void ParallelRDP::Init(const std::shared_ptr<InstanceFactory> &factory, const std::shared_ptr<WSIPlatform> &wsiPlatform,
|
||||||
const std::shared_ptr<WindowInfo> &newWindowInfo, const u8 *rdram, void *winPtr) {
|
const std::shared_ptr<WindowInfo> &newWindowInfo, const u8 *rdram) {
|
||||||
LoadWSIPlatform(factory, wsiPlatform, newWindowInfo, winPtr);
|
LoadWSIPlatform(factory, wsiPlatform, newWindowInfo);
|
||||||
|
|
||||||
ResourceLayout vertLayout;
|
ResourceLayout vertLayout;
|
||||||
ResourceLayout fragLayout;
|
ResourceLayout fragLayout;
|
||||||
@@ -222,17 +200,10 @@ void ParallelRDP::UpdateScreen(Util::IntrusivePtr<Image> image) const {
|
|||||||
cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly));
|
cmd->begin_render_pass(wsi->get_device().get_swapchain_render_pass(SwapchainRenderPass::ColorOnly));
|
||||||
DrawFullscreenTexturedQuad(image, cmd);
|
DrawFullscreenTexturedQuad(image, cmd);
|
||||||
|
|
||||||
SDL_Event event;
|
|
||||||
while (SDL_PollEvent(&event)) {
|
|
||||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui_ImplVulkan_NewFrame();
|
ImGui_ImplVulkan_NewFrame();
|
||||||
ImGui_ImplSDL3_NewFrame();
|
ImGui_ImplSDL3_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
ImGui::ShowDemoWindow();
|
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->get_command_buffer());
|
ImGui_ImplVulkan_RenderDrawData(ImGui::GetDrawData(), cmd->get_command_buffer());
|
||||||
|
|
||||||
|
|||||||
5
external/parallel-rdp/ParallelRDPWrapper.hpp
vendored
5
external/parallel-rdp/ParallelRDPWrapper.hpp
vendored
@@ -17,7 +17,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void Init(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &,
|
void Init(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &,
|
||||||
const std::shared_ptr<WindowInfo> &, const u8 *, void *);
|
const std::shared_ptr<WindowInfo> &, const u8 *);
|
||||||
ParallelRDP() = default;
|
ParallelRDP() = default;
|
||||||
|
|
||||||
void UpdateScreen(const n64::VI &) const;
|
void UpdateScreen(const n64::VI &) const;
|
||||||
@@ -28,12 +28,11 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void LoadWSIPlatform(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &,
|
void LoadWSIPlatform(const std::shared_ptr<Vulkan::InstanceFactory> &, const std::shared_ptr<Vulkan::WSIPlatform> &,
|
||||||
const std::shared_ptr<WindowInfo> &, void *);
|
const std::shared_ptr<WindowInfo> &);
|
||||||
void DrawFullscreenTexturedQuad(Util::IntrusivePtr<Vulkan::Image>, Util::IntrusivePtr<Vulkan::CommandBuffer>) const;
|
void DrawFullscreenTexturedQuad(Util::IntrusivePtr<Vulkan::Image>, Util::IntrusivePtr<Vulkan::CommandBuffer>) const;
|
||||||
void UpdateScreen(Util::IntrusivePtr<Vulkan::Image>) const;
|
void UpdateScreen(Util::IntrusivePtr<Vulkan::Image>) const;
|
||||||
|
|
||||||
std::shared_ptr<Vulkan::WSI> wsi;
|
std::shared_ptr<Vulkan::WSI> wsi;
|
||||||
std::shared_ptr<RDP::CommandProcessor> command_processor;
|
std::shared_ptr<RDP::CommandProcessor> command_processor;
|
||||||
std::shared_ptr<WindowInfo> windowInfo;
|
std::shared_ptr<WindowInfo> windowInfo;
|
||||||
SDL_Window *SDLWindow;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ EmuThread::EmuThread(const std::shared_ptr<QtInstanceFactory> &instance_,
|
|||||||
instance(instance_), wsiPlatform(wsiPlatform_), windowInfo(windowInfo_), core(parallel), settings(settings) {}
|
instance(instance_), wsiPlatform(wsiPlatform_), windowInfo(windowInfo_), core(parallel), settings(settings) {}
|
||||||
|
|
||||||
[[noreturn]] void EmuThread::run() noexcept {
|
[[noreturn]] void EmuThread::run() noexcept {
|
||||||
parallel.Init(instance, wsiPlatform, windowInfo, core.cpu->GetMem().GetRDRAMPtr(),
|
parallel.Init(instance, wsiPlatform, windowInfo, core.cpu->GetMem().GetRDRAMPtr());
|
||||||
reinterpret_cast<void *>(wsiPlatform->get_native_window()));
|
|
||||||
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
|
||||||
bool controllerConnected = false;
|
bool controllerConnected = false;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
#include <KaizenQt.hpp>
|
#include <KaizenQt.hpp>
|
||||||
#include <RenderWidget.hpp>
|
#include <RenderWidget.hpp>
|
||||||
|
#include <imgui.h>
|
||||||
|
#include <imgui_impl_sdl3.h>
|
||||||
|
#include <imgui_impl_vulkan.h>
|
||||||
|
|
||||||
RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) {
|
RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) {
|
||||||
setAttribute(Qt::WA_NativeWindow);
|
setAttribute(Qt::WA_NativeWindow);
|
||||||
@@ -24,4 +27,38 @@ RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) {
|
|||||||
|
|
||||||
wsiPlatform = std::make_unique<QtWSIPlatform>(windowHandle());
|
wsiPlatform = std::make_unique<QtWSIPlatform>(windowHandle());
|
||||||
windowInfo = std::make_unique<QtParallelRdpWindowInfo>(windowHandle());
|
windowInfo = std::make_unique<QtParallelRdpWindowInfo>(windowHandle());
|
||||||
|
|
||||||
|
auto winPtr = reinterpret_cast<void *>(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<s64> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,12 +5,9 @@
|
|||||||
#include <QVulkanWindow>
|
#include <QVulkanWindow>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
#include <imgui.h>
|
|
||||||
#include <imgui_impl_sdl3.h>
|
|
||||||
#include <imgui_impl_vulkan.h>
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
#include <SDL3/SDL_vulkan.h>
|
|
||||||
|
|
||||||
struct QtInstanceFactory : Vulkan::InstanceFactory {
|
struct QtInstanceFactory : Vulkan::InstanceFactory {
|
||||||
VkInstance create_instance(const VkInstanceCreateInfo *info) override {
|
VkInstance create_instance(const VkInstanceCreateInfo *info) override {
|
||||||
@@ -84,6 +81,10 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
class RenderWidget : public QWidget {
|
class RenderWidget : public QWidget {
|
||||||
|
SDL_Window *sdlWindow;
|
||||||
|
QTimer timer;
|
||||||
|
void UpdateEvents();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit RenderWidget(QWidget *parent);
|
explicit RenderWidget(QWidget *parent);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user