bootmanager.cpp 22 KB

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