bootmanager.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <glad/glad.h>
  5. #include <QApplication>
  6. #include <QHBoxLayout>
  7. #include <QKeyEvent>
  8. #include <QMessageBox>
  9. #include <QPainter>
  10. #include <QScreen>
  11. #include <QStringList>
  12. #include <QWindow>
  13. #ifdef HAS_OPENGL
  14. #include <QOffscreenSurface>
  15. #include <QOpenGLContext>
  16. #endif
  17. #if !defined(WIN32) && HAS_VULKAN
  18. #include <qpa/qplatformnativeinterface.h>
  19. #endif
  20. #include <fmt/format.h>
  21. #include "common/assert.h"
  22. #include "common/microprofile.h"
  23. #include "common/scm_rev.h"
  24. #include "common/scope_exit.h"
  25. #include "core/core.h"
  26. #include "core/frontend/framebuffer_layout.h"
  27. #include "core/settings.h"
  28. #include "input_common/keyboard.h"
  29. #include "input_common/main.h"
  30. #include "input_common/motion_emu.h"
  31. #include "video_core/renderer_base.h"
  32. #include "video_core/video_core.h"
  33. #include "yuzu/bootmanager.h"
  34. #include "yuzu/main.h"
  35. EmuThread::EmuThread() = default;
  36. EmuThread::~EmuThread() = default;
  37. void EmuThread::run() {
  38. std::string name = "yuzu:EmuControlThread";
  39. MicroProfileOnThreadCreate(name.c_str());
  40. Common::SetCurrentThreadName(name.c_str());
  41. // Main process has been loaded. Make the context current to this thread and begin GPU and CPU
  42. // execution.
  43. Core::System::GetInstance().GPU().Start();
  44. emit LoadProgress(VideoCore::LoadCallbackStage::Prepare, 0, 0);
  45. Core::System::GetInstance().RegisterHostThread();
  46. Core::System::GetInstance().Renderer().Rasterizer().LoadDiskResources(
  47. stop_run, [this](VideoCore::LoadCallbackStage stage, std::size_t value, std::size_t total) {
  48. emit LoadProgress(stage, value, total);
  49. });
  50. emit LoadProgress(VideoCore::LoadCallbackStage::Complete, 0, 0);
  51. // Holds whether the cpu was running during the last iteration,
  52. // so that the DebugModeLeft signal can be emitted before the
  53. // next execution step
  54. bool was_active = false;
  55. while (!stop_run) {
  56. if (running) {
  57. if (was_active) {
  58. emit DebugModeLeft();
  59. }
  60. running_guard = true;
  61. Core::System::ResultStatus result = Core::System::GetInstance().Run();
  62. if (result != Core::System::ResultStatus::Success) {
  63. running_guard = false;
  64. this->SetRunning(false);
  65. emit ErrorThrown(result, Core::System::GetInstance().GetStatusDetails());
  66. }
  67. running_wait.Wait();
  68. result = Core::System::GetInstance().Pause();
  69. if (result != Core::System::ResultStatus::Success) {
  70. running_guard = false;
  71. this->SetRunning(false);
  72. emit ErrorThrown(result, Core::System::GetInstance().GetStatusDetails());
  73. }
  74. running_guard = false;
  75. was_active = true;
  76. emit DebugModeEntered();
  77. } else if (exec_step) {
  78. UNIMPLEMENTED();
  79. } else {
  80. std::unique_lock lock{running_mutex};
  81. running_cv.wait(lock, [this] { return IsRunning() || exec_step || stop_run; });
  82. }
  83. }
  84. // Shutdown the core emulation
  85. Core::System::GetInstance().Shutdown();
  86. #if MICROPROFILE_ENABLED
  87. MicroProfileOnThreadExit();
  88. #endif
  89. }
  90. #ifdef HAS_OPENGL
  91. class OpenGLSharedContext : public Core::Frontend::GraphicsContext {
  92. public:
  93. /// Create the original context that should be shared from
  94. explicit OpenGLSharedContext(QSurface* surface) : surface(surface) {
  95. QSurfaceFormat format;
  96. format.setVersion(4, 3);
  97. format.setProfile(QSurfaceFormat::CompatibilityProfile);
  98. format.setOption(QSurfaceFormat::FormatOption::DeprecatedFunctions);
  99. if (Settings::values.renderer_debug) {
  100. format.setOption(QSurfaceFormat::FormatOption::DebugContext);
  101. }
  102. // TODO: expose a setting for buffer value (ie default/single/double/triple)
  103. format.setSwapBehavior(QSurfaceFormat::DefaultSwapBehavior);
  104. format.setSwapInterval(0);
  105. context = std::make_unique<QOpenGLContext>();
  106. context->setFormat(format);
  107. if (!context->create()) {
  108. LOG_ERROR(Frontend, "Unable to create main openGL context");
  109. }
  110. }
  111. /// Create the shared contexts for rendering and presentation
  112. explicit OpenGLSharedContext(QOpenGLContext* share_context, QSurface* main_surface = nullptr) {
  113. // disable vsync for any shared contexts
  114. auto format = share_context->format();
  115. format.setSwapInterval(main_surface ? Settings::values.use_vsync : 0);
  116. context = std::make_unique<QOpenGLContext>();
  117. context->setShareContext(share_context);
  118. context->setFormat(format);
  119. if (!context->create()) {
  120. LOG_ERROR(Frontend, "Unable to create shared openGL context");
  121. }
  122. if (!main_surface) {
  123. offscreen_surface = std::make_unique<QOffscreenSurface>(nullptr);
  124. offscreen_surface->setFormat(format);
  125. offscreen_surface->create();
  126. surface = offscreen_surface.get();
  127. } else {
  128. surface = main_surface;
  129. }
  130. }
  131. ~OpenGLSharedContext() {
  132. DoneCurrent();
  133. }
  134. void SwapBuffers() override {
  135. context->swapBuffers(surface);
  136. }
  137. void MakeCurrent() override {
  138. // We can't track the current state of the underlying context in this wrapper class because
  139. // Qt may make the underlying context not current for one reason or another. In particular,
  140. // the WebBrowser uses GL, so it seems to conflict if we aren't careful.
  141. // Instead of always just making the context current (which does not have any caching to
  142. // check if the underlying context is already current) we can check for the current context
  143. // in the thread local data by calling `currentContext()` and checking if its ours.
  144. if (QOpenGLContext::currentContext() != context.get()) {
  145. context->makeCurrent(surface);
  146. }
  147. }
  148. void DoneCurrent() override {
  149. context->doneCurrent();
  150. }
  151. QOpenGLContext* GetShareContext() {
  152. return context.get();
  153. }
  154. const QOpenGLContext* GetShareContext() const {
  155. return context.get();
  156. }
  157. private:
  158. // Avoid using Qt parent system here since we might move the QObjects to new threads
  159. // As a note, this means we should avoid using slots/signals with the objects too
  160. std::unique_ptr<QOpenGLContext> context;
  161. std::unique_ptr<QOffscreenSurface> offscreen_surface{};
  162. QSurface* surface;
  163. };
  164. #endif
  165. class DummyContext : public Core::Frontend::GraphicsContext {};
  166. class RenderWidget : public QWidget {
  167. public:
  168. explicit RenderWidget(GRenderWindow* parent) : QWidget(parent), render_window(parent) {
  169. setAttribute(Qt::WA_NativeWindow);
  170. setAttribute(Qt::WA_PaintOnScreen);
  171. }
  172. virtual ~RenderWidget() = default;
  173. /// Called on the UI thread when this Widget is ready to draw
  174. /// Dervied classes can override this to draw the latest frame.
  175. virtual void Present() {}
  176. void paintEvent(QPaintEvent* event) override {
  177. Present();
  178. update();
  179. }
  180. QPaintEngine* paintEngine() const override {
  181. return nullptr;
  182. }
  183. private:
  184. GRenderWindow* render_window;
  185. };
  186. class OpenGLRenderWidget : public RenderWidget {
  187. public:
  188. explicit OpenGLRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {
  189. windowHandle()->setSurfaceType(QWindow::OpenGLSurface);
  190. }
  191. void SetContext(std::unique_ptr<Core::Frontend::GraphicsContext>&& context_) {
  192. context = std::move(context_);
  193. }
  194. void Present() override {
  195. if (!isVisible()) {
  196. return;
  197. }
  198. context->MakeCurrent();
  199. if (Core::System::GetInstance().Renderer().TryPresent(100)) {
  200. context->SwapBuffers();
  201. glFinish();
  202. }
  203. }
  204. private:
  205. std::unique_ptr<Core::Frontend::GraphicsContext> context{};
  206. };
  207. #ifdef HAS_VULKAN
  208. class VulkanRenderWidget : public RenderWidget {
  209. public:
  210. explicit VulkanRenderWidget(GRenderWindow* parent) : RenderWidget(parent) {
  211. windowHandle()->setSurfaceType(QWindow::VulkanSurface);
  212. }
  213. };
  214. #endif
  215. static Core::Frontend::WindowSystemType GetWindowSystemType() {
  216. // Determine WSI type based on Qt platform.
  217. QString platform_name = QGuiApplication::platformName();
  218. if (platform_name == QStringLiteral("windows"))
  219. return Core::Frontend::WindowSystemType::Windows;
  220. else if (platform_name == QStringLiteral("xcb"))
  221. return Core::Frontend::WindowSystemType::X11;
  222. else if (platform_name == QStringLiteral("wayland"))
  223. return Core::Frontend::WindowSystemType::Wayland;
  224. LOG_CRITICAL(Frontend, "Unknown Qt platform!");
  225. return Core::Frontend::WindowSystemType::Windows;
  226. }
  227. static Core::Frontend::EmuWindow::WindowSystemInfo GetWindowSystemInfo(QWindow* window) {
  228. Core::Frontend::EmuWindow::WindowSystemInfo wsi;
  229. wsi.type = GetWindowSystemType();
  230. #ifdef HAS_VULKAN
  231. // Our Win32 Qt external doesn't have the private API.
  232. #if defined(WIN32) || defined(__APPLE__)
  233. wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
  234. #else
  235. QPlatformNativeInterface* pni = QGuiApplication::platformNativeInterface();
  236. wsi.display_connection = pni->nativeResourceForWindow("display", window);
  237. if (wsi.type == Core::Frontend::WindowSystemType::Wayland)
  238. wsi.render_surface = window ? pni->nativeResourceForWindow("surface", window) : nullptr;
  239. else
  240. wsi.render_surface = window ? reinterpret_cast<void*>(window->winId()) : nullptr;
  241. #endif
  242. wsi.render_surface_scale = window ? static_cast<float>(window->devicePixelRatio()) : 1.0f;
  243. #endif
  244. return wsi;
  245. }
  246. GRenderWindow::GRenderWindow(GMainWindow* parent_, EmuThread* emu_thread_)
  247. : QWidget(parent_), emu_thread(emu_thread_) {
  248. setWindowTitle(QStringLiteral("yuzu %1 | %2-%3")
  249. .arg(QString::fromUtf8(Common::g_build_name),
  250. QString::fromUtf8(Common::g_scm_branch),
  251. QString::fromUtf8(Common::g_scm_desc)));
  252. setAttribute(Qt::WA_AcceptTouchEvents);
  253. auto layout = new QHBoxLayout(this);
  254. layout->setMargin(0);
  255. setLayout(layout);
  256. InputCommon::Init();
  257. this->setMouseTracking(true);
  258. connect(this, &GRenderWindow::FirstFrameDisplayed, parent_, &GMainWindow::OnLoadComplete);
  259. }
  260. GRenderWindow::~GRenderWindow() {
  261. InputCommon::Shutdown();
  262. }
  263. void GRenderWindow::PollEvents() {
  264. if (!first_frame) {
  265. first_frame = true;
  266. emit FirstFrameDisplayed();
  267. }
  268. }
  269. bool GRenderWindow::IsShown() const {
  270. return !isMinimized();
  271. }
  272. // On Qt 5.0+, this correctly gets the size of the framebuffer (pixels).
  273. //
  274. // Older versions get the window size (density independent pixels),
  275. // and hence, do not support DPI scaling ("retina" displays).
  276. // The result will be a viewport that is smaller than the extent of the window.
  277. void GRenderWindow::OnFramebufferSizeChanged() {
  278. // Screen changes potentially incur a change in screen DPI, hence we should update the
  279. // framebuffer size
  280. const qreal pixel_ratio = windowPixelRatio();
  281. const u32 width = this->width() * pixel_ratio;
  282. const u32 height = this->height() * pixel_ratio;
  283. UpdateCurrentFramebufferLayout(width, height);
  284. }
  285. void GRenderWindow::BackupGeometry() {
  286. geometry = QWidget::saveGeometry();
  287. }
  288. void GRenderWindow::RestoreGeometry() {
  289. // We don't want to back up the geometry here (obviously)
  290. QWidget::restoreGeometry(geometry);
  291. }
  292. void GRenderWindow::restoreGeometry(const QByteArray& geometry) {
  293. // Make sure users of this class don't need to deal with backing up the geometry themselves
  294. QWidget::restoreGeometry(geometry);
  295. BackupGeometry();
  296. }
  297. QByteArray GRenderWindow::saveGeometry() {
  298. // If we are a top-level widget, store the current geometry
  299. // otherwise, store the last backup
  300. if (parent() == nullptr) {
  301. return QWidget::saveGeometry();
  302. }
  303. return geometry;
  304. }
  305. qreal GRenderWindow::windowPixelRatio() const {
  306. return devicePixelRatioF();
  307. }
  308. std::pair<u32, u32> GRenderWindow::ScaleTouch(const QPointF& pos) const {
  309. const qreal pixel_ratio = windowPixelRatio();
  310. return {static_cast<u32>(std::max(std::round(pos.x() * pixel_ratio), qreal{0.0})),
  311. static_cast<u32>(std::max(std::round(pos.y() * pixel_ratio), qreal{0.0}))};
  312. }
  313. void GRenderWindow::closeEvent(QCloseEvent* event) {
  314. emit Closed();
  315. QWidget::closeEvent(event);
  316. }
  317. void GRenderWindow::keyPressEvent(QKeyEvent* event) {
  318. InputCommon::GetKeyboard()->PressKey(event->key());
  319. }
  320. void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
  321. InputCommon::GetKeyboard()->ReleaseKey(event->key());
  322. }
  323. void GRenderWindow::mousePressEvent(QMouseEvent* event) {
  324. // touch input is handled in TouchBeginEvent
  325. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  326. return;
  327. }
  328. auto pos = event->pos();
  329. if (event->button() == Qt::LeftButton) {
  330. const auto [x, y] = ScaleTouch(pos);
  331. this->TouchPressed(x, y);
  332. } else if (event->button() == Qt::RightButton) {
  333. InputCommon::GetMotionEmu()->BeginTilt(pos.x(), pos.y());
  334. }
  335. QWidget::mousePressEvent(event);
  336. }
  337. void GRenderWindow::mouseMoveEvent(QMouseEvent* event) {
  338. // touch input is handled in TouchUpdateEvent
  339. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  340. return;
  341. }
  342. auto pos = event->pos();
  343. const auto [x, y] = ScaleTouch(pos);
  344. this->TouchMoved(x, y);
  345. InputCommon::GetMotionEmu()->Tilt(pos.x(), pos.y());
  346. QWidget::mouseMoveEvent(event);
  347. }
  348. void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
  349. // touch input is handled in TouchEndEvent
  350. if (event->source() == Qt::MouseEventSynthesizedBySystem) {
  351. return;
  352. }
  353. if (event->button() == Qt::LeftButton) {
  354. this->TouchReleased();
  355. } else if (event->button() == Qt::RightButton) {
  356. InputCommon::GetMotionEmu()->EndTilt();
  357. }
  358. }
  359. void GRenderWindow::TouchBeginEvent(const QTouchEvent* event) {
  360. // TouchBegin always has exactly one touch point, so take the .first()
  361. const auto [x, y] = ScaleTouch(event->touchPoints().first().pos());
  362. this->TouchPressed(x, y);
  363. }
  364. void GRenderWindow::TouchUpdateEvent(const QTouchEvent* event) {
  365. QPointF pos;
  366. int active_points = 0;
  367. // average all active touch points
  368. for (const auto tp : event->touchPoints()) {
  369. if (tp.state() & (Qt::TouchPointPressed | Qt::TouchPointMoved | Qt::TouchPointStationary)) {
  370. active_points++;
  371. pos += tp.pos();
  372. }
  373. }
  374. pos /= active_points;
  375. const auto [x, y] = ScaleTouch(pos);
  376. this->TouchMoved(x, y);
  377. }
  378. void GRenderWindow::TouchEndEvent() {
  379. this->TouchReleased();
  380. }
  381. bool GRenderWindow::event(QEvent* event) {
  382. if (event->type() == QEvent::TouchBegin) {
  383. TouchBeginEvent(static_cast<QTouchEvent*>(event));
  384. return true;
  385. } else if (event->type() == QEvent::TouchUpdate) {
  386. TouchUpdateEvent(static_cast<QTouchEvent*>(event));
  387. return true;
  388. } else if (event->type() == QEvent::TouchEnd || event->type() == QEvent::TouchCancel) {
  389. TouchEndEvent();
  390. return true;
  391. }
  392. return QWidget::event(event);
  393. }
  394. void GRenderWindow::focusOutEvent(QFocusEvent* event) {
  395. QWidget::focusOutEvent(event);
  396. InputCommon::GetKeyboard()->ReleaseAllKeys();
  397. }
  398. void GRenderWindow::resizeEvent(QResizeEvent* event) {
  399. QWidget::resizeEvent(event);
  400. OnFramebufferSizeChanged();
  401. }
  402. std::unique_ptr<Core::Frontend::GraphicsContext> GRenderWindow::CreateSharedContext() const {
  403. #ifdef HAS_OPENGL
  404. if (Settings::values.renderer_backend == Settings::RendererBackend::OpenGL) {
  405. auto c = static_cast<OpenGLSharedContext*>(main_context.get());
  406. // Bind the shared contexts to the main surface in case the backend wants to take over
  407. // presentation
  408. return std::make_unique<OpenGLSharedContext>(c->GetShareContext(),
  409. child_widget->windowHandle());
  410. }
  411. #endif
  412. return std::make_unique<DummyContext>();
  413. }
  414. bool GRenderWindow::InitRenderTarget() {
  415. ReleaseRenderTarget();
  416. first_frame = false;
  417. switch (Settings::values.renderer_backend) {
  418. case Settings::RendererBackend::OpenGL:
  419. if (!InitializeOpenGL()) {
  420. return false;
  421. }
  422. break;
  423. case Settings::RendererBackend::Vulkan:
  424. if (!InitializeVulkan()) {
  425. return false;
  426. }
  427. break;
  428. }
  429. // Update the Window System information with the new render target
  430. window_info = GetWindowSystemInfo(child_widget->windowHandle());
  431. child_widget->resize(Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height);
  432. layout()->addWidget(child_widget);
  433. // Reset minimum required size to avoid resizing issues on the main window after restarting.
  434. setMinimumSize(1, 1);
  435. resize(Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height);
  436. OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
  437. OnFramebufferSizeChanged();
  438. BackupGeometry();
  439. if (Settings::values.renderer_backend == Settings::RendererBackend::OpenGL) {
  440. if (!LoadOpenGL()) {
  441. return false;
  442. }
  443. }
  444. return true;
  445. }
  446. void GRenderWindow::ReleaseRenderTarget() {
  447. if (child_widget) {
  448. layout()->removeWidget(child_widget);
  449. child_widget->deleteLater();
  450. child_widget = nullptr;
  451. }
  452. main_context.reset();
  453. }
  454. void GRenderWindow::CaptureScreenshot(u32 res_scale, const QString& screenshot_path) {
  455. auto& renderer = Core::System::GetInstance().Renderer();
  456. if (res_scale == 0) {
  457. res_scale = VideoCore::GetResolutionScaleFactor(renderer);
  458. }
  459. const Layout::FramebufferLayout layout{Layout::FrameLayoutFromResolutionScale(res_scale)};
  460. screenshot_image = QImage(QSize(layout.width, layout.height), QImage::Format_RGB32);
  461. renderer.RequestScreenshot(
  462. screenshot_image.bits(),
  463. [=] {
  464. const std::string std_screenshot_path = screenshot_path.toStdString();
  465. if (screenshot_image.mirrored(false, true).save(screenshot_path)) {
  466. LOG_INFO(Frontend, "Screenshot saved to \"{}\"", std_screenshot_path);
  467. } else {
  468. LOG_ERROR(Frontend, "Failed to save screenshot to \"{}\"", std_screenshot_path);
  469. }
  470. },
  471. layout);
  472. }
  473. void GRenderWindow::OnMinimalClientAreaChangeRequest(std::pair<u32, u32> minimal_size) {
  474. setMinimumSize(minimal_size.first, minimal_size.second);
  475. }
  476. bool GRenderWindow::InitializeOpenGL() {
  477. #ifdef HAS_OPENGL
  478. // TODO: One of these flags might be interesting: WA_OpaquePaintEvent, WA_NoBackground,
  479. // WA_DontShowOnScreen, WA_DeleteOnClose
  480. auto child = new OpenGLRenderWidget(this);
  481. child_widget = child;
  482. child_widget->windowHandle()->create();
  483. auto context = std::make_shared<OpenGLSharedContext>(child->windowHandle());
  484. main_context = context;
  485. child->SetContext(
  486. std::make_unique<OpenGLSharedContext>(context->GetShareContext(), child->windowHandle()));
  487. return true;
  488. #else
  489. QMessageBox::warning(this, tr("OpenGL not available!"),
  490. tr("yuzu has not been compiled with OpenGL support."));
  491. return false;
  492. #endif
  493. }
  494. bool GRenderWindow::InitializeVulkan() {
  495. #ifdef HAS_VULKAN
  496. auto child = new VulkanRenderWidget(this);
  497. child_widget = child;
  498. child_widget->windowHandle()->create();
  499. main_context = std::make_unique<DummyContext>();
  500. return true;
  501. #else
  502. QMessageBox::critical(this, tr("Vulkan not available!"),
  503. tr("yuzu has not been compiled with Vulkan support."));
  504. return false;
  505. #endif
  506. }
  507. bool GRenderWindow::LoadOpenGL() {
  508. auto context = CreateSharedContext();
  509. auto scope = context->Acquire();
  510. if (!gladLoadGL()) {
  511. QMessageBox::critical(this, tr("Error while initializing OpenGL 4.3!"),
  512. tr("Your GPU may not support OpenGL 4.3, or you do not have the "
  513. "latest graphics driver."));
  514. return false;
  515. }
  516. QStringList unsupported_gl_extensions = GetUnsupportedGLExtensions();
  517. if (!unsupported_gl_extensions.empty()) {
  518. QMessageBox::critical(
  519. this, tr("Error while initializing OpenGL!"),
  520. tr("Your GPU may not support one or more required OpenGL extensions. Please ensure you "
  521. "have the latest graphics driver.<br><br>Unsupported extensions:<br>") +
  522. unsupported_gl_extensions.join(QStringLiteral("<br>")));
  523. return false;
  524. }
  525. return true;
  526. }
  527. QStringList GRenderWindow::GetUnsupportedGLExtensions() const {
  528. QStringList unsupported_ext;
  529. if (!GLAD_GL_ARB_buffer_storage)
  530. unsupported_ext.append(QStringLiteral("ARB_buffer_storage"));
  531. if (!GLAD_GL_ARB_direct_state_access)
  532. unsupported_ext.append(QStringLiteral("ARB_direct_state_access"));
  533. if (!GLAD_GL_ARB_vertex_type_10f_11f_11f_rev)
  534. unsupported_ext.append(QStringLiteral("ARB_vertex_type_10f_11f_11f_rev"));
  535. if (!GLAD_GL_ARB_texture_mirror_clamp_to_edge)
  536. unsupported_ext.append(QStringLiteral("ARB_texture_mirror_clamp_to_edge"));
  537. if (!GLAD_GL_ARB_multi_bind)
  538. unsupported_ext.append(QStringLiteral("ARB_multi_bind"));
  539. if (!GLAD_GL_ARB_clip_control)
  540. unsupported_ext.append(QStringLiteral("ARB_clip_control"));
  541. // Extensions required to support some texture formats.
  542. if (!GLAD_GL_EXT_texture_compression_s3tc)
  543. unsupported_ext.append(QStringLiteral("EXT_texture_compression_s3tc"));
  544. if (!GLAD_GL_ARB_texture_compression_rgtc)
  545. unsupported_ext.append(QStringLiteral("ARB_texture_compression_rgtc"));
  546. if (!GLAD_GL_ARB_depth_buffer_float)
  547. unsupported_ext.append(QStringLiteral("ARB_depth_buffer_float"));
  548. for (const QString& ext : unsupported_ext)
  549. LOG_CRITICAL(Frontend, "Unsupported GL extension: {}", ext.toStdString());
  550. return unsupported_ext;
  551. }
  552. void GRenderWindow::OnEmulationStarting(EmuThread* emu_thread) {
  553. this->emu_thread = emu_thread;
  554. }
  555. void GRenderWindow::OnEmulationStopping() {
  556. emu_thread = nullptr;
  557. }
  558. void GRenderWindow::showEvent(QShowEvent* event) {
  559. QWidget::showEvent(event);
  560. // windowHandle() is not initialized until the Window is shown, so we connect it here.
  561. connect(windowHandle(), &QWindow::screenChanged, this, &GRenderWindow::OnFramebufferSizeChanged,
  562. Qt::UniqueConnection);
  563. }