Make SDL context part of the RenderWidget. Much cleaner

This commit is contained in:
SimoneN64
2024-09-20 12:13:39 +02:00
parent 0db505b663
commit d1ccaa6667
5 changed files with 49 additions and 42 deletions

View File

@@ -7,8 +7,7 @@ EmuThread::EmuThread(const std::shared_ptr<QtInstanceFactory> &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<void *>(wsiPlatform->get_native_window()));
parallel.Init(instance, wsiPlatform, windowInfo, core.cpu->GetMem().GetRDRAMPtr());
SDL_InitSubSystem(SDL_INIT_GAMEPAD);
bool controllerConnected = false;

View File

@@ -1,5 +1,8 @@
#include <KaizenQt.hpp>
#include <RenderWidget.hpp>
#include <imgui.h>
#include <imgui_impl_sdl3.h>
#include <imgui_impl_vulkan.h>
RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) {
setAttribute(Qt::WA_NativeWindow);
@@ -24,4 +27,38 @@ RenderWidget::RenderWidget(QWidget *parent) : QWidget(parent) {
wsiPlatform = std::make_unique<QtWSIPlatform>(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);
}
}

View File

@@ -5,12 +5,9 @@
#include <QVulkanWindow>
#include <QWidget>
#include <QWindow>
#include <QTimer>
#include <imgui.h>
#include <imgui_impl_sdl3.h>
#include <imgui_impl_vulkan.h>
#include <SDL3/SDL.h>
#include <SDL3/SDL_vulkan.h>
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<ParallelRDP::WindowInfo> windowInfo;
std::unique_ptr<Vulkan::WSIPlatform> wsiPlatform;
std::unique_ptr<QtInstanceFactory> instance;
std::unique_ptr<QtInstanceFactory> instance;
Q_SIGNALS:
void Show() { show(); }
void Hide() { hide(); }