diff --git a/include/panda_qt/main_window.hpp b/include/panda_qt/main_window.hpp index 65a668ad..07b3a509 100644 --- a/include/panda_qt/main_window.hpp +++ b/include/panda_qt/main_window.hpp @@ -30,6 +30,11 @@ class MainWindow : public QMainWindow { Theme currentTheme; void setTheme(Theme theme); + void swapEmuBuffer(); + + // Tracks whether we are using an OpenGL-backed renderer or a Vulkan-backed renderer + bool usingGL = false; + bool usingVk = false; public: MainWindow(QApplication* app, QWidget* parent = nullptr); diff --git a/src/panda_qt/main_window.cpp b/src/panda_qt/main_window.cpp index a5ba0129..bb06e5b0 100644 --- a/src/panda_qt/main_window.cpp +++ b/src/panda_qt/main_window.cpp @@ -32,16 +32,20 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) // The emulator graphics context for the thread should be initialized in the emulator thread due to how GL contexts work emuThread = std::thread([&]() { const RendererType rendererType = emu->getConfig().rendererType; + usingGL = (rendererType == RendererType::OpenGL || rendererType == RendererType::Software || rendererType == RendererType::Null); + usingVk = (rendererType == RendererType::Vulkan); - if (rendererType == RendererType::OpenGL || rendererType == RendererType::Software || rendererType == RendererType::Null) { + if (usingGL) { // Make GL context current for this thread, enable VSync GL::Context* glContext = screen.getGLContext(); glContext->MakeCurrent(); glContext->SetSwapInterval(1); emu->initGraphicsContext(glContext); + } else if (usingVk) { + Helpers::panic("Vulkan on Qt is currently WIP, try the SDL frontend instead!"); } else { - Helpers::panic("Unsupported renderer type for the Qt backend! Vulkan on Qt is currently WIP, try the SDL frontend instead!"); + Helpers::panic("Unsupported graphics backend for Qt frontend!"); } bool success = emu->loadROM("OoT.3ds"); @@ -51,11 +55,19 @@ MainWindow::MainWindow(QApplication* app, QWidget* parent) : QMainWindow(parent) while (true) { emu->runFrame(); - screen.getGLContext()->SwapBuffers(); + swapEmuBuffer(); } }); } +void MainWindow::swapEmuBuffer() { + if (usingGL) { + screen.getGLContext()->SwapBuffers(); + } else { + Helpers::panic("[Qt] Don't know how to swap buffers for the current rendering backend :("); + } +} + // Cleanup when the main window closes MainWindow::~MainWindow() { delete emu;