bootmanager.cpp 22 KB

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