50 lines
1.8 KiB
C++
50 lines
1.8 KiB
C++
#include <KaizenGui.hpp>
|
|
#include <RenderWidget.hpp>
|
|
#include <Core.hpp>
|
|
#include <QGuiApplication>
|
|
|
|
enum class CompositorCategory { Windows, MacOS, XCB, Wayland };
|
|
|
|
static CompositorCategory GetOSCompositorCategory() {
|
|
const QString platform_name = QGuiApplication::platformName();
|
|
if (platform_name == QStringLiteral("windows"))
|
|
return CompositorCategory::Windows;
|
|
if (platform_name == QStringLiteral("xcb"))
|
|
return CompositorCategory::XCB;
|
|
if (platform_name == QStringLiteral("wayland") || platform_name == QStringLiteral("wayland-egl"))
|
|
return CompositorCategory::Wayland;
|
|
if (platform_name == QStringLiteral("cocoa") || platform_name == QStringLiteral("ios"))
|
|
return CompositorCategory::MacOS;
|
|
|
|
warn("Unknown Qt platform!");
|
|
return CompositorCategory::Windows;
|
|
}
|
|
|
|
RenderWidget::RenderWidget() {
|
|
setAttribute(Qt::WA_NativeWindow);
|
|
setAttribute(Qt::WA_PaintOnScreen);
|
|
if (GetOSCompositorCategory() == CompositorCategory::Wayland) {
|
|
setAttribute(Qt::WA_DontCreateNativeAncestors);
|
|
}
|
|
|
|
if (GetOSCompositorCategory() == CompositorCategory::MacOS) {
|
|
windowHandle()->setSurfaceType(QWindow::MetalSurface);
|
|
} else {
|
|
windowHandle()->setSurfaceType(QWindow::VulkanSurface);
|
|
}
|
|
|
|
if (!Vulkan::Context::init_loader(nullptr)) {
|
|
panic("Could not initialize Vulkan ICD");
|
|
}
|
|
|
|
qtVkInstanceFactory = std::make_unique<QtInstanceFactory>();
|
|
|
|
windowHandle()->setVulkanInstance(&qtVkInstanceFactory->handle);
|
|
windowHandle()->create();
|
|
|
|
wsiPlatform = std::make_shared<QtWSIPlatform>(windowHandle());
|
|
windowInfo = std::make_shared<QtPrdpWindowInfo>(windowHandle());
|
|
n64::Core &core = n64::Core::GetInstance();
|
|
core.parallel.Init(wsiPlatform, windowInfo, qtVkInstanceFactory.get(), core.GetMem().GetRDRAMPtr());
|
|
}
|