bootmanager.cpp 22 KB

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