Okokokokokokokok
This commit is contained in:
@@ -53,6 +53,8 @@ add_executable(kaizen-qt
|
|||||||
main.cpp
|
main.cpp
|
||||||
KaizenQt.hpp
|
KaizenQt.hpp
|
||||||
KaizenQt.cpp
|
KaizenQt.cpp
|
||||||
|
RenderWidget.cpp
|
||||||
|
RenderWidget.hpp
|
||||||
EmuThread.hpp
|
EmuThread.hpp
|
||||||
EmuThread.cpp
|
EmuThread.cpp
|
||||||
mainwindow.ui
|
mainwindow.ui
|
||||||
|
|||||||
@@ -2,17 +2,13 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
|
||||||
KaizenQt::KaizenQt() noexcept
|
KaizenQt::KaizenQt() noexcept : mainWindow(new MainWindowController), emuThread(new EmuThread(mainWindow)) {
|
||||||
: mainWindow(new MainWindowController),
|
|
||||||
emuThread(new EmuThread(mainWindow))
|
|
||||||
{
|
|
||||||
ConnectMainWindowSignalsToSlots();
|
ConnectMainWindowSignalsToSlots();
|
||||||
|
|
||||||
mainWindow->show();
|
mainWindow->show();
|
||||||
}
|
}
|
||||||
|
|
||||||
void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept
|
void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept {
|
||||||
{
|
|
||||||
connect(mainWindow, &MainWindowController::OpenROM, this, &KaizenQt::LoadROM);
|
connect(mainWindow, &MainWindowController::OpenROM, this, &KaizenQt::LoadROM);
|
||||||
connect(mainWindow, &MainWindowController::Exit, this, []() {
|
connect(mainWindow, &MainWindowController::Exit, this, []() {
|
||||||
QApplication::quit();
|
QApplication::quit();
|
||||||
@@ -22,8 +18,7 @@ void KaizenQt::ConnectMainWindowSignalsToSlots() noexcept
|
|||||||
connect(mainWindow, &MainWindowController::Pause, emuThread, &EmuThread::TogglePause);
|
connect(mainWindow, &MainWindowController::Pause, emuThread, &EmuThread::TogglePause);
|
||||||
}
|
}
|
||||||
|
|
||||||
void KaizenQt::LoadROM(const QString& file_name) noexcept
|
void KaizenQt::LoadROM(const QString& file_name) noexcept {
|
||||||
{
|
|
||||||
emuThread->core.LoadROM(file_name.toStdString());
|
emuThread->core.LoadROM(file_name.toStdString());
|
||||||
emuThread->start();
|
emuThread->start();
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,26 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <MainWindow.hpp>
|
|
||||||
#include <EmuThread.hpp>
|
#include <EmuThread.hpp>
|
||||||
|
#include <MainWindow.hpp>
|
||||||
|
|
||||||
|
enum class CompositorCategory {
|
||||||
|
Windows, MacOS, XCB, Wayland
|
||||||
|
};
|
||||||
|
|
||||||
|
static inline CompositorCategory GetOSCompositorCategory() {
|
||||||
|
const QString platform_name = QGuiApplication::platformName();
|
||||||
|
if (platform_name == QStringLiteral("windows"))
|
||||||
|
return CompositorCategory::Windows;
|
||||||
|
else if (platform_name == QStringLiteral("xcb"))
|
||||||
|
return CompositorCategory::XCB;
|
||||||
|
else if (platform_name == QStringLiteral("wayland") ||
|
||||||
|
platform_name == QStringLiteral("wayland-egl"))
|
||||||
|
return CompositorCategory::Wayland;
|
||||||
|
else if (platform_name == QStringLiteral("cocoa") || platform_name == QStringLiteral("ios"))
|
||||||
|
return CompositorCategory::MacOS;
|
||||||
|
|
||||||
|
Util::error("Unknown Qt platform!");
|
||||||
|
return CompositorCategory::Windows;
|
||||||
|
}
|
||||||
|
|
||||||
class KaizenQt : public QObject {
|
class KaizenQt : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
#include <MainWindow.hpp>
|
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <MainWindow.hpp>
|
||||||
|
|
||||||
MainWindowController::MainWindowController() noexcept
|
MainWindowController::MainWindowController() noexcept {
|
||||||
{
|
|
||||||
view.setupUi(this);
|
view.setupUi(this);
|
||||||
ConnectSignalsToSlots();
|
ConnectSignalsToSlots();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindowController::ConnectSignalsToSlots() noexcept
|
void MainWindowController::ConnectSignalsToSlots() noexcept {
|
||||||
{
|
|
||||||
connect(view.actionOpen, &QAction::triggered, this, [this]() {
|
connect(view.actionOpen, &QAction::triggered, this, [this]() {
|
||||||
QString file_name = QFileDialog::getOpenFileName(this);
|
QString file_name = QFileDialog::getOpenFileName(this);
|
||||||
|
|
||||||
if (!file_name.isEmpty())
|
if (!file_name.isEmpty()) {
|
||||||
{
|
|
||||||
view.actionPause->setEnabled(true);
|
view.actionPause->setEnabled(true);
|
||||||
view.actionReset->setEnabled(true);
|
view.actionReset->setEnabled(true);
|
||||||
view.actionStop->setEnabled(true);
|
view.actionStop->setEnabled(true);
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <QMainWindow>
|
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
|
#include <QMainWindow>
|
||||||
|
#include <QApplication>
|
||||||
|
|
||||||
class MainWindowController : public QMainWindow
|
class MainWindowController : public QMainWindow
|
||||||
{
|
{
|
||||||
@@ -15,7 +16,7 @@ private:
|
|||||||
Ui::MainWindow view;
|
Ui::MainWindow view;
|
||||||
bool textPauseToggle = false;
|
bool textPauseToggle = false;
|
||||||
|
|
||||||
signals:
|
Q_SIGNALS:
|
||||||
void OpenROM(const QString& rom_file);
|
void OpenROM(const QString& rom_file);
|
||||||
void Exit();
|
void Exit();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
|||||||
31
src/frontend/RenderWidget.cpp
Normal file
31
src/frontend/RenderWidget.cpp
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
#include <RenderWidget.hpp>
|
||||||
|
#include <KaizenQt.hpp>
|
||||||
|
|
||||||
|
RenderWidget::RenderWidget(QWidget* parent) : QWidget(parent) {
|
||||||
|
if (volkInitialize() != VK_SUCCESS) {
|
||||||
|
Util::panic("Could not initialize Vulkan loader!");
|
||||||
|
}
|
||||||
|
|
||||||
|
create();
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.create();
|
||||||
|
windowHandle()->setVulkanInstance(&instance);
|
||||||
|
|
||||||
|
wsiPlatform = new QtWSIPlatform(windowHandle());
|
||||||
|
windowInfo = std::make_unique<QtParallelRdpWindowInfo>(windowHandle());
|
||||||
|
|
||||||
|
LoadWSIPlatform(wsiPlatform, std::move(windowInfo));
|
||||||
|
}
|
||||||
75
src/frontend/RenderWidget.hpp
Normal file
75
src/frontend/RenderWidget.hpp
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
#pragma once
|
||||||
|
#undef signals
|
||||||
|
#include <ParallelRDPWrapper.hpp>
|
||||||
|
#include <QWidget>
|
||||||
|
#include <QWindow>
|
||||||
|
#include <QVulkanInstance>
|
||||||
|
|
||||||
|
class QtParallelRdpWindowInfo : public ParallelRdpWindowInfo {
|
||||||
|
public:
|
||||||
|
QtParallelRdpWindowInfo(QWindow* window) : window(window) {}
|
||||||
|
CoordinatePair get_window_size() {
|
||||||
|
CoordinatePair{ static_cast<float>(window->width()), static_cast<float>(window->height()) };
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
QWindow* window;
|
||||||
|
};
|
||||||
|
|
||||||
|
class QtWSIPlatform final : public Vulkan::WSIPlatform {
|
||||||
|
public:
|
||||||
|
QtWSIPlatform(QWindow* window) : window(window) {}
|
||||||
|
|
||||||
|
std::vector<const char*> get_instance_extensions() override {
|
||||||
|
auto vec = std::vector<const char*>();
|
||||||
|
|
||||||
|
for (const auto& ext : window->vulkanInstance()->extensions()) {
|
||||||
|
vec.push_back(ext);
|
||||||
|
}
|
||||||
|
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkSurfaceKHR create_surface(VkInstance, VkPhysicalDevice) override {
|
||||||
|
return QVulkanInstance::surfaceForWindow(window);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t get_surface_width() override {
|
||||||
|
return 640;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t get_surface_height() override {
|
||||||
|
return 480;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool alive(Vulkan::WSI&) override {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void poll_input() override { }
|
||||||
|
|
||||||
|
void event_frame_tick(double frame, double elapsed) override { }
|
||||||
|
|
||||||
|
const VkApplicationInfo* get_application_info() override {
|
||||||
|
return &appInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkApplicationInfo appInfo{
|
||||||
|
.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
|
||||||
|
.apiVersion = VK_API_VERSION_1_3
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
QWindow* window;
|
||||||
|
};
|
||||||
|
|
||||||
|
class RenderWidget : public QWidget {
|
||||||
|
public:
|
||||||
|
explicit RenderWidget(QWidget* parent);
|
||||||
|
|
||||||
|
QPaintEngine* paintEngine() const override {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
std::unique_ptr<ParallelRdpWindowInfo> windowInfo;
|
||||||
|
QtWSIPlatform* wsiPlatform;
|
||||||
|
QVulkanInstance instance;
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
|
#include <KaizenQt.hpp>
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QCommandLineParser>
|
#include <QCommandLineParser>
|
||||||
#include <QCommandLineOption>
|
#include <QCommandLineOption>
|
||||||
#include <KaizenQt.hpp>
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
QApplication app(argc, argv);
|
QApplication app(argc, argv);
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
<property name="bottomMargin">
|
<property name="bottomMargin">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="RenderWidget" name="vulkanWidget"/>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QMenuBar" name="menubar">
|
<widget class="QMenuBar" name="menubar">
|
||||||
@@ -119,6 +122,13 @@
|
|||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>Renderer</class>
|
||||||
|
<extends>QWidget</extends>
|
||||||
|
<header>RenderWidget.hpp</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|||||||
Reference in New Issue
Block a user